Codeforces_835

A.比较两人总时间。

#include<bits/stdc++.h>
using namespace std;

int s,v1,v2,t1,t2;

int main()
{
    ios::sync_with_stdio(false);
    cin >> s >> v1 >> v2 >> t1 >> t2;
    int x1 = s*v1+2*t1,x2 = s*v2+2*t2;
    if(x1 < x2) cout << "First" << endl;
    else if(x1 > x2)    cout << "Second" << endl;
    else    cout << "Friendship" << endl;
    return 0;
}
View Code

B.记录每个数值个9的差的个数,贪心大的。

#include<bits/stdc++.h>
using namespace std;

int k,cnt[10];
string s;

int main()
{
    ios::sync_with_stdio(false);
    cin >> k >> s;
    int sum = 0;
    for(int i = 0;i < s.length();i++)
    {
        sum += s[i]-'0';
        cnt[9-s[i]+'0']++;
    }
    int ans = 0,now = 9;
    while(sum < k)
    {
        while(cnt[now] == 0)    now--;
        cnt[now]--;
        sum += now;
        ans++;
    }
    cout << ans << endl;
    return 0;
}
View Code

C.给周期内每个时间点都开数组,二维前缀和。

#include<bits/stdc++.h>
using namespace std;

int n,q,c,ans[105][105][15] = {0};

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> q >> c;
    for(int i = 1;i <= n;i++)
    {
        int x,y,z;
        cin >> x >> y >> z;
        for(int j = 0;j <= c;j++)   ans[x][y][j] += (j+z)%(c+1);
    }
    for(int k = 0;k <= c;k++)
    {
        for(int i = 1;i <= 100;i++)
        {
            for(int j = 1;j <= 100;j++) ans[i][j][k] += ans[i][j-1][k]+ans[i-1][j][k]-ans[i-1][j-1][k];
        }
    }
    while(q--)
    {
        int t,x1,x2,y1,y2;
        cin >> t >> x1 >> y1 >> x2 >> y2;
        t %= (c+1);
        cout << ans[x2][y2][t]-ans[x1-1][y2][t]-ans[x2][y1-1][t]+ans[x1-1][y1-1][t] << endl;
    }
    return 0;
}
View Code

D.区间dp。

#include<bits/stdc++.h>
using namespace std;

string s;
int dp[5005][5005] = {0},ans[5005] = {0};

int main()
{
    ios::sync_with_stdio(0);
    cin >> s;
    s = ' '+s;
    for(int i = 1;i < s.length();i++)   dp[i][i] = 1;
    for(int i = 2;i < s.length();i++)
    {
        if(s[i-1] == s[i])  dp[i-1][i] = 2;
    }
    for(int len = 3;len < s.length();len++)
    {
        for(int l = 1;l+len-1 < s.length();l++)
        {
            int r = l+len-1;
            if(s[l] != s[r] || !dp[l+1][r-1])    continue;
            dp[l][r] = dp[l][l+len/2-1]+1;
        }
    }
    for(int i = 1;i < s.length();i++)
    {
        for(int j = i;j < s.length();j++)   ans[dp[i][j]]++;
    }
    for(int i = s.length()-1;i >= 1;i--)    ans[i] += ans[i+1];
    for(int i = 1;i < s.length();i++)   cout << ans[i] << " ";
    cout << endl;
    return 0;
}
View Code

E.因为有两个y,先把两个y划分进不同的组,把n个位置按位运算。每一位对应的值异或,统计只含一个y的位,10次。任取其中一位,对n个数划分成2块,之后对某一块少的二分找y的位置,9次。因为已经所有只含一个y的位,异或可得另一个y的位置。

#include<bits/stdc++.h>
using namespace std;

int n,x,y;


int ask(vector<int> v)
{
    if(v.empty())   return 0;
    cout << "? " << v.size();
    for(int i = 0;i < v.size();i++) cout << " " << v[i];
    cout << endl;
    int x;
    cin >> x;
    return x;
}

int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> x >> y;
    int diff = 0,diffb;
    for(int i = 0;i < 10;i++)
    {
        vector<int> v;
        for(int j = 1;j <= n;j++)
        {
            if(j&(1<<i))    v.push_back(j);
        }
        int t = ask(v);
        if(t == y || t == (x^y))
        {
            diff |= (1<<i);
            diffb = i;
        }
    }
    vector<int> a,b;
    for(int i = 1;i <= n;i++)
    {
        if(i&(1<<diffb))    a.push_back(i);
        else    b.push_back(i);
    }
    if(a.size() > b.size()) swap(a,b);
    int l = 0,r = a.size()-1;
    while(l < r)
    {
        int mid = (l+r)/2;
        vector<int> v;
        for(int i = l;i <= mid;i++) v.push_back(a[i]);
        int t = ask(v);
        if(t == y ||t == (x^y)) r = mid;
        else    l = mid+1;
    }
    int ans1 = a[l],ans2 = ans1^diff;
    if(ans1 > ans2) swap(ans1,ans2);
    cout << "! " << ans1 << " " << ans2 << endl;
    return 0;
}
View Code

 

posted @ 2017-08-01 14:21  zzzzzzzzhu  阅读(148)  评论(0编辑  收藏  举报