|
|
back to boardWhat's wrong with my code??? Who can help me!!! #include <iostream.h> #define limit 15000 int a[limit]={0}; int record[32001]={0}; int work(int x){ long l,r,mid; int tot=0; l=1; r=32000; while (l<=r){ mid=(l+r)/2; if (x<=mid) record[mid]++; if (x>=mid) tot+=record[mid]; if (x==mid) break; if (x<mid) r=mid-1; else l=mid+1; } return tot-1; } int main(){ int i,n,x,y; cin>>n; for (i=1; i<=n; i++){ cin>>x>>y; a[work(x)]++; } for (i=0; i<n; i++) cout<<a[i]<<endl; return 0; } Re: What's wrong with my code??? Who can help me!!! Sort the coordinates and use hash-table to keep it. If you do not understand, I can to explain how you can find star you need Sorry for my English !!! Re: What's wrong with my code??? Who can help me!!! The Problem said "Stars are listed in ascending order of Y coordinate. Stars with equal Y coordinates are listed in ascending order of X coordinate." so I have no need to sort the stars, I can be working while reading. I only use array to simulate a BinTree. Re: What's wrong with my code??? Who can help me!!! Sorry!My code is AC now! |
|
|