A -- A. Quailty and Playing Cards 模拟 + 思考

http://www.ifrog.cc/acm/problem/1036?contest=1005&no=0

分类,考虑Q神出的是第一张或者是第二张,然后对手出那些牌来应付。

Q神出第一张和第二张的情况是分开的,应该取两者的最大值。(因为要取最优情况)

而Q神出第一张的时候,对手出任意一张,是取min,保证对手出牌最优

注意这里花色是没用的。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
int book[500];
struct node {
    int num, val;
} a[40];
int add(int val) {
    if (val != 14) return val;
    else return 1;
}
int judge(node a, node b, int who) {
    if (a.num > b.num) {
        return add(a.num);
    } else if (a.num == b.num) {
        if (who == 1) {
            return add(a.num);
        } else return -add(b.num);
    } else {
        return -add(b.num);
    }
}
void work() {
    for (int i = 1; i <= 4; ++i) {
        char str[10];
        scanf("%s", str + 1);
        a[i].num = book[str[1]];
        a[i].val = book[str[2]];
    }
//    for (int i = 1; i <= 4; ++i) {
//        cout << a[i].num << " " << a[i].val << endl;
//    }
//    cout <<"***" << endl;
    int ans = inf;
    int t = 0;
    if (judge(a[1], a[3], 1) > 0) {
        t += judge(a[1], a[3], 1);
        t += judge(a[2], a[4], 1);
    } else {
        t += judge(a[1], a[3], 1);
        t += judge(a[2], a[4], 2);
    }
    ans = min(ans, t);
    t = 0;
    if (judge(a[1], a[4], 1) > 0) {
        t += judge(a[1], a[4], 1);
        t += judge(a[2], a[3], 1);
    } else {
        t += judge(a[1], a[4], 1);
        t += judge(a[2], a[3], 2);
    }
    ans = min(ans, t);

    t = 0;
    int ans2 = inf;
    if (judge(a[2], a[3], 1) > 0) {
        t += judge(a[2], a[3], 1);
        t += judge(a[1], a[4], 1);
    } else {
        t += judge(a[2], a[3], 1);
        t += judge(a[1], a[4], 2);
    }
    ans2 = min(ans2, t);
    t = 0;
    if (judge(a[2], a[4], 1) > 0) {
        t += judge(a[2], a[4], 1);
        t += judge(a[1], a[3], 1);
    } else {
        t += judge(a[2], a[4], 1);
        t += judge(a[1], a[3], 2);
    }

    ans2 = min(ans2, t);

//    cout << ans << " " << ans2 << endl;

    ans = max(ans, ans2);
    cout << ans << endl;
}
int main() {
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    book['A'] = 14;
    book['K'] = 13;
    book['Q'] = 12;
    book['J'] = 11;
    book['T'] = 10;
    for (int i = '2'; i <= '9'; ++i) {
        book[i] = i - '0';
    }
    book['H'] = 4;
    book['S'] = 3;
    book['C'] = 2;
    book['D'] = 1;
    int t;
    scanf("%d", &t);
    while(t--) {
        work();
    }
    return 0;
}
View Code

 

posted on 2016-09-25 13:09  stupid_one  阅读(252)  评论(0编辑  收藏  举报

导航