睡觉去..插代码 #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std; struct mouse_label{ int weight; int speed; int n; int from; }mouse[1003]; int cmp(struct mouse_label x, struct mouse_label y) { if(x.weight==y.weight) return x.speed>y.speed; else return x.weight<y.weight; } void output(int flag ) { if(mouse[flag].from !=-1) output(mouse[flag].from); printf("%d/n",mouse[flag].n); } int main(void) { void output(int flag); int count = 1; int b[1003] = {1}; for(int i=0;i<1002;i++) b[i]= 1; while (scanf("%d %d",&mouse[count].weight,&mouse[count].speed) !=EOF) { mouse[count].n = count; count ++; } sort(mouse+1,mouse+count,cmp); for(int i=1;i<count;i++) mouse[i].from = -1; for(int i=1;i<count;i++) for(int j=1;j<i;j++) if(mouse[i].weight>mouse[j].weight&&mouse[i].speed<mouse[j].speed&&b[i]<b[j]+1) { b[i] = b[j]+1; mouse[i].from = j; } int max = b[1]; int flag = 1; for(int i=1;i<count;i++) if(max<b[i]) { max = b[i]; flag = i; } printf("%d/n",max); output(flag); return 0; }