UVa 10131 is bigger Smarter? (lds+ data structure sorting)

Source: Internet
Author: User

Is bigger Smarter?
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &%llu

Submit Status

Description

Question 1:is bigger Smarter? The problem

Some people think, the bigger an elephant are, the smarter it is. To disprove this, you want the data in a collection of elephants and put as large a subset of this data as Possibl e into a sequence so, the weights is increasing, but the IQ's is decreasing.

The input would consist of data for a bunch of elephants, one elephant per line, terminated by the end-of-file. The data for a particular elephant would consist of a pair of integers:the first representing its size in kilograms and th e second representing its IQ in hundredths of IQ points. Both integers is between 1 and 10000. The data would contain information for in most of the elephants. Elephants may have the same weight, the same IQ, or even the same weight and IQ.

Say the numbers on the i-th data line is 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 of the representing an elephant). If these n integers is a[1], a[2],..., a[n] Then it must is 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 is correct, n should be as large as possible. All inequalities is strict:weights must is strictly increasing, and IQs must be strictly decreasing. There may is many correct outputs for a given input, and your program only needs to find one.Sample Input
6008 13006000 2100500 20001000 40001100 30006000 20008000 14006000 12002000 1900
Sample Output
44597

Test instructions: Is the elephant really bigger and smarter, to find the longest elephant sequence with the weight increasing IQ decreasing.

Analysis: It is obvious that the longest degradation sub-sequence, the weight of the first order, the same weight as the IQ descending platoon, so that can come out.

1#include <cstdio>2#include <cstdlib>3#include <cstring>4 //Antiew[i] For the number I elephant weight rank; EW is the number of the first-name elephant, and W,s is the elephant's weight, IQ;5 intw[1005],s[1005],n=0, ew[1005],antiew[1005],loest[1005],p[1005];6 //int f[1005][1005];7 intcmpConst void* x,Const void*y)8 {9     if(W[* (int*) x]! = w[* (int*) y])Ten         returnw[* (int*) x]-w[* (int*) y]; One     Else A         returns[* (int*) y]-s[* (int*) x]; - } -  the voidPrintinti) - { -     if(i = =-1)return; - print (p[i]); +printf"%d\n", Ew[i] +1); -     //printf ("%d:%d%d\n", Ew[i] + 1,w[ew[i]],s[ew[i]); + } A  at intMain () - { - #ifdef LOCAL -Freopen (".. \\data.in","R", stdin); -     #endif //LOCAL -     //read into the elephant's weight w IQ s total N-head elephant in      while(SCANF ("%d%d", w+n,s+n) = =2) -n++; to     //EW is an elephant's weight gain. +      for(intI=0; i<n;i++) -Ew[i] =i; theQsort (Ew,n,sizeof(int), CMP); *      for(intI=0; i<n;i++) $Antiew[ew[i]] =i;Panax Notoginsengmemset (p,-1,sizeof(P)); -memset (Loest,0,sizeof(Loest)); the  +loest[0] =1; A      for(intI=1; i<n;i++) the     { +         //Maxl is the largest of the strictly descending descending subsequence length of the elephant IQ of the first I -         intMaxl=0; $          for(intj=i-1; j>=0; j--)if(S[ew[i] < S[ew[j]] && w[ew[i] [> W[ew[j]] && Maxl <Loest[j]) $         { -MAXL =Loest[j]; -P[i] =J; the         } -         if(P[i] = =-1)WuyiLoest[i] =1; the         Else -Loest[i] = Maxl +1; Wu     } -  About     intmaxip=0; $      for(intI=0; i<n;i++)if(Loest[maxip] <Loest[i]) -MAXIP =i; -printf"%d\n", Loest[maxip]); -  A print (MAXIP); +     /* the for (int i=0;i<n;i++) - printf ("Ref.:%4d Weight:%4d iq:%4d weight rank:%4d\n", i + 1,w[i],s[i],antiew[i]+1); $ for (int i=0;i<n;i++) the printf ("Weight rank:%4d Weight:%4d IQ:%4d number:%4d\n", i+1,w[ew[i]],s[ew[i]],ew[i]+1); the     */ the     return 0; the}

UVa 10131 is bigger Smarter? (lds+ data structure sorting)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.