HDU 1052 贪心+dp
http://acm.hdu.edu.cn/showproblem.php?pid=1052
Tian Ji -- The Horse Racing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31270 Accepted Submission(s): 9523
"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 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.
92 83 71
95 87 74
2
20 20
20 20
2
20 19
22 18
0
0
0
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define inf 0x3f3f3f3f
int f[][];
int a[],b[];
int cmp(int i,int j)
{
if(a[i]>b[j])return ;
if(a[i]==b[j])return ;
return -;
}
int main()
{
int N,M,i,j,k;
while(cin>>N&&N){
for(i=;i<=N;++i) scanf("%d",a+i);
for(i=;i<=N;++i) scanf("%d",b+i);
memset(f,,sizeof(f));
sort(a+,a++N);
sort(b+,b++N);
for(i=;i<=N;++i) f[i][i]=cmp(i,);
for(int len=;len<=N;++len)
{
for(i=,j=len;j<=N;++i,++j)
{
f[i][j]=max(f[i+][j]+cmp(i,j-i+),f[i][j-]+cmp(j,j-i+));
}
}
printf("%d\n",f[][N]*);
}
return ;
}
HDU 1052 贪心+dp的更多相关文章
- hdu 1257 最少拦截系统【贪心 || DP——LIS】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1052 Tian Ji -- The Horse Racing (贪心)(转载有修改)
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- Tian Ji -- The Horse Racing HDU - 1052
Tian Ji -- The Horse Racing HDU - 1052 (有平局的田忌赛马,田忌赢一次得200块,输一次输掉200块,平局不得钱不输钱,要使得田忌得到最多(如果只能输就输的最少) ...
- 【BZOJ-3174】拯救小矮人 贪心 + DP
3174: [Tjoi2013]拯救小矮人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 686 Solved: 357[Submit][Status ...
- hdu 4123 树形DP+RMQ
http://acm.hdu.edu.cn/showproblem.php? pid=4123 Problem Description Bob wants to hold a race to enco ...
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
- hdu 3709 数字dp(小思)
http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...
- hdu 4352 数位dp + 状态压缩
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 4283 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
随机推荐
- MySQL中数据中设计中的范式与反范式
设计关系数据库时,遵从不同的规范要求,设计出合理的关系型数据库,这些不同的规范要求被称为不同的范式,各种范式呈递次规范,越高的范式数据库冗余越小.但是有些时候一昧的追求范式减少冗余,反而会降低数据读写 ...
- Linux下安装MongoDB全程记录
1.下载安装包 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.6.0.tgz 2.解压缩 [root@loca ...
- python模块学习(二)
configparser模块 软件常见文档格式如下: [DEFAULT]ServerAliveInterval = 45Compression = yesCompressionLevel = 9For ...
- python构造wireshark可以解析的LTE空口数据
Wireshark是可以解析LTE的空口数据.但是在wireshark的实现中,这些数据都是被封装到UDP报文中.然后根据wireshark的格式文件对LTE的数据加上头信息.头信息的定义参考附件pa ...
- 20170411 F-02创建财务凭证
SAPMF05A 100 X 0 BDC_OKCODE /00 0 BKPF-BLDAT 20170411 0 BKPF-BLART SA 0 BKPF-BUK ...
- 如何配置一个路径,能够既适合Linux平台,又适合Windows平台,可以从这个路径中读取文件
如何配置一个路径,能够既适合Linux平台,又适合Windows平台,可以从这个路径中读取文件? 目的:就是希望在项目的配置文件中配上一样的路径,不管协作者使用的是什么平台,都能够读到文件. 比如:L ...
- GIS学习和开发的在线资源
1.OpenGIS Consortium标准,http://www.opengeospatial.org.著名的OGC标准是每个GIS开发者最后都不得不学习的,或深或浅. 2.SharpMap,Pro ...
- iOS 11 Xcode9开发 新特性学习 (新方法篇)
1 . 引入github (1) 在Xcode 9 中,引入了 gitHub,新源代码管理导航器 可以展示branch分支和 tag标签. (2)点进去,就可以看指定一次commit了哪些东西 2 ...
- 022_Hadoop中的数据类型(Writable、WritableComparable、Comparator、RawComparator…)
1. 在hadoop中所有的key/value都必须实现Writable接口,有两个方法,分别用于读(反序列化)和写(序列化)操作.
- FAT和EXFAT文件系统
文件系统 文件系统是操作系统用于明确磁盘或分区上的文件的方法和数据结构:即在磁盘上组织文件的方法.在移动存储设备上比较常用的有FAT文件系统和ExFAT文件系统. FAT分区依据FAT表中每个簇链的所 ...