|
|
back to boardShow all messages Hide all messages#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; } 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 !!! 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. |
|
|