FatMouse's Speed
来源:互联网 发布:淘宝添加自定义属性 编辑:程序博客网 时间:2024/05/14 05:55
Problem Link:http://acm.hdu.edu.cn/showproblem.php?pid=1160
Original Problem:
FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9284 Accepted Submission(s): 4125
Special Judge
Problem Description
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.
Input
Input contains data for a bunch of mice, one mouse per line, terminated by end of file.
The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information for at most 1000 mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information for at most 1000 mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
Output
Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing a mouse). If these n integers are m[1], m[2],..., m[n] then it must be the case that
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[n]]
In order for the answer to be correct, n should be as large as possible.
All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[n]]
In order for the answer to be correct, n should be as large as possible.
All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
Sample Input
6008 13006000 2100500 20001000 40001100 30006000 20008000 14006000 12002000 1900
Sample Output
44597
Source
Zhejiang University Training Contest 2001
题意:给你许多组数据,没组两个数,一个代表老鼠的重量,一个代表老鼠的速度,为了证明老鼠越重速度越慢,让你取出几组数据证明,问最多能取出几组。体重要严格递增,速度严格递减。
这题是最长上升子序列问题,只是还需要输出其路线。我学会了DP记录路径^_^
code:<span style="font-size:18px;">#include<stdio.h>#include<stdlib.h>#include<algorithm>using namespace std;struct node{int w;int s;int no;}mice[1111];struct node1{int pre;int num;}dp[1111];bool cmp(node a,node b){if(a.w==b.w)return a.s>b.s;return a.w<b.w;}int main(){int i,j,k,max,t;i=0;while(scanf("%d%d",&mice[i].w,&mice[i].s)!=EOF){mice[i].no=i+1;i++;//if(i==9)//break;}sort(mice,mice+i,cmp);//printf("\n");//for(j=0;j<i;j++)//printf("%d %d\n",mice[j].w,mice[j].s);//printf("\n"); for(j=0;j<i;j++){dp[j].num=1;dp[j].pre=0;}max=1;t=1;for(j=1;j<i;j++){for(k=0;k<j;k++){if(mice[k].s>mice[j].s&&mice[k].w<mice[j].w){if(dp[j].num<dp[k].num+1){dp[j].num=dp[k].num+1;dp[j].pre=k;}}}if(dp[j].num>max){max=dp[j].num;t=j;}}printf("%d\n",max);int m[1111]; for(j=1;j<=max;j++){m[j]=t;t=dp[t].pre;}for(k=max;k>=1;k--)printf("%d\n",mice[m[k]].no);return 0;}</span>总结经验:排序用sort,不要用qsort。调用sort函数须加头文件#include<algorithm>和using namespace std;
0 0
- FatMouse's Speed
- zoj_1108 Fatmouse's Speed
- 【DP】FatMouse's Speed
- FatMouse's Speed(dp)
- FatMouse's Speed
- 1160FatMouse's Speed
- FatMouse's Speed
- HDU1160--FatMouse's Speed
- FatMouse's Speed
- ZOJ1108 FatMouse's Speed
- FatMouse's Speed
- hdu FatMouse's Speed
- HDU1160 FatMouse's Speed
- HDU1160 FatMouse's Speed
- FatMouse's Speed
- FatMouse's Speed
- hdu1160,FatMouse's Speed
- HDU1160--FatMouse's Speed
- 在JAVA中使用DES算法
- 高版本Chrome扩展程序强制停止问题
- Spark
- mvn部署的时候如何把配置文件部署进去
- 如何处理BLOB类型数据之一:上传文件并保存到BLOB中
- FatMouse's Speed
- Radar Installation
- UVA - 387 A Puzzling Problem(回溯)
- 刚开通博客来发个帖子安慰下自己 哈
- 递归——数字链
- java编写带过滤分页的通讯录
- 如何处理BLOB类型数据之二:下载BLOB内容并保存到文件中
- HDU 2015 偶数求和
- Nginx模块开发 —进程模型