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 ...
随机推荐
- iOS开发者的管理工具-CocoaPods安装
1. 安装 Ruby 对于iOS开发者,CocoaPods是最方便使用的第三方管理工具了,但是怎么安装CocoaPods呢,安装CocoaPods之前,要确保mac已经安装上Ruby,但在安装Ruby ...
- 从Leetcode的Combination Sum系列谈起回溯法
在LeetCode上面有一组非常经典的题型--Combination Sum,从1到4.其实就是类似于给定一个数组和一个整数,然后求数组里面哪几个数的组合相加结果为给定的整数.在这个题型系列中,1.2 ...
- ASP.NET Core 认证与授权[1]:初识认证
在ASP.NET 4.X 中,我们最常用的是Forms认证,它既可以用于局域网环境,也可用于互联网环境,有着非常广泛的使用.但是它很难进行扩展,更无法与第三方认证集成,因此,在 ASP.NET Cor ...
- js'初学笔记
之前看过一个博主说的学习前端养成写博客的习惯,我慢慢学着在上面写点东西,记录我的学习. 这段时间把之前学的js基础补上一点,学了一些对数组和字符的操作,split(),将字符串变成数组.join(), ...
- 【Linux笔记(001) 】-- centos7 系统目录结构与文件
一.目录结构与用途: /boot:系统引导文件.内核 /bin:用户的基本命令 /dev:设备文件 /etc:配置文件 /home:用户目录 /root:root用户目录 /sbin:管理类的基本命令 ...
- 【JVM命令系列】jmap
命令基本概述 Jmap是一个可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本.打印出某个java进程(使用pid)内存内的,所有'对象'的情况(如:产生那些对象,及其数量 ...
- HDFS概述(2)————Block块大小设置
以下内容转自:http://blog.csdn.net/samhacker/article/details/23089157?utm_source=tuicool&utm_medium=ref ...
- 移动端效果之Swiper
写在前面 最近在做移动端方面运用到了饿了么的vue前端组件库,因为不想单纯用组件而使用它,故想深入了解一下实现原理.后续将会继续研究一下其他的组件实现原理,有兴趣的可以关注下. 代码在这里:戳我 1. ...
- Python实战之Selenium自动化测试web登录(2)
#!/usr/bin/env python3 # -*- coding:utf-8 -*- from selenium import webdriver from selenium.webdriver ...
- Python自学笔记-sorted()函数(来自廖雪峰的官网Python3)
感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 排序算法 排序 ...