当前位置:Gxlcms > mysql > CodeforcesRound#294(Div.2)

CodeforcesRound#294(Div.2)

时间:2021-07-01 10:21:17 帮助过:32人阅读

519A A and B and Chess /*********************************************** * Author: fisty * Created Time: 2015/2/28 21:12:09 * File Name : A.cpp *********************************************** */#include iostream#include cstring#include dequ

519A

A and B and Chess

/***********************************************
 * Author: fisty
 * Created Time: 2015/2/28 21:12:09
 * File Name   : A.cpp
 *********************************************** */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define Debug(x) cout << #x << " " << x < P;
#define FOR(i, a, b) for(int i = a;i < b; i++)

int _white(char c){
    int n;
    switch(c){
        case 'Q': n = 9;break;
        case 'R': n = 5;break;
        case 'B': n = 3;break;
        case 'N': n = 3;break;
        case 'P': n = 1;break;
        dafault: n = 0;break;
    }
    return n;
}

int _black(char c){
    int n;
    switch(c){
        case 'q': n = 9;break;
        case 'r': n = 5;break;
        case 'b': n = 3;break;
        case 'n': n = 3;break;
        case 'p': n = 1;break;
        dafault: n = 0;break;
    }
    return n;
}
int main() {
    //freopen("in.cpp", "r", stdin);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int white = 0;int black = 0;
    FOR(i, 0, 8){      
        cin >> s;
        for(int j = 0;j < s.length(); j++){
            if(s[j] <= 'Z' && s[j] >= 'A'){
                white += _white(s[j]);
            }else if(s[j] <= 'z' && s[j] >= 'a'){
                black += _black(s[j]);
            }
        }
    }
    //Debug(white);
    //Debug(black);
    if(white > black){
        cout << "White" << endl;
    }else if(white < black){
        cout << "Black" << endl;
    }else{
        cout << "Draw" << endl;
    }
    return 0;
}
519B

A and B and Compilation Errors

A和B 比较,B和C比较。全部排序,遇到第一个不同数字输出并跳出比较
/***********************************************
 * Author: fisty
 * Created Time: 2015/2/28 21:43:51
 * File Name   : 294B.cpp
 *********************************************** */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define Debug(x) cout << #x << " " << x < P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
#define MAX_N 100100 
int a[MAX_N], b[MAX_N], c[MAX_N];
int main() {
    //freopen("in.cpp", "r", stdin);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;   
    cin >> n;
    Memset(a, 0);
    Memset(b, 0);
    Memset(c, 0);
    FOR(i, 0, n){
        cin >> a[i];
    }
    FOR(i, 0, n-1){
        cin >> b[i];
    }
    FOR(i, 0, n-2){
        cin >> c[i];
    }
    sort(a, a + n);
    sort(b, b + n-1);
    sort(c, c + n-2);
    for(int i = 0;i < n; i++){
        if(a[i] != b[i]){
            cout << a[i] << endl;
            break;
        }
    }
    for(int i = 0;i < n-1; i++){
        if(b[i] != c[i]){
            cout << b[i] << endl;
            break;
        }
    }
    return 0;
}


519C

A and B and Team Training

如果n > m 那么采取 n 取两个m 取一个的方案,


/***********************************************
 * Author: fisty
 * Created Time: 2015/2/28 21:54:12
 * File Name   : 294C.cpp
 *********************************************** */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define Debug(x) cout << #x << " " << x < P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
#define MAX_N 8000
int main() {
    //freopen("in.cpp", "r", stdin);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;   
    cin >> n >> m;
    int ans = 0;
    while(n >= 1 && m >= 1 && m + n >= 3){
        ans++;
        if(n > m){
            n -= 2;
            m--;
        }else{
            m -= 2;
            n--;
        }
    }
    cout << ans << endl;
    return 0;
}

519D

A and B and Interesting Substrings

首先维护前缀和,mp[i][v]表示以字符i结束的前缀和为V出现了几次

根据题目要求,如果字符u 和 v 中间值为零 那么两者的前缀和相等.

/***********************************************
 * Author: fisty
 * Created Time: 2015/2/28 22:46:13
 * File Name   : 294D.cpp
 *********************************************** */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define Debug(x) cout << #x << " " << x < P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
#define MAX_N 100000
string s;
int a[30];
map mp[MAX_N];
int main() {
    //freopen("in.cpp", "r", stdin);
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i = 0;i < 26; i++){
        cin >> a[i];
    }
    cin >> s;
    int n = s.length();
    LL ans = 0;
    LL v = 0;
    for(int i = 0;i < n; i++){
        ans += mp[s[i]-'a'][v];
        v += a[s[i]-'a'];
        mp[s[i]-'a'][v]++;
    }
    cout << ans << endl;
    return 0;
}

人气教程排行