HDU 4742 Pinball Game 3D (KD树)

HDU4742

用cdq分治搞了这题以后,再用KD树搞一发,KD树也挺裸的了,就是求一个范围里面的最小值。

Pinball Game 3D

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 633 Accepted Submission(s): 256

Problem Description

RD is a smart boy and excel in pinball game. However, playing common 2D pinball game for a great number of times results in accumulating tedium. Recently, RD has found a new type of pinball game, a 3D pinball game. The 3D pinball game space can be regarded as a three dimensional coordinate system containing N balls. A ball can be considered as a point. At the beginning, RD made a shot and hit a ball. The ball hit by RD will move and may hit another ball and the “another ball” may move and hit another another ball, etc. But once a ball hit another ball, it will disappear. RD is skilled in this kind of game, so he is able to control every ball’s moving direction. But there is a limitation: if ball A’s coordinate is (x1,y1,z1) and ball B’s coordinate is (x2,y2,z2), then A can hit B only if x1 <= x2 and y1 <= y2 and z1 <= z2. Now, you should help RD to calculate the maximum number of balls that can be hit and the number of different shooting schemes that can achieve that number. Two schemes are different if the sets of hit balls are not the same. The order doesn’t matter.

Input

The first line contains one integer T indicating the number of cases. In each case, the first line contains one integer N indicating the number of balls. The next N lines each contains three non-negative integer (x, y, z), indicating the coordinate of a ball. The data satisfies T <= 3, N <= 105, 0 <= x, y, z <= 230, no two balls have the same coordinate in one case.

Output

Print two integers for each case in a line, indicating the maximum number of balls that can be hit and the number of different shooting schemes. As the number of schemes can be quite large, you should output this number mod 230.

Sample Input

2 3 2 0 0 0 1 0 0 1 1 5 3 0 0 0 1 0 0 0 1 0 2 2 3 3 3

Sample Output

2 1 3 2

Hint

In the first case, RD can shoot the second ball at first and hit the third ball indirectly. In the second case, RD can shoot the second or the third ball initially and hit the fourth ball as well as the fifth ball. Two schemes are both the best.

直接上代码了!!!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/* ***************

Author :kuangbin

Created Time :2014/9/4 23:32:36

File Name :E:\2014ACM\专题学习\KD树\HDU4742.cpp

************************************************ */

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <string>

#include <math.h>

#include <stdlib.h>

#include <time.h>

using namespace std;

const int MAXN = 100010;

const int MOD = 1<<30;

const int INF = 0x7fffffff;//这个一定要够大

struct Node{

pair<int,int>e,sub,cur;

bool div;

Node *lc,*rc;

};

Node pool[MAXN],*tail;

Node *root;

bool cmpX(const pair<int,int> &a,const pair<int,int> &b){return a.first < b.first || (a.first == b.first && a.second < b.second);}

bool cmpY(const pair<int,int> &a,const pair<int,int> &b){return a.second < b.second || (a.second == b.second && a.first < b.first);}

bool cmp(const pair<int,int> &a,const pair<int,int> &b,bool div){return div?cmpY(a,b):cmpX(a,b);}

Node* build(pair<int,int> *a,int l,int r,bool div){

if(l >= r)return NULL;

Node *p = tail++;

p->div = div;

int mid = (l+r)/2;

nth_element(a+l,a+mid,a+r,div?cmpY:cmpX);

p->e = a[mid];

p->cur = p->sub = make_pair(0,0);

p->lc = build(a,l,mid,!div);

p->rc = build(a,mid+1,r,!div);

return p;

}

inline void update(pair<int,int> &a,pair<int,int> b){

if(a.first < b.first)a = b;

else if(a.first == b.first){

a.second += b.second;

if(a.second >= MOD)a.second -= MOD;

}

}

void add(Node *p,pair<int,int> e,pair<int,int> v){

update(p->sub,v);

if(e == p->e){

update(p->cur,v);

return;

}

else {

if(cmp(p->e,e,p->div))add(p->rc,e,v);

else add(p->lc,e,v);

}

}

pair<int,int>ans;

//查询最大值

void get(Node *p,pair<int,int>e,int maxx,int maxy){

if(!p)return;

if(p->sub.first < ans.first)return;

if(maxx <= e.first && maxy <= e.second)

update(ans,p->sub);

else {

if(p->e.first <= e.first && p->e.second <= e.second)update(ans,p->cur);

if(p->div){

if(p->e.second <= e.second)get(p->rc,e,maxx,maxy);

get(p->lc,e,maxx,min(maxy,p->e.second));

}

else {

if(p->e.first <= e.first)get(p->rc,e,maxx,maxy);

get(p->lc,e,min(maxx,p->e.first),maxy);

}

}

}

struct TNode{

int x,y,z;

void input(){

scanf("%d%d%d",&x,&y,&z);

}

bool operator < (const TNode &b)const{

if(x != b.x)return x < b.x;

else if(y != b.y)return y < b.y;

else return z < b.z;

}

}node[MAXN];

pair<int,int>p[MAXN];

pair<int,int>dp[MAXN];

int main()

{

int T;

int n;

scanf("%d",&T);

while(T--){

scanf("%d",&n);

int cnt = 0;

for(int i = 0;i < n;i++){

node[i].input();

p[cnt++] = make_pair(node[i].y,node[i].z);

}

sort(node,node+n);

sort(p,p+cnt);

cnt = unique(p,p+cnt)-p;

tail = pool;

root = build(p,0,cnt,0);

for(int i = 0;i < n;i++)dp[i] = make_pair(1,1);

for(int i = 0;i < n;i++){

ans = make_pair(0,0);

get(root,make_pair(node[i].y,node[i].z),INF,INF);

ans.first++;

update(dp[i],ans);

add(root,make_pair(node[i].y,node[i].z),dp[i]);

}

printf("%d %d\n",root->sub.first,root->sub.second);

}

return 0;

}
------ 本文结束------
  • 本文作者: kuangbin
  • 本文链接: 370.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
0%