首页 > 代码库 > uva 10131

uva 10131

A - Is Bigger Smarter?
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit Status Practice UVA 10131
Appoint description: 

Description

Download as PDF
 

Question 1: Is Bigger Smarter?

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
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<cstdlib>#include<queue>#include<vector>#include<set>using namespace std;struct ele{	int w,s,id;}a[1005];int dp[1005],path[1005],MAX=-1;bool comp(ele a1,ele a2){	return a1.w<a2.w;}void printpath(int i){	if(MAX--)	{		printpath(path[i]);		printf("%d\n",a[i].id);	}}int main(){	int i,j,p,k;	k=1;	while(~scanf("%d%d",&a[k].w,&a[k].s))	{		a[k].id=k;		k++;	}	k--;	sort(a+1,a+k,comp);	for(i=1;i<=k;i++)	{		dp[i]=1;		path[i]=i;	}	for(i=1;i<=k;i++)	{		for(j=1;j<i;j++)		{			if(a[i].w>a[j].w&&a[i].s<a[j].s&&dp[i]<dp[j]+1)			{				dp[i]=dp[j]+1;				path[i]=j; /*记录i之前那头大象*/			}		    if(dp[i]>MAX)			{				MAX=dp[i];				p=i;			}		}	}	printf("%d\n",MAX);      printpath(p);	return 0;}

  

uva 10131