Codeforces Round #294 (Div. 2)

时间:2020-01-09 20:55:20   收藏:0   阅读:64

传送门

A

大写是白棋子,小写是黑棋子

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int check(char s){
    switch(tolower(s)){
        case 'q':return 9;
        case 'r':return 5;
        case 'n':return 3;
        case 'b':return 3;
        case 'p':return 1;
        default:return 0;
    }
}
char s[20];
int a = 0;
int b = 0;
void go(){
    int ans = 0;
    int x = strlen(s);
    for(int i = 0; i < x; i++){
        if(s[i] >= 'A' && s[i] <= 'Z')a += check(s[i]);
        else if(s[i] >= 'a' && s[i] <= 'z')b += check(s[i]);
    }
}
int main(){
    for(int i = 0 ;i < 8; i++){
        scanf("%s",s);
        go();
    }
    if(a == b)printf("Draw\n");
    else if(a > b)printf("White\n");
    else printf("Black\n");
    return 0;
}

B

2次操作,第二次对第一次操作,第三次对第二次操作,找到操作后丢失的那个数字即可,map维护,set不行,因为重复数据

#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
const int maxn = 1e5 + 5;
std::map<int, int> a;
std::map<int, int> b;
std::map<int, int> c;
int main(){
    int n;
    cin >> n;
    int x;
    for(int i = 0; i < n; i++){
        scanf("%d",&x);
        a[x]++;
    }
    for(int i = 0; i < n - 1; i++){
        scanf("%d",&x);
        b[x]++;
        a[x]--;
    }
    for(int i = 0; i < n - 2; i++){
        scanf("%d",&x);
        c[x]++;
        b[x]--;
    }
    std::map<int, int>::iterator it;
    for(it = a.begin(); it != a.end(); it++){
        if(it->second == 1){
            cout << it->first << endl;
            break;
        }
    }
    for(it = b.begin(); it != b.end(); it++){
        if(it->second == 1){
            cout << it->first << endl;
            break;
        }
    }
    return 0;
}

C 思路厉害

把n个男孩,m个女孩分组,方案1:1男2女,方案2:2男1女,问最多的组数
遍历一遍n,i就是方案1的情况,然后如果按照方案1,女孩子还有,再运用方案2,求出最大值即可

#include <iostream>
#include <cstdio>
using namespace std;
int n,m;
int go(){
    int ans = 0;
    for(int i = 0; i <= n; i++){
        int cur = i;
        int a = n - i;
        int b = m - 2 * i;
        if(b >= 0){
            cur += min(a / 2,b);
            ans = max(ans,cur);
        }
    }
    return ans;
}
int main(){
    cin >> n >> m;
    cout << go() << endl;
    return 0;
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!