博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
No.34 - Codeforces777B 田忌赛马 贪心
阅读量:4061 次
发布时间:2019-05-25

本文共 1332 字,大约阅读时间需要 4 分钟。

题目要求给出两种策略:

1,田忌要尽可能少输
2,田忌要尽可能多赢

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

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

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

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

// ShellDawn// Codeforces 777B// No.34#include
#include
#include
#include
#include
#include
#define MM(x,y) memset(x,y,sizeof(x))#define INF 0x3f3f3f3f#define LL long longusing namespace std;//#define maxn 1005int 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;}

转载地址:http://pnwji.baihongyu.com/

你可能感兴趣的文章
IOS开发的开源库
查看>>
IOS开发的开源库
查看>>
Jenkins - sonarqube 代码审查
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成(一)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 单机部署(二)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 高可用集群部署(三)
查看>>
Golang struct 指针引用用法(声明入门篇)
查看>>
Linux 粘滞位 suid sgid
查看>>
C#控件集DotNetBar安装及破解
查看>>
Winform皮肤控件IrisSkin4.dll使用
查看>>
Winform多线程
查看>>
C# 托管与非托管
查看>>
Node.js中的事件驱动编程详解
查看>>
mongodb 命令
查看>>
MongoDB基本使用
查看>>
mongodb管理与安全认证
查看>>
nodejs内存控制
查看>>
nodejs Stream使用中的陷阱
查看>>
MongoDB 数据文件备份与恢复
查看>>
数据库索引介绍及使用
查看>>