No.34 - Codeforces777B 田忌赛马 贪心

题目要求给出两种策略:
1,田忌要尽可能少输
2,田忌要尽可能多赢

无非就是改变赢局和平局的比例。

当尽可能少输时,那就要先采取平局,然后再尽量取胜,剩下就是必输了。

当尽可能多赢时,那就要先尽量取胜,然后尽量平局,剩下就是必输了。

枚举时暴力做的,可能比最优双端队列贪心要慢。

// ShellDawn
// Codeforces 777B
// No.34

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<math.h>
#define MM(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
//

#define maxn 1005
int N;
int VA[maxn];
int VB[maxn];
int A[maxn];
int B[maxn];
int ans = 0;
int res = 0;

void equal(){
    int L = 1, R = 1;
    while( L <= N && R<=N){
        while(VA[L] == 1) L++;
        while(VB[R] == 1) R++;
        if(L > N || R > N) break;
        if(A[L] > B[R]) R++;
        else if(A[L] < B[R]) L++;
        else{
            //printf("<%d %d> (等于) <%d %d>\n",L,A[L],R,B[R]);
            VA[L] = VB[R] = 1;
            res ++ ;
        }
    }
}

void win(){
    for(int i=1;i<=N;i++){
        if(VA[i] == 1) continue;
        for(int j=N;j>=1;j--){
            if(VB[j] == 0 && A[i] > B[j]){
                //printf("<%d %d> (大于) <%d %d>\n",i,A[i],j,B[j]);
                VA[i] = 1;
                ans++;
                VB[j] = 1;   
                break;
            }
        }
    }
}

int main(){
    scanf("%d",&N);
    getchar();
    for(int i=1;i<=N;i++){
        char c = getchar();
        B[i] = c - '0';
    }
    getchar();
    for(int i=1;i<=N;i++){
        char c = getchar();
        A[i] = c - '0';
    }
    sort(A+1,A+N+1);
    sort(B+1,B+N+1);
    
    MM(VA,0); MM(VB,0);
    ans = 0; res = 0; equal(); win();
    printf("%d\n",N-ans-res);
    MM(VA,0); MM(VB,0);
    ans = 0; res = 0; win(); equal();
    printf("%d\n",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值