FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8334    Accepted Submission(s): 3715
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.

 
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. 

 
Sample Input
6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
 
Sample Output
4
4 5 9 7

思路:DP水,先排序,然后直接比较。

 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<cstring>
#define MAX 1111
using namespace std;
class mouse{
public:
int w, v, id;
bool operator < (const mouse &a) const{
return w < a.w;
}
};
mouse m[MAX];
int dp[MAX], pre[MAX];
stack<int>s;
int main(){
int ans = , i = , j, k;
/* freopen("in.c", "r", stdin); */
while(~scanf("%d%d", &m[i].w, &m[i].v)) m[i].id = i, ++i;
while(!s.empty()) s.pop();
sort(m+, m+i);
for(int j = ;j < i;j ++) dp[j] = ;
memset(pre, , sizeof(pre));
m[].w = m[].v = ;
for(j = ;j < i;j ++){
for(k = ;k < j;k ++){
if(m[j].w > m[k].w && m[j].v < m[k].v){
if(dp[j] < dp[k] + ){
dp[j] = dp[k] + ;
pre[j] = k;
}
}
}
}
for(k = ;k < i;k ++){
if(ans < dp[k]){
ans = dp[k];
j = k;
}
}
printf("%d\n", ans);
s.push(m[j].id);
for(k = j;m[pre[k]].id;k = pre[k]) s.push(m[pre[k]].id);
while(!s.empty()){
printf("%d\n", s.top());
s.pop();
}
return ;
}

HDOJ --- 1160的更多相关文章

  1. Hdoj 1160.FatMouse's Speed 题解

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  2. dp入门题目

    本文文旨,如题... 转载请注明出处... HDOJ 1176 免费馅饼 http://acm.hdu.edu.cn/showproblem.php?pid=1176 类似数塔,从底往上推,每次都是从 ...

  3. 【HDOJ】1160 FatMouse's Speed

    DP. #include <stdio.h> #include <string.h> #include <stdlib.h> #define MAXNUM 1005 ...

  4. 杭电hdoj题目分类

    HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就 ...

  5. HDOJ 题目分类

    HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:   ...

  6. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  8. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  9. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

随机推荐

  1. jQuery弹性滑块导航

    曾起何时在某网站上看到一弹性滑块导航的效果,瞬间被些效果吸引,开始以为是用FLASH实现的,但查源代码发现用的是JQuery缓动效果. 今天心血来潮想拿这个效果练练手.也看看这段时间学习JS及jque ...

  2. 【ADO.NET】8、DataSet的使用

    一.DataSet的查询 SqlDataReader 适用于大型数据的读取,它是一条一条的读取,读取出来的数据是存放在服务器上当正在读取数据的时候,突然与服务中断,将无法读取后面的数据DataSet ...

  3. varchar(n),nvarchar(n) 长度、性能、及所占空间分析 nvarchar(64) nvarchar(128) nvarchar(256)(转)

    varchar(n),nvarchar(n) 中的n怎么解释: nvarchar(n)最多能存n个字符,不区分中英文. varchar(n)最多能存n个字节,一个中文是两个字节. 所占空间: nvar ...

  4. thinkphp ajax检测是否数据可用

    模板文件:如 index.html 模板文件如:(index.html) <form><input type="text" name="username ...

  5. C#实现JSON序列化与反序列化介绍

    方法一:引入System.Web.Script.Serialization命名空间使用 JavaScriptSerializer类实现简单的序列化 序列化类:Personnel public clas ...

  6. winform模拟鼠标按键

    今天朋友说被他们公司的学习网站恶心到了,下班后要他看学习资料,看完点下一页,而且一页必须停留多少时间才能点击下一页,想不看都不行,于是晚上我突发奇想要给他做一个模拟鼠标按键的程序,可以让鼠标定时间隔触 ...

  7. php 魔术方法

    PHP5.0后,php面向对象提成更多方法,使得php更加的强大!! 一些在PHP叫魔术方法的函数,在这里介绍一下:其实在一般的应用中,我们都需要用到他们!! 1.__construct() 当实例化 ...

  8. php分页笔记

    在做留言板的时候,用到了分页,所以写了这个分页笔记   既然已经开始写分页了,肯定掌握了了php的一些知识以及mysql的基本操作   在做分页的时候,我也遇到了很多问题,但是大家不要怕,无论什么问题 ...

  9. zzuli oj 1165 实数的小数部分(指针专题)

    Description 读入一个实数,输出该实数的小数部分,小数部分若多余的末尾0,请去掉.如输入111111.12345678912345678900  则输出0.12345678912345678 ...

  10. 在 IIS MIME 类型中添加 md 扩展名

    最近在了解 Knowledge Base (知识库)的内容,对两个平台比较感兴趣,一个是 Raneto,一个是 MDwiki,两者都是使用md文件作为内容存储. 需要注意的是,使用IIS部署网站后,需 ...