题目链接

题意

两人赛马,每居获胜得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. PHP hexdec() 函数

    hexdec() 函数把十六进制转换为十进制. 语法 hexdec(hex_string) 参数 描述 hex_string 必需.规定要转换的十六进制数. 说明 返回与 hex_string 参数所 ...

  2. 解决Ubuntu中vi命令的编辑模式下不能正常使用方向键和退格键的问题

    在Ubuntu中,进入vi命令的编辑模式,发现按方向键不能移动光标,而是会输出ABCD,以及退格键也不能正常删除字符.这是由于Ubuntu预装的是vim-tiny,而我们需要使用vim-full,解决 ...

  3. <a>與<link>的區別

    <a>連接網頁: <link>定義文檔與外部資源的關係或引用外部樣式表,屬性ref表示連接對象的類型,stylesheet表示連接的是css類型的. 參考資料: https:/ ...

  4. ansible系列2-常用命令

    copyansible oldboy -m copy -a "src=/etc/hosts dest=/tmp/ mode=0600 owner=oldboy group=oldboy &q ...

  5. POJ1019-Number Sequence-数数。。

    1 12 123 1234 把数按照这样的形式拍成一排,给一个序号求出那个序号对应的数. 当出现两位数.三位数时,要麻烦的处理一下. #include <cstdio> #include ...

  6. Codeforces Round #394 (Div. 2) C. Dasha and Password

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Caused by: org.xml.sax.SAXParseException; lineNumber: 1

    百分百是你的MYBATIS 的xml 里面的 xml节点没写对,或者忘记关闭,或者格式不对

  8. 【POI每日题解 #5】 DWU-Double-row

    题目链接 [POI2005]DWU-Double-row wwwww 之前写了半小时 一卡机 没啦QAQ 简单说一下吧 [吐血ing 这道题长得好二分图啊 所以本能地连边 一种是A边 连可交换的数对 ...

  9. LOJ #2541. 「PKUWC 2018」猎人杀(容斥 , 期望dp , NTT优化)

    题意 LOJ #2541. 「PKUWC 2018」猎人杀 题解 一道及其巧妙的题 , 参考了一下这位大佬的博客 ... 令 \(\displaystyle A = \sum_{i=1}^{n} w_ ...

  10. 7种JVM垃圾收集器特点,优劣势、及使用场景

    今天继续JVM的垃圾回收器详解,如果说垃圾收集算法是JVM内存回收的方法论,那么垃圾收集器就是内存回收的具体实现. 一.常见的垃圾收集器有3类 1.新生代的收集器包括 Serial PraNew Pa ...