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
  • 相关阅读:
    HTML 嵌入 SWF ,访问域的问题
    Flex 4 中,StageScaleMode 设置
    一句话清除MC下所有的子
    DataGrid 表头标题,表格文字的字体设置
    Flash中,将某个元件置于最顶层
    Android开发中使用SQLite 数据库
    Android多分辨率支持说明
    Android adb shell 命令大全
    Android Camera 使用小结
    Android多分辨率支持以及各种类型图标尺寸大小
  • 原文地址:https://www.cnblogs.com/83131yyl/p/6354191.html
Copyright © 2011-2022 走看看