Electrons and Positrons

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<iomanip>
 5 #include<algorithm>
 6 #include<cstring>
 7 #include<cmath>
 8 #include<queue>
 9 #define rep(i,j,k) for(register int i = j; i <= k; i++)
10 #define dow(i,j,k) for(register int i = j; i >= k; i--)
11 #define ll long long
12 using namespace std;
13 
14 inline int read() {
15     int s = 0, t = 1; char c = getchar();
16     while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
17     while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
18     return s * t;
19 }
20 
21 const int N = 2e3+5, M = 4e6+5;
22 int dx[N], dy[N], cx[N], cy[N], f[N];
23 struct edge{ int to, nxt; } e[M];
24 int head[N], cnt = 0, ti[N], now = 0;
25 inline void clear() { memset(head,0,sizeof(head)), cnt = 0; }
26 inline void add(int x,int y) {
27     e[++cnt].to = y, e[cnt].nxt = head[x], head[x] = cnt;
28 }
29 #define ez(i,j) for(register int i = head[j]; i; i=e[i].nxt)
30 #define to e[i].to
31 inline bool check(int x) {
32     ez(i,x) {
33         if( ti[to] != now ) {
34             ti[to] = now;
35             if( !f[to] || check(f[to]) ) { f[to] = x; return 1; }
36         }
37     }
38     return 0;
39  }
40 
41 int main() {
42      int q = read();
43      while( q-- ) {
44          int x = read(), y = read();
45          clear();
46          rep(i,1,x) dx[i] = read(), dy[i] = read();
47          rep(i,1,y) cx[i] = read(), cy[i] = read();
48          rep(i,1,y) {
49              rep(j,1,x) if( dx[j] == cx[i] || dy[j] == cy[i] || abs(dx[j] - cx[i]) == abs(dy[j] - cy[i]) ) add(i,j);
50          }
51          memset(f,0,sizeof(f));
52          int ans = 0;
53          rep(i,1,y) {
54              now++;
55              if( check(i) ) ans++;
56          }
57          cout<<ans<<endl;
58      }
59     return 0;
60 }
View Code

 

人一我十,人十我万!追逐青春的梦想,怀着自信的心,永不放弃!仿佛已看到希望,尽管还在远方

posted on 2017-01-28 12:19  83131  阅读(147)  评论(0编辑  收藏  举报

导航