在线编程在线课堂在线测评Anycodes在线编程

编程论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

How to use bs4??
本帖最后由 carry0987 于
Double Queue 问题描述 : The new founded Balkan Investment Group Bank (
John 问题描述 : Little John is playing very funny game
linux-command Linux命令大全搜索工具,内容包含Linux命令
Coati 是一款跨平台的代码查看工具,适用于 C/C++ 和 Java。商业软件。特性:1. 索引
系统可承载海量并发,消息收发确认机制 保障消息必达 系统采用动态智
全平台视频监控,支持安卓苹果以及pcweb,支持海康大华等主流dvr,全部源码以及文档 单聊、群聊、商
如何访问类的私有属性? 下面以 TPathData 为例,
问题:从 XE4 以来,Firemonkey 曲线绘图在移动平台不平滑的问题一直令人诟病,提交到官方的 QC 也是族繁不及备载,官方似乎有意的
操作数据库(RODBC)   odbcConnect(dsn, uid="", p
数据模式:mode函数显示任何对象的模式。常见的单个的
系统可承载海量并发,消息收发确认机制 保障消息必达 系统采用动态智
RabbitMQ与PHP(一) 项
Iease团队扩编预备中,盼望能有Ruby或者java工程师加盟。全职兼职都可以。有爱好的伴侣请与我接洽。 邮件:i
ruby 怎么设置装备摆设GTK2,求教指导下!
#include #include #include #include using namespace std; int main() {
标题如图所示: 有n盏灯,编号1~n。一开端灯都是关着的
成熟的消息收发确认机制,支持万人大群 支持开发自定义的消息sdk接口,扩展性超强 支持单/
成熟的消息收发确认机制,支持万人大群 支持开发自定义的消息sdk接口,扩展性超强 支持单/
1. 注意列表和集合的区别 set 列表表现形式: list_1
Ajax   Ajax即“Asynchronous Javascript And
大师好,我比来在做布谷鸟优
分辨提取A和B图像Harris角点,接下来须要对

[HDU杭电] HDU 1052 Tian Ji — The Horse Racing-贪心-[解题报告] C++

[复制链接]
发表于 2016-3-25 22:13:46 | 显示全部楼层 |阅读模式
Tian Ji — The Horse Racing


问题描述 :
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?"

HDU 1052 Tian Ji — The Horse Racing-贪心-[解题报告] C++

HDU 1052 Tian Ji — The Horse Racing-贪心-[解题报告] C++
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.
样例输入:

  1. 3
  2. 92 83 71
  3. 95 87 74
  4. 2
  5. 20 20
  6. 20 20
  7. 2
  8. 20 19
  9. 22 18
  10. 0
复制代码
样例输出:

  1. 200
  2. 0
  3. 0
复制代码
题目链接:
Click
here~~
  1. #include <stdio.h>
  2. #include <algorithm>
  3. using namespace std;
  4. int T[1002],K[1002],n,win,lose;
  5. void read()
  6. {
  7.     for(int i=0;i<n;i++)
  8.         scanf("%d",&T[i]);
  9.     for(int i=0;i<n;i++)
  10.         scanf("%d",&K[i]);
  11.     sort(T,T+n);
  12.     sort(K,K+n);
  13. }
  14. void race()
  15. {
  16.     win = lose =0;
  17.     int t_slow=0,t_fast=n-1;
  18.     int k_slow=0,k_fast=n-1;
  19.     while(t_slow <= t_fast)
  20.     {
  21.         if(T[t_slow] > K[k_slow])        //情况1
  22.         {
  23.             win++;
  24.             t_slow++;
  25.             k_slow++;
  26.         }
  27.         else if(T[t_slow] < K[k_slow])   //情况2
  28.         {
  29.             lose++;
  30.             t_slow++;
  31.             k_fast--;
  32.         }
  33.         else                             //情况3
  34.         {
  35.             if(T[t_fast] > K[k_fast])    //先别放水,让哥比完这场
  36.             {
  37.                 win++;
  38.                 t_fast--;
  39.                 k_fast--;
  40.             }
  41.             else                         //1、2、3、放
  42.             {
  43.                 if(T[t_slow] < K[k_fast])//哥不一定会输哦~~~
  44.                     lose++;
  45.                 t_slow++;
  46.                 k_fast--;
  47.             }
  48.         }
  49.     }
  50. }
  51. int main()
  52. {
  53.     //freopen("1","r",stdin);
  54.     //freopen("2","w",stdout);
  55.     while(scanf("%d",&n),n)
  56.     {
  57.         read();
  58.         race();
  59.         printf("%d\n",200*(win-lose));
  60.     }
  61.     return 0;
  62. }
复制代码
在线编程(http://www.anycodes.cn)&编程论坛(http://www.52exe.cn)感谢您的支持!
回复

使用道具 举报

发布主题 上个主题 下个主题 快速回复 返回列表 官方QQ群
在线客服
客 服 中 心
群 机 器 人
网站二维码
收 起 客 服

QQ|Archiver|手机版|小黑屋|Anycodes ( ICP14002806Anycodes在线编程

GMT+8, 2018-11-22 01:09 , Processed in 1.322480 second(s), 73 queries .

Powered by Anycodes

© 2001-2013 吉林市群龙科技有限公司 Inc.

快速回复 返回顶部 返回列表