DlIFVDq
P2955 [USACO09OCT]奇数偶数Even? Odd?
本题亮点:I (1 <= I <= 10^60);这是一个long long 也存不下来的数,那怎么读入呢?又怎么储存呢?
字符串大爷。
(注意字符串的最后一位可能是‘ ’,注意一下)
372. 棋盘覆盖
- 建图的方式
- 数组的空间多思考一下
/*
4 6
1 3
1 4
2 1
2 3
4 2
4 4
*/
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define dwn(i,a,b) for(int i=a;i>=b;--i)
template <typename T> inline void rd(T &x){x=0;char c=getchar();int f=0;while(!isdigit(c)){f|=c=='-';c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x=f?-x:x;}
inline void write(int n){if(n==0)return;write(n/10);putchar(n%10+'0');}
#define mem(a,b) memset(a,b,sizeof(a))
#define ee(i,u) for(int i=head[u];i;i=e[i].next)
#define maxx 2000000
const int N = 105;
int head[maxx],edge_num,ans;
int match[20000],col[N][N];//为什么开10000就不对呢????
bool zg[20000];
bool vis[N][N];
struct edge{
int v,next;
}e[maxx];
inline void add(int u,int v){
e[++edge_num].v=v;
e[edge_num].next=head[u];
head[u]=edge_num;
}
int n,t,x,y;
inline bool dfs(int u){
ee(i,u){
int v=e[i].v;
if(!zg[i]){
zg[i]=1;
if(match[v]==0 || dfs(match[v])){
match[v]=u;
return 1;
}
}
}
return 0;
}
int main(){
#ifdef WIN32
//freopen("qipan.txt","r",stdin);
#endif
rd(n),rd(t);
while(t--){
rd(x),rd(y);
vis[x][y]=1;
}
rep(i,1,n)
rep(j,1,n){
if((i+j)%2==0 && vis[i][j]==0) col[i][j]=2;//白
else if((i+j)%2==1 && vis[i][j]==0) col[i][j]=1;//黑
}
rep(i,1,n)
rep(j,1,n){/*
if(col[i][j]==1){
if(col[i+1][j]==2){
add((i-1)*n+j,i*n+j);
printf("%lld %lld
",(i-1)*n+j,i*n+j);
}
else if(col[i-1][j]==2){
add((i-1)*n+j,(i-2)*n+j);
printf("%lld %lld
",(i-1)*n+j,(i-2)*n+j);
}
else if(col[i][j-1]==2){
add((i-1)*n+j,(i-1)*n+j-1);
printf("%lld %lld
",(i-1)*n+j,(i-1)*n+j-1);
}
else if(col[i][j+1]==2){
add((i-1)*n+j,(i-1)*n+j+1);
printf("%lld %lld
",(i-1)*n+j,(i-1)*n+j+1);
}
}*/
if(col[i][j]==2){
if(col[i+1][j]==1){
add((i-1)*n+j,i*n+j);
//printf("%lld %lld
",(i-1)*n+j,i*n+j);
}
if(col[i-1][j]==1){
add((i-1)*n+j,(i-2)*n+j);
//printf("%lld %lld
",(i-1)*n+j,(i-2)*n+j);
}
if(col[i][j-1]==1){
add((i-1)*n+j,(i-1)*n+j-1);
//printf("%lld %lld
",(i-1)*n+j,(i-1)*n+j-1);
}
if(col[i][j+1]==1){
add((i-1)*n+j,(i-1)*n+j+1);
//printf("%lld %lld
",(i-1)*n+j,(i-1)*n+j+1);
}
}
}
mem(match,0);
rep(i,1,n*n){
mem(zg,0);
if(dfs(i))
ans++;
}
printf("%d",ans);
return 0;
}