总时间限制: 5000ms 内存限制: 65536kB
描述
Here is a famous story in Chinese history.
That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and others.

Both of Tian and the king have three horses in different classes, namely, regular, plus, and super. The rule is to have three rounds in a match; each of the horses must be used in one round. The winner of a single round takes two hundred silver dollars from the loser.

Being the most powerful man in the country, the king has so nice horses that in each class his horse is better than Tian’s. As a result, each time the king takes six hundred silver dollars from Tian.

Tian Ji was not happy about that, until he met Sun Bin, one of the most famous generals in Chinese history. Using a little trick due to Sun, Tian Ji brought home two hundred silver dollars and such a grace in the next match.

It was a rather simple trick. Using his regular class horse race against the super class from the king, they will certainly lose that round. But then his plus beat the king’s regular, and his super beat the king’s plus. What a simple trick. And how do you think of Tian Ji, the high ranked official in China?

Were Tian Ji lives in nowadays, he will certainly laugh at himself. Even more, were he sitting in the ACM contest right now, he may discover that the horse racing problem can be simply viewed as finding the maximum matching in a bipartite graph. Draw Tian’s horses on one side, and the king’s horses on the other. Whenever one of Tian’s horses can beat one from the king, we draw an edge between them, meaning we wish to establish this pair. Then, the problem of winning as many rounds as possible is just to find the maximum matching in this graph. If there are ties, the problem becomes more complicated, he needs to assign weights 0, 1, or -1 to all the possible edges, and find a maximum weighted perfect matching…

However, the horse racing problem is a very special case of bipartite matching. The graph is decided by the speed of the horses – a vertex of higher speed always beat a vertex of lower speed. In this case, the weighted bipartite matching algorithm is a too advanced tool to deal with the problem.

In this problem, you are asked to write a program to solve this special case of matching problem.
输入
The input consists of up to 50 test cases. Each case starts with a positive integer n ( n<=1000) on the first line, which is the number of horses on each side. The next n integers on the second line are the speeds of Tian’s horses. Then the next n integers on the third line are the speeds of the king’s horses. The input ends with a line that has a single `0’ after the last test case.
输出
For each input case, output a line containing a single number, which is the maximum money Tian Ji will get, in silver dollars.
样例输入
3
92 83 71
95 87 74
2
20 20
20 20
2
20 19
22 18
0
样例输出
200
0
0
来源
Shanghai 2004

说实话 这个题除了题面描述有点恶心外,思路和当年课文中学到的一模一样,只要各种情况都想到了这个题就很好了

首先将自己的和敌方的馬排序
然后我方最差的和地方最差的能比过吗?
    能的话看下一匹,我方+1
    不能的话将它废物利用和对面最强的比,消耗,对面+1
    平局的话
        判断当前我方最快的马的情况,如果他比敌方的马还强,则不替换直接上(因为对面不管上哪个都赢不了),我方+1
        否则就上最猜的消耗对面的,敌方+1

最后使用我方赢得数量-敌方赢得数量 *200就是答案

说明:代码不是本人写的,写好后看别人思路,太牛逼了,我当时枚举的代码比这长多了,意会咯
代码如下

awin=bwin=0;
afast=bfast=n-1;
aslow=bslow=0;
for(int i=0;i<n;++i){if(a[aslow]>b[bslow]){awin++;aslow++; bslow++;}else if(a[aslow]<b[bslow]){bwin++;aslow++; bfast--;}else{if(a[afast]>b[bfast]){awin++;afast--; bfast--;}else if(a[aslow]<b[bfast]){bwin++;aslow++; bfast--;}}
}

2018北大暑校acm算法训练课程 Tian Ji -- The Horse Racing 贪心相关推荐

  1. 2018北大暑校acm算法训练课程 海贼王之伟大航路 状压dp

    题干信息: "我是要成为海贼王的男人!",路飞一边喊着这样的口号,一边和他的伙伴们一起踏上了伟大航路的艰险历程.路飞他们伟大航路行程的起点是罗格镇,终点是拉夫德鲁(那里藏匿着&qu ...

  2. Tian Ji -- The Horse Racing 贪心算法

    Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. ...

  3. Tian Ji -- The Horse Racing(田忌赛马)/贪心算法

    Tian Ji – The Horse Racing(田忌赛马) 田忌赛马的故事 (可以直接看题) Here is a famous story in Chinese history. "T ...

  4. 贪心算法 003:Tian Ji -- The Horse Racing

    003:Tian Ji – The Horse Racing 总时间限制: 5000ms 内存限制: 65536kB 描述 Here is a famous story in Chinese hist ...

  5. 杭电1052-Tian Ji -- The Horse Racing 贪心算法(有思路和注释)

    Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. ...

  6. ACM算法训练【逆序对的数量】

    ACM算法训练[逆序对的数量] 题目说明 数据范围 样例 分析与代码 题目说明 数据范围 样例 分析与代码 ①归并排序基本思想: ②在归并的过程中,逆序对出现的三种情况: a.全部出现在左边的区间 b ...

  7. ACM算法训练【模拟队列】

    ACM算法训练[模拟队列] 1.题目 2.样例 3.代码 1.题目 2.样例 输入样例: 10 push 6 empty query pop empty push 3 push 4 pop query ...

  8. “程序设计与算法训练”课程设计“二值图像数字水印技术的实践”

    数据结果课程设计(题目抄袭自某牛逼985高校). github项目地址(含报告等) 课程编号:0521733B                                              ...

  9. ACM算法训练赛——STL(完结)

    STL训练赛 A - JiaoZhu and SC #include <bits/stdc++.h> #define int long long #define rep(i, a, b) ...

最新文章

  1. excel排名_excel函数技巧:看看按条件排名要如何进行?
  2. 移动端触屏click点击事件延迟问题,以及tap的解决方案
  3. linux桌面lxde 安装_Ubuntu 18.04下安装Lxde轻量桌面系统和VNC服务器
  4. mysql从字符串中取子字符串_如何从开始于MySQL中特定位置的字符串中提取子字符串?...
  5. wtl单文档选项_Vite 中文文档翻译
  6. .net SerialPort
  7. Linux命令之hexdump
  8. PostgreSQL 函数调试、诊断、优化 auto_explain
  9. The Pragmatic Programmer 读书笔记之中的一个 DRY-Don’t Repeat Youself
  10. CLR线程池的作用与原理浅析
  11. Linux安装Oracle,卡在60%处的解决方法
  12. network 网络带宽
  13. SVN安装及使用教程图文详解
  14. 微信小程序:组件间的传值
  15. 2022-2027年(新版)中国石墨烯行业竞争态势及发展前景预测报告
  16. 多系统引导启动项详解和更改启动内核的方法
  17. 设计师最常用网站汇总
  18. BZOJ 2752 [HAOI2012]高速公路(road):线段树【维护区间内子串和】
  19. ipad/iphone的浏览器,为啥可以播放优酷土豆等在线视频
  20. 侍魂哪个服务器人最多,经典街机游戏《侍魂》里帅气的人物,你最喜欢哪个?...

热门文章

  1. python模拟CryptoJS.AES.decrypt解密
  2. automake java_autoconf与automake加入新的编译选项
  3. 微信公众号欢迎大家一起交流,一起分享
  4. halcon瑕疵检测的简单Demo
  5. JavaScript-----tab栏的切换
  6. Matlab绘制箭头坐标轴图形
  7. JAVA设计模式六大原则:(5)迪米特法则
  8. openmv与stm32之间的通信学习(数字识别)
  9. xfce4解决中文输入、无声音问题
  10. 你的系统需要SMB2或者更高版本,才能访问共享