Bombing
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 1723 Accepted Submission(s): 639
It seems not to be a hard work in circumstances of street battles, however, you’ll be encountered a much more difficult instance: recounting exploits of the military. In the bombing action, the commander will dispatch a group of bombers with weapons having the huge destructive power to destroy all the targets in a line. Thanks to the outstanding work of our spy, the positions of all opponents’ bases had been detected and marked on the map, consequently, the bombing plan will be sent to you.
Specifically, the map is expressed as a 2D-plane with some positions of enemy’s bases marked on. The bombers are dispatched orderly and each of them will bomb a vertical or horizontal line on the map. Then your commanded wants you to report that how many bases will be destroyed by each bomber. Notice that a ruined base will not be taken into account when calculating the exploits of later bombers.
3 2 1 2 1 3 2 3 0 1 1 3 0 0
2 1//数据100000很大,故不可直接循环寻找可能导致超时!#include<iostream> #include<cstdio> #include<algorithm> using namespace std; #define MAX 100000+10
struct point { int ind; int wei; };
point x[MAX]; point y[MAX]; bool hash[MAX];
bool cmp(point a,point b) { return a.wei<b.wei; }
int main() { int n,m,i,j; int tx,ty; int flag,w; int ans; while(~scanf("%d%d",&n,&m)&&!(0==n&&0==m)) { for(i=0;i<n;i++) { scanf("%d%d",&tx,&ty); x[i].wei=tx; x[i].ind=i; y[i].wei=ty; y[i].ind=i;
hash[i]=0; }
sort(x,x+n,cmp); sort(y,y+n,cmp);
//memset(hash,0,sizeof(hash)); for(i=0;i<m;i++) { scanf("%d%d",&flag,&w); ans=0; point *p; if(flag==0) { p=x; } else { p=y; } int low=0,high=n-1; int mid=(low+high)>>1; while(low<=high) { if(p[mid].wei<w) low=mid+1; else high=mid-1; mid=(low+high)>>1; } for(j=low;j<n;j++) { if(p[j].wei!=w) break; if(hash[p[j].ind]) continue; hash[p[j].ind]=true; ans++; } cout<<ans<<endl; } cout<<endl; } return 0; }