设为首页 加入收藏

TOP

POJ 3416 Crossing
2015-07-20 17:39:41 来源: 作者: 【 】 浏览:3
Tags:POJ 3416 Crossing
Crossing
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 1564 Accepted: 726

Description

Wintokk has collected a huge amount of coins at THU. One day he had all his coins fallen on to the ground. Unfortunately, WangDong came by and decided to rob Wintokk of the coins.

They agreed to distribute the coins according to the following rules:

Consider the ground as a plane. Wintokk draws a horizontal line on the plane and then WangDong draws a vertical one so that the plane is divided into 4 parts, as shown below.

\

Wintokk will save the coins in I and III while thZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vc2UgZml0IGluIElJIGFuZCBJViB3aWxsIGJlIHRha2VuIGF3YXkgYnkgdGhlIHJvYmJlciBXYW5nRG9uZy48L3A+CjxwPkZvciBmaXhlZCBsb2NhdGlvbnMgb2YgdGhlIGNvaW5zIG93bmVkIGJ5IFdpbnRva2ssIHRoZXkgZHJldyBzZXZlcmFsIHBhaXJzIG9mIGxpbmVzLiBGb3IgZWFjaCBwYWlyLCBXaW50b2trIHdhbnRzIHRvIGtub3cgdGhlIGRpZmZlcmVuY2UgYmV0d2VlbiB0aGUgbnVtYmVyIG9mIHRoZSBzYXZlZCBjb2lucyBhbmQgdGhhdCBvZiB0aGUgbG9zdCBjb2lucy48L3A+CjxwPkl0"s guaranteed that all the coins will lie on neither of the lines drew by that two guys.

Input

The first line contains an integer T, indicating the number of test cases. Then T blocks of test cases follow. For each case, the first line contains two integers N and M, where N is the number of coins on the ground and M indicates how many times they are going to draw the lines. The 2nd to (N+1)-th lines contain the co-ordinates of the coins and the last M lines consist of the M pairs integers (x, y) which means that the two splitting lines intersect at point (x, y).

(N,M ≤ 50000, 0 ≤x,y ≤ 500000)

Output

For each query, output a non-negative integer, the difference described above. Output a blank line between cases.

Sample Input

2
10 3
29 22
17 14
18 23
3 15
6 28
30 27
4 1
26 7
8 0
11 21
2 25
5 10
19 24
10 5
28 18
2 29
6 5
13 12
20 27
15 26
11 9
23 25
10 0
22 24
16 30
14 3
17 21
8 1
7 4

Sample Output

6
4
4

2
2
4
4
4

Source

POJ Monthly--2007.10.06, Wang Dong 解题思路:用两个树状数组维护原点左右两边硬币的个数,先把硬币及原点排序,把所有点插入到右边的树状数组中,取所有在原点左边的点加入到左边树状数组中,同时从右边的树状数组中删除,分别统计下一三象限和二四象限的值相减求绝对值即可
#include
  
   
#include
   
     #include
    
      #include
     
       using namespace std; int l[500005],r[500005]; struct P { int x; int y; int id; }point[50005],coin[50005]; int cmp(P a,P b) { if(a.x!=b.x) return a.x
      
       0;i-=lowbit(i)) sum+=s[i]; return sum; } int main() { int i,t,n,m,ans[50005],y; scanf("%d",&t); while(t--) { y=-1; memset(l,0,sizeof(l)); memset(r,0,sizeof(r)); memset(ans,0,sizeof(ans)); scanf("%d%d",&n,&m); for(i=1;i<=n;i++) { scanf("%d%d",&coin[i].x,&coin[i].y); coin[i].x++;coin[i].y++; if(y
       
        =coin[op].x&&op<=n) { add(l,coin[op].y,y,1); add(r,coin[op].y,y,-1); op++; } int a=sum(r,y)-sum(r,point[i].y)+sum(l,point[i].y); int b=sum(l,y)-sum(l,point[i].y)+sum(r,point[i].y); ans[point[i].id]=abs(a-b); } for(i=1;i<=m;i++) printf("%d\n",ans[i]); printf("\n"); } return 0; }
       
      
     
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ZOJ 1203 Swordfish 剑鱼行动 最.. 下一篇camel-name-utils 在驼峰风格跟下..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis 分布式锁全解 (2025-12-25 17:19:51)
·SpringBoot 整合 Red (2025-12-25 17:19:48)
·MongoDB 索引 - 菜鸟 (2025-12-25 17:19:45)
·What Is Linux (2025-12-25 16:57:17)
·Linux小白必备:超全 (2025-12-25 16:57:14)