亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > C++ > 正文

【貪心】[hdu1052]Tian Ji -- The Horse Racing(田忌賽馬)[c++]

2019-11-06 06:32:16
字體:
來源:轉載
供稿:網友
Tian Ji -- The Horse Racing

Time Limit: 2000/1000 MS (java/Others) Memory Limit: 65536/32768 K (Java/Others)

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

原題鏈接

貪心策略

先對田忌、齊王的馬按照速度分別排序。 對排序后的兩組馬的速度,按如下規則比較:

一、當前田忌最慢的馬比齊王最慢的馬要快,因為田忌任何馬都能贏齊王的這匹最慢的馬,就拿自己最慢的馬來和齊王比,贏一局且實力損失最小。

二、當前田忌最慢的馬比齊王最慢的馬要慢,因為田忌最慢的馬一定會輸齊王任何的馬,就拿這匹馬和齊王最快的馬比,輸一局且消耗的齊王實力最大。

三、當前田忌最快的馬比齊王最快的馬要慢,因為田忌任何馬都會輸給齊王的這匹最快的馬,就拿自己最慢的馬來和齊王比,輸一局且實力損失最小。

四、當前田忌最快的馬比齊王最快的馬要快,因為田忌最快的馬和齊王的任何馬比都會贏,就那這匹馬和齊王最快的馬比,贏一局且消耗的齊王實力最大。

一二和三四的比較順序無所謂

五、頭尾都相等時,用田忌最慢的馬消耗齊王最快的馬,出現兩種情況: - 1.齊王最快的馬比田忌最慢的馬快,輸一局。 - 2.齊王最快的馬與田忌最慢的馬相等,平一局,此時所有馬的速度都相等。

代碼[c++]

#include <cstdlib>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int HOUSEN = 1005;int main(){ int n; while(scanf("%d",&n)&&n!=0) { int tian[HOUSEN],king[HOUSEN]; for(int i=0; i<n; i++) scanf("%d",tian+i); for(int i=0; i<n; i++) scanf("%d",king+i); sort(tian,tian+n); sort(king,king+n); int tleft=0,tright=n-1; int kleft=0,kright=n-1; int win=0,lost=0; while(tleft<=tright) { if(tian[tleft]>king[kleft]) { win++; tleft++; kleft++; } else if(tian[tleft]<king[kleft]) { lost++; tleft++; kright--; } else if(tian[tright]<king[kright]) { lost++; tleft++; kright--; } else if(tian[tright]>king[kright]) { win++; tright--; kright--; } else { if(tian[tleft]<king[kright])lost++; tleft++; kright--; } } printf("%d/n",200*(win-lost)); } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美成人免费全部| 国产精品视频自拍| 亚洲精品久久久久久久久久久| 久久精品小视频| 欧美与黑人午夜性猛交久久久| 亚洲天堂免费视频| 日韩免费观看网站| 欧美极度另类性三渗透| 亚洲色图第三页| 亚洲一区二区久久久| 欧美在线亚洲一区| 国产xxx69麻豆国语对白| 久久成年人免费电影| 91精品国产91久久久久久不卡| 91精品国产精品| 77777亚洲午夜久久多人| 国产精品久久久久久久久久小说| 色哟哟亚洲精品一区二区| 中文一区二区视频| 亚洲最大激情中文字幕| 国产在线视频91| 国产精品自拍小视频| 97成人精品区在线播放| 91精品久久久久久综合乱菊| 在线午夜精品自拍| 欧美三级免费观看| 日韩精品一区二区三区第95| 欧美三级免费观看| 亚洲电影免费观看| 久热爱精品视频线路一| 91啪国产在线| 欧美精品第一页在线播放| 日韩在线观看网站| 久久久久久中文字幕| 亚洲国产精品小视频| 亚洲成人精品视频| 亚洲免费福利视频| 宅男66日本亚洲欧美视频| 精品女同一区二区三区在线播放| 日韩高清电影免费观看完整| 91影视免费在线观看| 久久精品91久久香蕉加勒比| 色香阁99久久精品久久久| 亚洲国产中文字幕在线观看| 久久久久亚洲精品国产| 欧美日韩亚洲视频一区| 欧美成人三级视频网站| 久久久综合av| 国产99久久精品一区二区永久免费| 不卡av在线播放| 成人激情免费在线| 亚洲xxxx妇黄裸体| 欧美成年人在线观看| 精品久久久香蕉免费精品视频| 国产a级全部精品| 亚洲精品短视频| 欧美黑人性猛交| 午夜精品久久久久久久男人的天堂| 欧美壮男野外gaytube| 国语自产精品视频在免费| 亚洲成人黄色网址| 亚洲人高潮女人毛茸茸| 精品日韩中文字幕| 国产极品精品在线观看| 国产精品久久久久久久午夜| 欧美国产日韩一区二区三区| 九九九热精品免费视频观看网站| 日韩中文字幕免费| 亚洲第一区第二区| 欧美国产精品va在线观看| 国产精品黄色av| 日韩在线视频免费观看高清中文| 91日本在线视频| 久久久久久尹人网香蕉| 中文字幕亚洲欧美日韩2019| 色诱女教师一区二区三区| 亚洲va久久久噜噜噜久久天堂| 欧美尤物巨大精品爽| 日韩欧美在线一区| 91精品久久久久久久久久入口| 国产精品高潮视频| 日韩精品黄色网| 在线观看国产欧美| 热99久久精品| 国产精品久久久久久婷婷天堂| 国产精品久久久久不卡| 97在线免费视频| 国产成人啪精品视频免费网| 成人亚洲欧美一区二区三区| 久热精品视频在线观看一区| 人体精品一二三区| 97色在线观看| 国产成人精品久久二区二区91| 欧美成人手机在线| 日韩经典一区二区三区| 日韩美女毛茸茸| 欧美精品videosex牲欧美| 97香蕉久久夜色精品国产| 久久久久久久久久久成人| 国自产精品手机在线观看视频| 亚洲网站在线播放| 欧美激情视频在线观看| 国产精品美女免费视频| 亚洲视频国产视频| 91精品在线看| 欧美激情精品久久久久| 日本中文字幕成人| 日韩欧美亚洲成人| 国产精品久久久久久久app| 久久精品免费播放| 国产欧美日韩91| 美日韩精品免费视频| 亚洲精品白浆高清久久久久久| 日本久久久久久久久久久| 精品国产一区二区三区久久| 成人在线国产精品| 这里只有视频精品| 亚洲欧美日韩久久久久久| 久久韩国免费视频| 日韩在线观看视频免费| 九九精品视频在线| 国产丝袜一区二区三区免费视频| 亚洲色图偷窥自拍| www亚洲欧美| 国产亚洲欧洲高清| 国产成人avxxxxx在线看| 亚洲国产福利在线| 欧美黄网免费在线观看| 成人黄色午夜影院| 黑人欧美xxxx| 亚洲欧美激情另类校园| 在线日韩日本国产亚洲| 欧美一区二区三区免费视| 欧美性在线观看| 亚洲欧洲在线免费| 亚洲男人7777| 欧美日本高清视频| 亚洲精品ady| 伊人精品在线观看| 国产一区二区三区在线看| 国产成人精品优优av| 久久精品电影网站| 亚洲精品美女久久久久| 欧美激情中文网| 尤物精品国产第一福利三区| 成人乱人伦精品视频在线观看| www.日韩欧美| 欧美成人中文字幕在线| 国产精品白嫩初高中害羞小美女| 欧美色播在线播放| 亚洲精品久久久久中文字幕二区| 日韩在线欧美在线国产在线| 久久久久久免费精品| 欧美日韩日本国产| 久久精品视频在线播放| 中文字幕欧美在线| 欧美性xxxx18| 成人久久一区二区| 欧美性色xo影院| 欧美激情欧美狂野欧美精品| 久久精品视频一| 亚洲www在线| 亚洲999一在线观看www| 成人av在线天堂|