zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    原型模板分享——国外高阶版“大众点评”TripAdvisor
    插画手绘入门教程
    十大用户体验设计失败案例,你知道吗?
    用摹客,轻松管理设计规范!
    摹客“独门绝技”之评论审阅篇
    政务管理系统原型模板分享
    产品经理如何做需求分析?
    python基础知socket编程
    异常处理
    元类,__call__方法和单例模式
  • 原文地址:https://www.cnblogs.com/83131yyl/p/6354191.html
Copyright © 2011-2022 走看看