题目链接

题意

两人赛马,每居获胜得200,平局无事发生,输了也输200。求最优的策略使赢的钱最多。

分析

排序,从最快的开始比,若比不过,则用最弱的消耗最强的。模拟即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
#include <vector>
#include<bitset>
#include<map>
#include<deque>
#include<stack>
using namespace std;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
const int inf = 0x3f3f3f3f;
const int maxn = 1e6+;
const int mod = +;
#define lson l,m,2*rt
#define rson m+1,r,2*rt+1
typedef long long ll;
int a[],b[];
int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int n;
while(scanf("%d",&n)&&n){
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]);
int sta=,stb=,eda=n,edb=n;
sort(a+,a++n);
sort(b+,b++n);
int ans=;
for(int i=;i<=n;i++){
if(a[eda]>b[edb]){
ans+=;
eda--;
edb--;
}else if(a[eda]<b[edb]){
ans-=;
sta++;
edb--;
}else{
if(a[sta]>b[stb]){
ans+=;
sta++;
stb++;
}else if(a[sta]<b[edb]){
ans-=;
sta++;
edb--;
}else{
sta++;
edb--;
}
}
}
printf("%d\n",ans);
}
return ;
}

UVALive - 3266 Tian Ji -- The Horse Racing(贪心)的更多相关文章

  1. UVaLive 3266 Tian Ji -- The Horse Racing (贪心)

    题意:田忌赛马,每胜一局就得200,负一局少200,问最多得多少钱. 析:贪心,如果最快的马比齐王的还快,就干掉它,如果最慢的马比齐王的马快,就干掉它,否则用最慢的马去和齐王最快的马比. 代码如下: ...

  2. UVa LA 3266 - Tian Ji -- The Horse Racing 贪心,不只处理一端,也处理另一端以理清局面 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  3. POJ-2287.Tian Ji -- The Horse Racing (贪心)

    Tian Ji -- The Horse Racing Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 17662   Acc ...

  4. hdu_1052 Tian Ji -- The Horse Racing 贪心

    Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  5. HDU 1052 Tian Ji -- The Horse Racing(贪心)

    题目来源:1052 题目分析:题目说的权值匹配算法,有点误导作用,这道题实际是用贪心来做的. 主要就是规则的设定: 1.田忌最慢的马比国王最慢的马快,就赢一场 2.如果田忌最慢的马比国王最慢的马慢,就 ...

  6. HDU-1052 Tian Ji -- The Horse Racing 贪心 考虑特殊位置(首尾元素)的讨论

    题目链接:https://cn.vjudge.net/problem/HDU-1052 题意 田忌赛马问题扩展版 给n匹马,马的能力可以相同 问得分最大多少 思路 贪心做得还是太少,一开始一点思虑都没 ...

  7. 【贪心】[hdu1052]Tian Ji -- The Horse Racing(田忌赛马)[c++]

    Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...

  8. HDU 1052 Tian Ji -- The Horse Racing【贪心在动态规划中的运用】

    算法分析: 这个问题很显然可以转化成一个二分图最佳匹配的问题.把田忌的马放左边,把齐王的马放右边.田忌的马A和齐王的B之间,如果田忌的马胜,则连一条权为200的边:如果平局,则连一条权为0的边:如果输 ...

  9. HDU 1052 Tian Ji -- The Horse Racing (贪心)(转载有修改)

    Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

随机推荐

  1. PAT 1066 图像过滤

    https://pintia.cn/problem-sets/994805260223102976/problems/994805266514558976 图像过滤是把图像中不重要的像素都染成背景色, ...

  2. Vim列模式(块选择)输入

    https://www.ibm.com/developerworks/cn/linux/l-cn-vimcolumn/ https://www.zhihu.com/question/19968224 ...

  3. Java微信二次开发(六)

    Token定时获取 需要导入库:添加log4j(slf4j-api-1.5.10.jar,slf4j-log4j12-1.5.10.jar,log4j-1.2.15.jar,并且在src下添加log4 ...

  4. redis map存储的注意点

  5. Linux学习之/etc/init.d/目录和rc.local脚本

    init.d目录中包含很多系统服务的启动和停止脚本,比较常用的就是网络服务,当你修改了网络配置时,可以自行 sudo /etc/init.d/networking restart  命令来重启网络服务 ...

  6. Codeforces Round #419 (Div. 2) B. Karen and Coffee

    To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...

  7. day6 字典

    字典的创建方式 注意 字典是无序的 1. dic{"name":"yang","age":35} 常用还是用这个 2. dic3 = dic ...

  8. CDQ分治总结(CDQ,树状数组,归并排序)

    闲话 CDQ是什么? 是一个巨佬,和莫队.HJT(不是我这个蒟蒻)一样,都发明出了在OI中越来越流行的算法/数据结构. CDQ分治思想 分治就是分治,"分而治之"的思想. 那为什么 ...

  9. 自学Linux Shell7.3-linux共享文件

    点击返回 自学Linux命令行与Shell脚本之路 7.3-linux共享文件 在linux系统中共享文件的方法是通过创建组. 1. linux为每个文件和目录存储了3个额外的信息位: SUID设置用 ...

  10. AtCoder Regular Contest 067 F - Yakiniku Restaurants

    题意: 有n个餐厅排成一排,第i个与第i+1个之间距离是Ai. 有m种食物,每种食物只能在一个餐厅里吃,第j种食物在第i个餐厅里吃的收益是$b[i][j]$. 选择每种食物在哪个餐厅里吃,使收益减去走 ...