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

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

Tian Ji -- The Horse Racing

2019-11-11 03:02:19
字體:
來源:轉載
供稿:網友

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
国产亚洲精品久久久久动| 欧美午夜丰满在线18影院| 亚洲一区av在线播放| 欧美激情在线狂野欧美精品| 欧美精品激情blacked18| 91黑丝高跟在线| 国产精品精品视频| 国产精品一区二区三区免费视频| 久久免费国产视频| 亚洲国产成人久久综合一区| 国产91成人在在线播放| 亚洲人a成www在线影院| 欧美激情性做爰免费视频| 久久全国免费视频| 亚洲午夜精品久久久久久性色| 久国内精品在线| 亚洲精品456在线播放狼人| 亚洲激情在线观看视频免费| 中文字幕日韩综合av| 久久99国产综合精品女同| 久久国产精品影片| 亚洲已满18点击进入在线看片| 最近2019年中文视频免费在线观看| 欧美天堂在线观看| 青青久久av北条麻妃黑人| 欧美视频一区二区三区…| 91高清免费视频| 91精品久久久久久久久不口人| 日韩亚洲欧美中文高清在线| 成人女保姆的销魂服务| 日韩一区二区三区国产| 亚洲经典中文字幕| 亚洲性69xxxbbb| 97视频在线免费观看| 国产亚洲欧美aaaa| 亚洲精品美女在线观看播放| 成人黄色免费看| 久久精品中文字幕| 97色在线观看| 亚洲开心激情网| 日韩国产高清污视频在线观看| 国产91久久婷婷一区二区| 在线观看视频99| 国产精品免费一区二区三区都可以| 欧美激情日韩图片| 福利视频一区二区| 91精品国产综合久久男男| 日本sm极度另类视频| 久久视频在线视频| 国产成人福利网站| 亚洲人成自拍网站| 欧美激情亚洲另类| 欧美—级高清免费播放| 亚洲天堂第二页| 亚洲一区精品电影| 亚洲精品欧美日韩| 成人网页在线免费观看| 精品中文字幕乱| 亲爱的老师9免费观看全集电视剧| 国产精品视频白浆免费视频| 日韩亚洲在线观看| 激情久久av一区av二区av三区| 欧美电影免费播放| 国产欧美精品xxxx另类| 亚洲2020天天堂在线观看| 亚洲国产私拍精品国模在线观看| 欧美寡妇偷汉性猛交| 日本不卡视频在线播放| 国产精品视频中文字幕91| 成人a免费视频| 成人激情黄色网| 亚洲直播在线一区| 国产日本欧美一区| 国产一区二区三区丝袜| 国产精品h片在线播放| 国产丝袜精品视频| 尤物yw午夜国产精品视频明星| 亚洲人成电影网站| 国产精品中文字幕久久久| 孩xxxx性bbbb欧美| 日韩欧美精品在线观看| 国产精品三级美女白浆呻吟| 色悠悠久久88| 欧美激情精品久久久久久大尺度| 精品欧美一区二区三区| 91久久国产综合久久91精品网站| 精品国产老师黑色丝袜高跟鞋| 久久久久国产一区二区三区| 亚洲综合中文字幕在线观看| 欧美激情免费在线| 久久在线免费观看视频| 欧美黄色片免费观看| 日韩av电影在线网| 激情懂色av一区av二区av| 日本道色综合久久影院| 不卡伊人av在线播放| 日韩在线观看成人| 色综合色综合久久综合频道88| 国产精品专区第二| 国产精品福利久久久| 中文字幕久久久av一区| 国产成人激情视频| 国产成人综合久久| 国产精品美女网站| 91视频国产高清| 欧美乱妇高清无乱码| 91av在线影院| 欧美黑人一级爽快片淫片高清| 97在线视频一区| 91热福利电影| 欧美精品www在线观看| 成人激情视频网| 久久国产精品电影| 欧美黑人xxxⅹ高潮交| 美女视频黄免费的亚洲男人天堂| 69影院欧美专区视频| 欧美日韩一区二区三区在线免费观看| 精品动漫一区二区| 性欧美暴力猛交69hd| 在线视频欧美性高潮| 一本一本久久a久久精品综合小说| 亚洲欧洲日韩国产| 日韩av免费在线观看| 国产人妖伪娘一区91| 精品福利视频导航| 亚洲一区二区三区成人在线视频精品| 成人www视频在线观看| 国产精品激情av在线播放| 久久99久久99精品中文字幕| 国产精品久久97| 亚洲欧美中文另类| 搡老女人一区二区三区视频tv| 国产精品av电影| 亚洲最大的免费| 国产精品亚洲аv天堂网| 4p变态网欧美系列| 日韩成人高清在线| 精品成人国产在线观看男人呻吟| 欧美午夜视频一区二区| 欧美激情极品视频| 欧美最猛黑人xxxx黑人猛叫黄| 日本午夜人人精品| 精品中文字幕视频| 亚洲美女自拍视频| 欧美孕妇毛茸茸xxxx| 国产香蕉精品视频一区二区三区| 国产亚洲aⅴaaaaaa毛片| 亚洲精品大尺度| 91精品视频在线播放| 久久精品91久久久久久再现| 国产精品人成电影在线观看| 九九九久久国产免费| 亚洲精品98久久久久久中文字幕| 国产精品欧美日韩一区二区| 日韩av在线最新| 一区二区欧美日韩视频| 狠狠爱在线视频一区| 日韩精品免费在线视频观看| 国产成人啪精品视频免费网| 性欧美xxxx| 欧美日韩国产丝袜另类| www.午夜精品| 欧美激情一区二区三区成人| 亚洲欧美中文日韩v在线观看|