码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces_822

时间:2017-07-24 01:24:42      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:bsp   cto   main   map   长度   alt   string   std   bit   

A.小的那个数的阶乘。

技术分享
#include<bits/stdc++.h>
using namespace std;

int a,b;

int main()
{
    ios::sync_with_stdio(0);
    cin >> a >> b;
    int t  = min(a,b);
    int ans = 1;
    for(int i = 1;i <= t;i++)    ans *= i;
    cout << ans << endl;
    return 0;
}
View Code

B.暴力t串的起始位置,比较两个串。

技术分享
#include<bits/stdc++.h>
using namespace std;

int n,m;
string s1,s2;
vector<int> v;

int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> m >> s1 >> s2;
    s1 =  +s1;
    s2 =  +s2;
    int ans = 1e9;
    for(int i = 0;i <= m-n;i++)
    {
        int cnt = 0;
        for(int j = 1;j <= n;j++)
        {
            if(s1[j] != s2[i+j])    cnt++;
        }
        if(cnt < ans)
        {
            ans = cnt;
            v.clear();
            for(int j = 1;j <= n;j++)
            {
                if(s1[j] != s2[i+j])    v.push_back(j);
            }
        }
    }
    cout << ans << endl;
    for(int i = 0;i < v.size();i++) cout << v[i] << " ";
    cout << endl;
    return 0;
}
View Code

C.先按l排序,遍历每一段,维护一个优先队列,每次把当前之前的段从优先队列中拿出来,更新对应长度的最小花费,然后把该段放进优先队列。

技术分享
#include<bits/stdc++.h>
using namespace std;

int n,x;
map<int,int> mp;
struct xx
{
    int l,r,c;
    friend bool operator <(xx a,xx b)
    {
        return a.l < b.l;
    }
}a[200005];
struct yy
{
    int r,len,c;
    yy(int a,int b,int cc):r(a),len(b),c(cc){};
    friend bool operator <(yy a,yy b)
    {
        return a.r > b.r;
    }
};
priority_queue<yy> q;

int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> x;
    for(int i = 1;i <= n;i++)   cin >> a[i].l >> a[i].r >> a[i].c;
    sort(a+1,a+1+n);
    int ans = 2e9+5;
    for(int i = 1;i <= n;i++)
    {
        while(!q.empty() && q.top().r < a[i].l)
        {
            if(!mp.count(q.top().len))  mp[q.top().len] = q.top().c;
            else    mp[q.top().len] = min(mp[q.top().len],q.top().c);
            q.pop();
        }
        int len = a[i].r-a[i].l+1;
        if(mp.count(x-len)) ans = min(ans,a[i].c+mp[x-len]);
        q.push(yy(a[i].r,len,a[i].c));
    }
    if(ans == 2e9+5)    cout << -1 << endl;
    else    cout << ans << endl;
    return 0;
}
View Code

D.暴力dp刚好卡过。

技术分享
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;

int t,l,r;
long long dp[5000005],f[5000005];

int main()
{
    ios::sync_with_stdio(0);
    cin >> t >> l >> r;
    for(int i = 1;i <= r;i++)
    {
        f[i] = (long long)i*(i-1)/2;
        dp[i] = f[i];
    }
    for(int i = 2;i <= r;i++)
    {
        for(int j = i,k = 1;j <= r;j += i,k++)  dp[j] = min(dp[j],dp[i]*k+f[k]);
    }
    long long tt = 1,ans = 0;;
    for(int i = l;i <= r;i++)
    {
        ans = (ans+dp[i]%MOD*tt)%MOD;
        tt = tt*t%MOD;
    }
    cout << ans << endl;
    return 0;
}
View Code

 

Codeforces_822

标签:bsp   cto   main   map   长度   alt   string   std   bit   

原文地址:http://www.cnblogs.com/zhurb/p/7226749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!