题意:田忌赛马,每胜一局就得200,负一局少200,问最多得多少钱。

析:贪心,如果最快的马比齐王的还快,就干掉它,如果最慢的马比齐王的马快,就干掉它,否则用最慢的马去和齐王最快的马比。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn], b[maxn]; int main(){
while(scanf("%d", &n) == 1 && n){
for(int i = 0; i < n; ++i) scanf("%d", a+i);
for(int i = 0; i < n; ++i) scanf("%d", b+i);
sort(a, a + n, greater<int>());
sort(b, b + n, greater<int>());
int ans = 0;
int fro1 = 0, fro2 = 0;
int rear1 = n-1, rear2 = n-1;
while(fro1 <= rear1){
if(a[fro1] > b[fro2]){
ans += 200;
++fro1;
++fro2;
}
else if(a[rear1] > b[rear2]){
ans += 200;
--rear1;
--rear2;
}
else if(a[rear1] <= b[rear2]){
if(a[rear1] < b[fro2]) ans -= 200;
--rear1;
++fro2;
}
}
printf("%d\n", ans);
}
return 0;
} /*
3
15 12 9
16 13 9 5
7 8 9 12 15
7 8 9 13 16 4
1 2 4 5
2 3 3 4
*/

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

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

    题目链接 题意 两人赛马,每居获胜得200,平局无事发生,输了也输200.求最优的策略使赢的钱最多. 分析 排序,从最快的开始比,若比不过,则用最弱的消耗最强的.模拟即可. #include<i ...

  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. RDLC报表-分组序号

    1.RowNumber("group_name")是按行每个分组重新1,2,3这样来显示的,如果需要按每个分组来显示1,并且递增,则需要通过自定义代码来控制,在报表-属性-代码里插 ...

  2. SpringBoot学习笔记(12):计划任务

    SpringBoot学习笔记(12):计划任务 计划任务 在企业的实践生产中,可能需要使用一些定时任务,如月末.季末和年末需要统计各种各样的报表,每周自动备份数据等. 在Spring中使用定时任务 1 ...

  3. Zookeeper四字命令

    ZooKeeper 支持某些特定的四字命令(The Four Letter Words)与其进行交互.它们大多是查询命令,用来获取 ZooKeeper 服务的当前状态及相关信息.用户在客户端可以通过 ...

  4. 获取HDC的几种方法

    当需要在显示器上(当然包括打印机等设备上)绘图时,或者写文字的时候,需要取得设备的上下文句柄,即HDC,本文以下都称为HDC.那么,有哪些办法取得HDC呢? 1 BeginPain()和EndPain ...

  5. android的GPS代码分析JNI如何HAL之间如何设置回调函数【转】

    本文转载自:http://blog.csdn.net/kmesg/article/details/6531577 本文只关注JNI和HAL的接口部分 在jni的android_location_Gps ...

  6. 获取url的参数

    function getPrams () { var url, urlPrams, urlPramsArr=[], item=[], prams={}; url = location.href; if ...

  7. properties文件的解析

    此文章是从网上看到一篇实用小文章,感觉不过,摘录下来的!如有问题,可及时联系,可立刻做相应处理! Java读取.properties 配置文件的几种方法 在做java工程时, 经常会将一些配置信息放到 ...

  8. Shell读取文件内容【转】

    while read wOne wTwo wThreedo    [ -z $wOne ] && continue           #测试此行内容是否为空    xxx=$wOne ...

  9. MySQL活动期间订单满600元并且在活动日期之前超过30天没有下过单_20161030

    计算 活动期间订单满600元并且在活动日期之前超过30天没有下过单 首先拿到这个需求,首先需要明确活动日期区间 10.29-10.31,其次要取这个时间段内某天订单额最高的那天及订单额,再次需要判断这 ...

  10. MySQL如何计算动销率_20161025

    动销率一般反映在采购管理上,它的公式为:商品动销率=(动销品种数 /仓库总品种数)*100% . 也可以理解为销售的商品数量和仓库库存的商品数量,假如你仓库里有100个品种,在上月销售了50种,动销率 ...