|
|
back to boardI got WA #4. pls help me! my code : #include <iostream> #include <algorithm> using namespace std; struct cord { int x,y,p; }; int comp(cord a,cord b) { if (a.x < b.x) return 1; return 0; } int main() { cord a[501]; int best[501]; int way[501]; int oway[501],f=0; int n,i,j,k,l;
cin>>n; for (i=0;i<n;i++) { cin>>a[i].x>>a[i].y; if (a[i].y < a[i].x) swap(a[i].x,a[i].y); best[i]=1; a[i].p=i+1; way[i]=i; } sort(a,a+n,comp); for (i=0;i<n;i++) for (j=0;j<n;j++) if (j != i) { if (a[i].x >= a[j].x && a[i].y <= a[j].y) { if (best[j]+1 >= best[i]) { best[i]=best[j]+1; way[i]=j; } } } k=best[0]; l=0; for (i=1;i<n;i++) if (best[i] >= k) k=best[i],l=i; while (l != way[l] && k > 0) { oway[f]=a[l].p; f++; l=way[l]; k--; } oway[f]=a[l].p; f++; cout<<f<<endl; for (i=0;i<f;i++) cout<<oway[i]<<" "; cout<<endl;
return 0; } Edited by author 26.04.2011 18:15 Edited by author 26.04.2011 18:15 Re: I got WA #4. pls help me! oh, I have solved it. Thanks! Edited by author 26.04.2011 23:09 Re: I got WA #4. pls help me! Posted by Steven 27 Aug 2013 13:22 Why? |
|
|