UVA—10131 Is Bigger Smarter?
来源:互联网 发布:空气质量检测软件 编辑:程序博客网 时间:2024/06/13 13:44
The Problem
Some people think that the bigger an elephant is, the smarter it is. To disprove this, you want to take the data on a collection of elephants and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the IQ's are decreasing.
The input will consist of data for a bunch of elephants, one elephant per line, terminated by the end-of-file. The data for a particular elephant will consist of a pair of integers: the first representing its size in kilograms and the second representing its IQ in hundredths of IQ points. Both integers are between 1 and 10000. The data will contain information for at most 1000 elephants. Two elephants may have the same weight, the same IQ, or even the same weight and IQ.
Say that the numbers on the i-th data line are W[i] and S[i]. 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 an elephant). If these n integers are a[1], a[2],..., a[n] then it must be the case that
W[a[1]] < W[a[2]] < ... < W[a[n]]
and S[a[1]] > S[a[2]] > ... > S[a[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 IQs 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
<span style="font-size:14px;">#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int Max=1000;int maxlen[Max+10];int p[Max+10];struct elephant{ int w; int s; int num;}a[Max+10];int temp(elephant a,elephant b){ if(a.w==b.w) return a.s>b.s; else return a.w<b.w;}void trace(int i){ if(p[i]!=-1) trace(p[i]); printf("%d\n",a[i].num);}int main(){ int cnt1=0,cnt=0; int ant=0; int pos; a[0].num=1; while(scanf("%d%d",&a[cnt++].w,&a[cnt1++].s)!=EOF); for(int i=0;i<cnt;i++){ a[i].num=i+1; maxlen[i]=1; p[i]=-1; } sort(a,a+cnt-1,temp); for(int i=1;i<cnt-1;i++){ for(int j=0;j<i;j++){ if(a[j].w!=a[i].w&&a[j].s>a[i].s&&maxlen[j]+1>maxlen[i]){ maxlen[i]=maxlen[j]+1; p[i]=j; } } } for(int i=cnt-2;i>=0;i--){ if(maxlen[i]>ant){ ant=maxlen[i]; pos=i; } } printf("%d\n",ant); trace(pos);}</span>
- UVA—10131 Is Bigger Smarter?
- UVa 10131 Is Bigger Smarter?
- UVa 10131 Is Bigger Smarter?
- UVA 10131 - Is Bigger Smarter
- uva 10131 Is Bigger Smarter?
- uva:10131 - Is Bigger Smarter?
- uva 10131 Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- Uva - 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter
- UVa 10131: Is Bigger Smarter?
- UVa:10131 Is Bigger Smarter?
- UVA - 10131 Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- 奇异矩阵 singular matrix
- 博客搬家至Github
- Java学习之整数类型最大值最小值
- JS 实现背景图片的自动变换(设定每3秒变化一次)
- poj 1222 EXTENDED LIGHTS OUT (高斯消元解异或方程组 开关问题)
- UVA—10131 Is Bigger Smarter?
- [操作系统基础]程序运行时内存的分区以及作用
- 如何给你的Android 安装文件(APK)瘦身
- 创建游戏场景
- Xcode6 上面关于ios8系统通讯录调用的代理方法变更;
- C#读取Excel文件
- 网页乱码
- Python 学习笔记-字符串
- Object-C 基础学习笔记(基本类型、集合)