hdu4678Mine
http://acm.hdu.edu.cn/showproblem.php?pid=4678
之前写了一并差集找连通块 貌似不对 比赛时写的dfs爆栈了 只好用bfs了
单独数字块 为1
空白+数字块 数字数%2+1
异或
#include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<queue>
using namespace std;
#define N 1010
int dis[][] = {,,-,,,,,-,,,,-,-,,-,-};
int n,m,k;
int vis[N][N],o[N][N],f[N][N];
struct node
{
int x,y;
};
int bfs(int x,int y)
{
queue<node>q;
struct node st,sd;
int num = ,i;
st.x = x;
st.y = y;
vis[x][y] = ;
q.push(st);
while(!q.empty())
{
sd = q.front();
int tx = sd.x;
int ty = sd.y;
q.pop();
for(i = ;i < ; i++)
{
int dx = tx+dis[i][];
int dy = ty+dis[i][];
if(dx>=&&dx<n&&dy>=&&dy<m&&!vis[dx][dy])
{
vis[dx][dy] = ;
if(!f[dx][dy]&&o[dx][dy])
num++;
st.x = dx;
st.y = dy;
if(!f[dx][dy]&&!o[dx][dy])
q.push(st);
}
}
}
if(num%==)
return ;
return ;
}
int main()
{
int i,j,t,kk=;
scanf("%d",&t);
while(t--)
{
kk++;
scanf("%d%d%d",&n,&m,&k);
for(i = ; i <= n ; i++)
for(j = ; j <= m ; j++)
{
f[i][j] = ;
o[i][j] = ;
vis[i][j] = ;
}
while(k--)
{
int x,y;
scanf("%d%d",&x,&y);
f[x][y] = ;
for(i = ; i < ; i++)
{
int tx = x+dis[i][];
int ty = y+dis[i][];
if(tx>=&&tx<n&&ty>=&&ty<m)
o[tx][ty] = ;
}
}
int ans=;
for(i = ; i < n ; i++)
for(j = ; j < m ; j++)
if(!f[i][j]&&!vis[i][j]&&o[i][j]==)
{
int w = bfs(i,j);
ans ^= w;
}
for(i = ; i < n ; i++)
for(j = ; j < m ; j++)
if(!f[i][j]&&!vis[i][j]&&o[i][j])
ans ^= ;
printf("Case #%d: ",kk);
if(ans==)
printf("Fanglaoshi\n");
else
printf("Xiemao\n");
}
return ;
}
hdu4678Mine的更多相关文章
随机推荐
- Golang中解析json,构造json
json解析是如今(网络)应用程序开发中最不可或缺的一环了.许多语言需要库支持才可以解析.构造json,但Golang凭借着原生库就可以很好地做到这一点. json的基本表现形式有两个:struct与 ...
- jQuery 源码分析 7: sizzle
jQuery使用的是sizzle这个选择器引擎,这个引擎以其高速著称,其实现十分精妙但是也足够复杂,下面现简单分析一下相关的代码. 在jQuery的部分API接口是直接引用了Sizzle的方法,这些接 ...
- lucene4.0 基于smb文件服务器的全文检索
使用lucene 4.0版本的全文检索 所需要的jar包 网速太慢,下次有空再把jar传上来 1.FileIndex 建立索引,查询,删除,更新 package com.strongit.tool ...
- the evaluation period for visual studio trial edition has ended的解决方法-转发
首先献上自己收集的Visual studio 2008序列号: Visual Studio 2008 Professional Edition: XMQ2Y-4T3V6-XJ48Y-D3K2V-6C4 ...
- 第二章 Qt常用工具的介绍
第二章 Qt常用工具的介绍 (1)No.1 qmake 相信编写过Makefile的开发人员,随着工程中源码的级数递增和以类型.功能.模块组织源码的子目录的增多,都不愿意重复机械地手工编写这个工程管理 ...
- 排序算法SIX:冒泡排序BubbleSort
/** *冒泡排序: * 两个两个比较,一轮过后最大的排在了最后面 * n个数变为n-1个没排好的数 * 再进行一轮 * 第二大的排在了倒数第二个 * 以此类推 * 直到排到第一个为止 * * 弄两个 ...
- leetcode 解题 String to Integer (atoi)(C&python)
//此题是easy题,比较简单,主要困难在考虑全输入的各种情况://1.开始的时候有空格等空白字符//2.开头有加减号//3.溢出(第一次写就是没有考虑到这个情况) //C代码int myAtoi(c ...
- uCOS-II任务的挂起和恢复
函数描述 OSTaskSuspend() 功能描述:无条件挂起一个任务.调用此函数的任务也可以传递参数OS_PRIO_SELF,挂起调用任务本身.函数原型:INT8U OSTaskSuspend ( ...
- 【filter】springmvc web.xml
1.filter用于拦截用户请求,在服务器作出响应前,可以在拦截后修改request和response,这样实现很多开发者想得到的功能. 2.filter实现 ×编写一个继承Filter接口的类 ×在 ...
- poj 2559 Largest Rectangle in a Histogram (单调栈)
http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 6 ...