Problem C
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?"
C" title="Problem 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.
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.
containing a single number, which is the maximum money Tian Ji will
get, in silver dollars.
71
74
0
46MS)
#include
#include
#include
#define maxn 1005
using namespace std;
struct horses
{
int
speed;
char
s;
};
bool comp(horses &a,horses&b)
{
if(a.speed!=b.speed)
return a.speed>b.speed;
else
return a.speed>b.speed;
}
int main()
{
//freopen("in.txt", "r", stdin);
int
n,money=0,tb,te,gb,ge;
horses
ti[maxn],god[maxn];
while(~scanf("%d",&n)&&n)
{
money=0;
tb=gb=0;
te=ge=n-1;
for(int i=0;i
scanf("%d",&ti[i].speed);
for(int i=0;i
scanf("%d",&god[i].speed);
sort(&ti[0],&ti[n],comp);
sort(&god[0],&god[n],comp);
while (tb <= te)
{
if (ti[te].speed > god[ge].speed)//田忌最快的马比大王的快就赢一局
{
money++;
te--;
ge--;
}
else if (ti[te].speed < god[ge].speed)//田忌最快的马比大王的慢就输一局
{
money--;
te--;
gb++;
}
else//最快的马一样快
{
if(ti[tb].speed > god[gb].speed)//田忌最慢的马比大王的快就赢一局
{
money++;
tb++;
gb++;
}
else
{
if (ti[te].speed < god[gb].speed)//田忌的慢就输
money--;
te--;
gb++;
}
}
//注意:这些最快最慢都是相对于当前还没有进行过比赛的马,每比一次状态转移
//一次
}
printf("%d\n",money*200);
}
return
0;
}
Problem C的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案
$s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...
随机推荐
- webpack + vue + node 打造单页面(入门篇)
1.node下载地址:http://nodejs.cn/download/,安装完成检查node和npm版本 2.淘宝镜像 : npm install cnpm -g --registry=https ...
- CentOS7下安装MariaDB
环境:Window10 上建立 VMWare 虚拟机,EasyInstaller 方式安装 CentOS 7 1. “失败”的经历 备份原 repo 文件,并更改 yum 源(方法详见修改yum源)为 ...
- Postman 串行传参和动态传参详解
Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件 用Postman做接口测试的时候,要把多条用例一起执行,就需要把用例连接起来,一次性执行 目录 串行传参 动态传参 使用 ...
- Spring中的Service/DAO/DTO
- Pro Flight YOKE 设备键位映射踩过的坑
背景 VR游戏项目.街机游戏项目7月阶段版本快要结束了,考虑到带有键鼠外设显得逼格比较Low,所以决定采用"高大上"的专业设备来进行游戏操作. 需求 需要将键盘鼠标操作的18个键位 ...
- jquery.i18n.properties前端国际化解决方案“填坑日记”
但现在的情况是老的项目并没有使用这类架构.说起国际化,博主几年前就做过,在MVC里面实现国际化有通用的解决方案,主要就是通过资源文件的方式定义多语言.最初接到这个任务,并没有太多顾虑,毕竟这种东西有很 ...
- AES加密解密——AES在JavaWeb项目中前台JS加密,后台Java解密的使用
一:前言 在软件开发中,经常要对数据进行传输,数据在传输的过程中可能被拦截,被监听,所以在传输数据的时候使用数据的原始内容进行传输的话,安全隐患是非常大的.因此就要对需要传输的数据进行在客户端进行加密 ...
- The Twin Towers zoj2059 DP
The Twin Towers Time Limit: 2 Seconds Memory Limit: 65536 KB Twin towers we see you standing ta ...
- S2_OOP第一章
面向对象设计的过程就是抽象的过程 步骤: 第一步:发现类 第二步:发现类的属性 第三步:发现类的方法 抽象是遵循的原则 属性和方法的设置是为了解决业务问题 关注主要属性和方法 如果没有必要,不增加额外 ...
- 基于LoadRunner11,以wifi热点方式录制APP脚本简单指导
本想详细写下操作过程,但并不觉着十分必要,通过baidu或我要自学网均能找到相关资料,所以详细操作过程不再赘述,只是把过程中遇到的问题说明下解释下,让大家“录制APP”的路更平坦! 1.如何使用Loa ...