J. FatMouse's Speed

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

题意:

要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数。(Special Judge  说明答案不唯一,只要输出的答案正确就可以)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
int num,w,s;
}a[];
int cmp(node c,node d) {return c.w<d.w;}
int x,y,k,t[],r[];
int main()
{
int i,j,L,p=,ant=,er=;
k=;
memset(t,,sizeof(t));
while(cin>>x>>y)
{
a[k].num=k+;
a[k].w=x;
a[k].s=y;
k++;
}
sort(a,a+k,cmp);
for(i=;i<k;i++) t[i]=;
for(i=;i<k;i++)
{
for(j=;j<i;j++)
{
if(a[j].s>a[i].s&&a[j].w<a[i].w&&t[i]<t[j]+)
t[i]+=;
}
}
for(i=;i<k;i++) p=max(p,t[i]);
cout<<p<<endl;
for(i=;i<k;i++)
{
if(p==t[i]) j=i;
}
int temp=j;
r[er++]=a[j].num;
for(L=j-;L>=;L--)
{
if(t[L]+==t[j]&&a[L].s>a[temp].s)
{
ant++;
r[er++]=a[L].num;
t[j]=t[L];
temp=L;
}
if(ant==p) break;
}
for(i=er-;i>;i--) cout<<r[i]<<endl;
return ;
}

最新文章

  1. PHP两种基础的算法:冒泡、快速排序法》》》望能够帮助到大家
  2. 先装.net后装iis的问题
  3. java文件保存至服务器
  4. oracel数据泵的使用
  5. python 操作注册表
  6. UVA1025---A Spy in the Metro(DP)
  7. struct和union分析实例
  8. oracle 存储过程基础
  9. 用标准C编写COM(一)
  10. LINUX启动ORACLE监听和服务
  11. NET中级课--文件,流,序列化2
  12. JAVA: httpclient 具体解释——第五章;
  13. 【JMeter】source(&quot;文件路程&quot;)和${变量}同时出现会报错
  14. shell脚本中单双引号疑惑
  15. 斐讯 天天牛绑定教程 邀请码:8vozbf
  16. 验证对Random的两个猜想
  17. QString 与 string转换
  18. HTML5+CSS把footer固定在底部
  19. nGrinder的安装与使用
  20. iftop、ifstat详解

热门文章

  1. jquery扫尾
  2. spring mvc+mybatis+sql server简单配置
  3. Eclipse快捷键与使用技巧总结
  4. .htaccess 基础教程(三)RewriteCond标志符,RewriteRule适用的标志符
  5. Java 串口通信
  6. C++删除目录和复制目录函数
  7. nginx负载均衡基于ip_hash的session粘帖
  8. iOS 归档archive使用方法
  9. js中数组连接concat()
  10. Mac Pro 16G 安装MyEclipse提示虚拟内存(为0)不够