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

首頁 > 學院 > 開發設計 > 正文

Tian Ji -- The Horse Racing

2019-11-11 04:17:33
字體:
來源:轉載
供稿:網友

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

解題報告

我是類圖論里面Bellman-Ford算法寫的,方法有點笨,應該有更好的貪心算法。 總感覺我的方法有點懸,因為我無法證明方法的可行性,可能是運氣好躲過了大量數據。

#include<stdio.h>#include<algorithm>#define MAX_N 1002using namespace std;int a[MAX_N],b[MAX_N];int cmp(int x,int y){ if(x>y) return 1; else if(x==y) return 0; return -1;}int main(){ int n; while(~scanf("%d",&n)&&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); sort(b,b+n); for(int u=0;u<n;u++){ bool update=false; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ int x0=a[j],y0=b[j]; int x1=a[i],y1=b[i]; int val01=cmp(x0,y0); int val02=cmp(x1,y1); int val11=cmp(x0,y1); int val12=cmp(x1,y0); if(val11+val12>val01+val02||x0==y0&&x1==y1){ int tmp=b[j];b[j]=b[i];b[i]=tmp; bool update=true; } } } if(!update) break; } int ans=0; for(int i=0;i<n;i++){ ans+=cmp(a[i],b[i]); } printf("%d/n",ans*200); } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
日本高清视频精品| 日韩欧美在线视频日韩欧美在线视频| 超碰日本道色综合久久综合| 亚洲在线第一页| 亚洲tv在线观看| 欧美裸体男粗大视频在线观看| 91av视频在线免费观看| 欧美在线xxx| 久久精品国产91精品亚洲| 欧美黑人xxx| 欧美性猛交xxxx久久久| 日韩国产精品亚洲а∨天堂免| 高潮白浆女日韩av免费看| 中文字幕精品久久久久| 91夜夜未满十八勿入爽爽影院| 亚洲国产精品人人爽夜夜爽| 国产一区二区在线免费| 一区三区二区视频| 欧美成人在线影院| 欧美国产日韩视频| 中文字幕精品在线视频| 欧美精品久久久久久久| 91高清免费在线观看| 亲爱的老师9免费观看全集电视剧| 日韩av片永久免费网站| 久久香蕉国产线看观看av| 久久人人爽亚洲精品天堂| 91在线观看欧美日韩| 国产精品激情av电影在线观看| 亚洲图片欧洲图片av| 日韩不卡在线观看| 欧美精品久久久久久久久| 成人午夜一级二级三级| 日本午夜在线亚洲.国产| 日韩国产精品一区| 国内精久久久久久久久久人| 国产亚洲欧洲高清| 欧美专区第一页| 成人a在线观看| 亚洲人成电影在线| 国产精品高潮呻吟久久av无限| 久久精品99国产精品酒店日本| 韩国三级电影久久久久久| 色诱女教师一区二区三区| 日韩电影中文字幕在线| 精品视频在线观看日韩| yellow中文字幕久久| 亚洲欧美日韩国产成人| 91在线观看免费高清| 亚洲三级黄色在线观看| 国产伦精品免费视频| 91精品国产色综合久久不卡98口| 成人网欧美在线视频| 一本一本久久a久久精品牛牛影视| 国产精品私拍pans大尺度在线| 国产精品久久久| 久久国产视频网站| 欧美日韩性视频| 成人激情视频在线| 国产精品久久久久影院日本| 欧美性猛交xxxx久久久| 国内外成人免费激情在线视频网站| 欧美极品第一页| 97超级碰在线看视频免费在线看| 色午夜这里只有精品| 欧美成人手机在线| 日韩中文字幕不卡视频| 欧美亚洲激情视频| 亚洲成人av在线播放| 亚洲成年人在线播放| 亚洲男人天堂2023| 久久男人av资源网站| 精品一区二区三区三区| 亚洲xxxx做受欧美| 欧美裸体xxxx极品少妇| 亚洲社区在线观看| 欧美亚洲国产视频小说| 国产综合在线视频| 色婷婷综合久久久久中文字幕1| 亚洲自拍欧美色图| 日韩高清电影好看的电视剧电影| 亚洲国产成人在线播放| 欧美肥老太性生活视频| 色伦专区97中文字幕| 亚洲国产99精品国自产| 国产一区二区精品丝袜| 亚洲第一区第一页| 91sao在线观看国产| 亚洲白拍色综合图区| 欧美日韩午夜视频在线观看| 欧美激情中文网| 国产精品第七影院| 国产精品国内视频| 欧美日韩国产综合新一区| 蜜臀久久99精品久久久久久宅男| 日韩一区二区三区在线播放| 国产乱人伦真实精品视频| 奇米4444一区二区三区| 伊人伊成久久人综合网小说| 国产亚洲精品久久久久久牛牛| 热门国产精品亚洲第一区在线| 国产91网红主播在线观看| 欧美日韩亚洲视频一区| 国产精品爽黄69天堂a| 欧美成人精品一区二区三区| 日韩一区二区福利| 国产精品美乳一区二区免费| 国产精品视频在线观看| 日韩在线一区二区三区免费视频| 久久久久久噜噜噜久久久精品| 中文字幕亚洲第一| 国产精品自拍偷拍视频| 久久人人爽人人爽爽久久| 亚洲第一福利网| 国产欧美精品一区二区三区-老狼| 欧美乱人伦中文字幕在线| 亚洲国产97在线精品一区| 亚洲人成电影网站色www| 亚洲国内高清视频| 欧美日韩一区二区免费在线观看| 亚洲影院色在线观看免费| 日韩成人在线免费观看| 色青青草原桃花久久综合| 丝袜一区二区三区| 欧美大胆在线视频| 日韩激情av在线免费观看| 亚洲欧美国产精品久久久久久久| 欧美性xxxxx极品| 欧美在线视频一区二区| 日本免费久久高清视频| 亚洲精品丝袜日韩| 亚洲自拍偷拍色图| 萌白酱国产一区二区| 狠狠色狠狠色综合日日五| 亚洲日本中文字幕免费在线不卡| 中文字幕亚洲第一| 国产一区二区三区直播精品电影| 91成人性视频| 日韩成人在线免费观看| 国产精品jizz在线观看麻豆| 欧美激情精品久久久久久蜜臀| 欧美成人黑人xx视频免费观看| 国产丝袜一区二区三区免费视频| 国产精品99久久99久久久二8| 精品日韩视频在线观看| 亚洲欧美中文日韩v在线观看| 狠狠躁夜夜躁人人躁婷婷91| 尤物99国产成人精品视频| 国产999精品久久久| 久久人人爽人人爽人人片亚洲| 岛国视频午夜一区免费在线观看| 国产成人免费91av在线| www.久久色.com| 日韩免费在线观看视频| 91成人国产在线观看| 懂色av一区二区三区| 亚洲电影免费观看高清完整版| www.日韩不卡电影av| 亚洲视频视频在线| 97免费在线视频| 国产亚洲精品久久| 中文字幕亚洲欧美| 自拍偷拍亚洲在线| 欧美猛交免费看|