HOT!!! 欢迎参加“金山西山居-2013创意游戏程序挑战赛”!

Tian Ji -- The Horse Racing

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13712    Accepted Submission(s): 3869

Problem Description
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.

Input
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.
Output
For each input case, output a line containing a single number, which is the maximum money Tian Ji will get, in silver dollars.
Sample Input
3 92 83 71 95 87 74 2 20 20 20 20 2 20 19 22 18 0
Sample Output
200 0 0
Source
2004 Asia Regional Shanghai
Recommend
JGShining
解题报告:错了n次,终于过了,原来没考虑平局————————贪心思想,分类讨论
(1)无平局
①己方最小<对方最小,拿最小拼对方最大;
②己方最小>对方最小,直接赢;
(2)己方最小=对方最小
③己方最大>对方最大,直接赢;
④己方最大<=对方最大,拿最小拼对方最大;
⑤最小与最大都与对方相等,拿最小拼对方最大 ,己方最小=对方最大,则平局:指针往前移,cnt不变;
#include<cstdio>
#include<algorithm>
using namespace std;
int T[1005],K[1005];
int t1,t2,k1,k2,n;
void Compare(){int cnt=0;for(int i=0;i<n;i++){if(T[t1]>K[k1]){cnt++;t1++;k1++;}else if(T[t1]<K[k1]){t1++;k2--;cnt--;}else {if(T[t2]>K[k2]){t2--;k2--;cnt++;}else if(T[t2]<K[k2]){cnt--;t1++;k2--;}else if(T[t2]==K[k2]){if(T[t1]<K[k2])cnt--;k2--;t1++;}}}printf("%d\n",cnt*200);
}
int main(){while(scanf("%d",&n),n){for(int i=0;i<n;i++)scanf("%d",&T[i]);for(int i=0;i<n;i++)scanf("%d",&K[i]);sort(T,T+n);sort(K,K+n);t1=k1=0;t2=k2=n-1;Compare();}return 0;
}

hdu-1052 Tian Ji -- The Horse Racing相关推荐

  1. hdu 1052 Tian Ji -- The Horse Racing

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

  2. HDU 1052 Tian Ji -- The Horse Racing

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1052 题意:田忌赛马,贪心 #include<iostream> #include<al ...

  3. 杭电1042c语言循环,HDU杭电1052 Tian Ji - The Horse Racing答题报告

    HDU杭电1052 Tian Ji -- The Horse Racing解题报告 本人第一次写博客,希望各位大神多多指导与包涵,不足的地方还请指出,新手在此谢过啦!!! 题目描述: Time Lim ...

  4. 贪心法田忌赛马问题Java代码,hdoj 1052 Tian Ji - The Horse Racing【田忌赛马】 【贪心】...

    hdoj 1052 Tian Ji -- The Horse Racing[田忌赛马] [贪心] 思路:先按从小到大排序, 然后从最快的开始比(假设i, j 是最慢的一端, flag1, flag2是 ...

  5. HDU杭电1052 Tian Ji -- The Horse Racing解题报告

    本人第一次写博客,希望各位大神多多指导与包涵,不足的地方还请指出,新手在此谢过啦!!! 题目描述: Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

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

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

  7. OpenJudge Tian Ji -- The Horse Racing

    目录 Tian Ji -- The Horse Racing 要求: 描述: 输入 : 输出: 样例输入: 样例输出: 问题分析: 情况一: 情况二: 情况三: 最终代码: 总结: 其他思路: Tia ...

  8. Tian Ji -- The Horse Racing(贪心+STL)

    Problem:Tian Ji – The Horse Racing Description: Here is a famous story in Chinese history. "Tha ...

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

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

最新文章

  1. HR收到Dota天梯2000分玩家的简历,给不给面试的机会呢?
  2. SQL入门经典(第5版)学习笔记(三)
  3. java gson 工具类_gson工具类将Java类转换为json的使用
  4. html5 酒店入住插件,jQuery酒店类入住日期时间范围选择器插件
  5. boost::geometry::math::equals用法的测试程序
  6. python根据2点经纬度计算距离
  7. 既生瑜何生亮 access_token VS refresh_token
  8. npm ERR! cb() never called!
  9. 用户密码重设对EFS的影响
  10. 打印工资条怎么做到每个人都有表头明细_抖音百万点赞!2018年最火的5个Excel骚操作,你都会吗?...
  11. VS2010下编译mp4v2及在项目中的使用
  12. 史上最强的10大管理定律
  13. ckplayer网页播放器简易教程
  14. linux svc作用,[svc]linux性能监控
  15. 安装显卡后计算机无法启动,Win10更新显卡驱动后无法开机进入系统的解决方法...
  16. 英语单词记忆测试软件,适用于检查学生英语单词背诵情况的软件
  17. SAP中统驭科目理解及举例
  18. 史上Windows快捷键大全
  19. 自动摘要生成(一):最大边界相关算法(MMR)
  20. 都说建议新手用3Dmax,那到底学好3Dmax要多久呢?

热门文章

  1. 如何将FLV格式视频转换成高清MP4格式方法
  2. windows自带hyperv安装虚拟机ubuntu与分辨率修改
  3. w7测算计算机分级,HSW-E平台跑分竟失败:需要打补丁
  4. 货币转换python代码_演示4:python与Tkinter的货币转换,4python,币值,含,tkinter
  5. pandas计算excel两列的日期差
  6. Element UI 的日历控件,并在日期中做标注
  7. 13 个非常有用的 Python 代码片段,建议收藏!
  8. DNS Client Events 1014
  9. python如何在图片上添加文字_Python在图片中添加文字的两种方法
  10. mysql写系统_一个用PHP和MYSQL写的定饭系统_PHP