10131 - Is Bigger Smarter?
2013-04-08 13:45
21 查看
描述:题意很简单,先快排一下,然后从中选择即可,因为我觉得只用数组有些麻烦,所以用了结构体 #include <cstdio> #include <cstdlib> struct Ele { int We; int Iq; int sum; int next; int pos; }; Ele count[1010]; int cmp(const void *p1 ,const void *p2) { int p1_We=((Ele *)p1)->We,p1_Iq=((Ele *)p1)->Iq; int p2_We=((Ele *)p2)->We,p2_Iq=((Ele *)p2)->Iq; if(p1_We>p2_We) return 1; else if(p1_We<p2_We) return -1; else { if(p1_Iq>p2_Iq) return -1; else return 1; } } int main() { //freopen("a.txt","r",stdin); int x,y,len=0; while(scanf("%d %d",&x,&y)!=EOF) { count[len].We=x; count[len].Iq=y; count[len].sum=1; count[len].next=-1; count[len].pos=len+1; len++; } qsort(count,len,sizeof(Ele),cmp); for(int i=len-2; i>=0; i--) { y=x=-1; for(int j=len-1; j>i; j--) if(count[i].We<count[j].We&&count[i].Iq>count[j].Iq) { if(x==-1) { x=count[j].sum; y=j; } else if(x<count[j].sum) { x=count[j].sum; y=j; } } count[i].sum+=count[y].sum; count[i].next=y; } y=0; x=count[0].sum; for(int i=1; i<len; i++) if(x<count[i].sum) { x=count[i].sum; y=i; } printf("%d\n",x); while(y!=-1) { printf("%d\n",count[y].pos); y=count[y].next; } return 0; }
相关文章推荐
- UVA 10131 - Is Bigger Smarter
- UVa 10131 - Is Bigger Smarter?
- Uva - 10131 - Is Bigger Smarter?
- Uva 10131 Is Bigger Smarter? (LIS,打印路径)
- uva 10131 Is Bigger Smarter?(DAG最长路)
- uva 10131 - Is Bigger Smarter?
- UVa 10131 Is Bigger Smarter?
- UVa 10131 Is Bigger Smarter? (DP&LIS)
- UVA - 10131 Is Bigger Smarter?(dp+最大升序子序列)
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter
- 【解题报告】uva10131_Is Bigger Smarter?(越大越聪明, dp, LIS)
- Is Bigger Smarter? - UVa 10131 dp
- UVA - 10131 Is Bigger Smarter?
- 10131 - Is Bigger Smarter?
- UVA 10131 - Is Bigger Smarter?
- uva:10131 - Is Bigger Smarter?
- UVa 10131 Is Bigger Smarter? 最长公共子序列