http://codeforces.com/gym/100650

阅读题,边界的cell的邻居要当成一个环形的来算,时间有8s,状态最多2^16种,所以直接暴力枚举就行了。另外一种做法是逆推。

#include<bits/stdc++.h>
using namespace std; int m,n;
const int maxn = ;
int g[maxn][maxn];
int cnt[maxn][maxn];
int dx[] = {-,,-,-, ,,, };
int dy[] = { ,,-, ,-,,,-}; typedef pair<int,int> pii;
#define fi first
#define se second
#define PB push_back
#define MP make_pair
int tar; bool check(int mask)
{
for(int i = ; i < m; i++)
for(int j = ; j < n; j++){
g[i][j] = (mask>>(i*n+j))&;
}
vector<pii> die,birth;
for(int i = ; i < m; i++)
for(int j = ; j < n; j++){
cnt[i][j] = ;
for(int k = ; k < ; k++){
int nx = i+dx[k],ny = j+dy[k];
if(nx>=m) nx = ;
if(nx<) nx = m-;
if(ny<) ny = n-;
if(ny>=n) ny = ;
cnt[i][j] += g[nx][ny];
}
if(cnt[i][j]<||cnt[i][j]>=) die.PB(MP(i,j));
if(!g[i][j] && cnt[i][j] == ) birth.PB(MP(i,j));
}
for(int i = ; i < die.size(); i++) {
pii &t = die[i];
g[t.fi][t.se] = ;
}
for(int i = ; i < birth.size(); i++){
pii &t = birth[i];
g[t.fi][t.se] = ;
}
int sta = ;
for(int i = ; i < m; i++){
for(int j = ; j < n; j++){
if(g[i][j]) sta |= <<(i*n+j);
}
}
return sta == tar;
} int main()
{
// freopen("in.txt","r",stdin);
int kas = ;
while(~scanf("%d%d",&m,&n)&&m){
if(kas++) putchar('\n');
int N; scanf("%d",&N);
tar = ;
while(N--){
int r,c;
scanf("%d%d",&r,&c);
tar |= <<(r*n+c);
}
int M = <<(n*m);
int ans = ;
for(int mask = ; mask < M; mask++){
ans += check(mask);
}
printf("Case %d: ",kas);
if(ans) printf("%d possible ancestors.",ans);
else printf("Garden of Eden.");
}
return ;
}

Codeforces C The Game of Efil (暴力枚举状态)的更多相关文章

  1. Codeforces 425A Sereja and Swaps(暴力枚举)

    题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...

  2. Codeforces Round #253 (Div. 2)B(暴力枚举)

    就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include< ...

  3. codeforces 869A The Artful Expedient【暴力枚举/亦或性质】

    A. time limit per test 1 second memory limit per test 256 megabytes input standard input output stan ...

  4. Codeforces 791A Bear and Big Brother(暴力枚举,模拟)

    A. Bear and Big Brother time limit per test:1 second memory limit per test:256 megabytes input:stand ...

  5. Codeforces Round #258 (Div. 2)C(暴力枚举)

    就枚举四种情况,哪种能行就是yes了.很简单,关键是写法,我写的又丑又长...看了zhanyl的写法顿时心生敬佩.写的干净利落,简直美如画...这是功力的体现! 以下是zhanyl的写法,转载在此以供 ...

  6. CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)

    [题目链接]:click here~~ [题目大意] 一组题目的数目(n<=15),每一个题目有对应的难度,问你选择一定的题目(大于r个且小于l个)且选择后的题目里最小难度与最大难度差不小于x, ...

  7. HDU 4462:Scaring the Birds(暴力枚举+状态压缩)

    http://acm.hdu.edu.cn/showproblem.php?pid=4462 题意:有一个n*n的地图,有k个空地可以放稻草人,给出每个空地可以放的稻草人属性,属性中有个R代表这个位置 ...

  8. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  9. Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举

    B. Covered Path Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...

随机推荐

  1. Linux locate 文件搜索

    在学习 兄弟连 linux教学视频 的时候,我将所学的 linux 命令记录在我的博客中,方便自己查阅. 文件处理命令:locate 基础的命令 命令名称:locate 命令的所在路径:/usr/bi ...

  2. 算法学习--Day10

    今天开始了新一章的学习,前面的题目虽然做了几道,但是我觉得训练量仍然太小了.不过机试确实很多题目,并且难度也有所不同,所以要针对不同的题目进行专门的练习才好.题目类型有些多,等接下来我将搜索的题目写完 ...

  3. Codevs 1523 地精部落

    1523 地精部落 省队选拔赛  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master 题解       题目描述 Description 传说很久以前,大地上居住 ...

  4. scrapy.Request使用meta传递数据,以及deepcopy的使用

    scrapy.Request(url[,callback,method="GET",headers,body,cookies,meta,dont_filter=False])   ...

  5. css-float浮动详细

    前言 pc端的页面为了保持良好的兼容性,一般会使用css2部分就支持的浮动(float)和定位(postion)来布局.浮动行为怪异,但有迹可循.以下下是在css揭秘一书中总结的浮动内幕. 包含块:浮 ...

  6. vim 快速定位到文件末尾、头部

    gg           : 跳转到文件头 Shift+g   : 跳转到文件末尾 行数+gg : 跳转到指定行,例跳转到123行:123gg

  7. socket编程模拟linux下的ssh代码实现

    实现思路: 1.提供输入指令的客户端: 2.提供返回执行指令结果的服务端 3.寻找服务端返回结果一次无法全部接收的解决思路 服务端代码(ssh_server.py) #coding=utf-8 imp ...

  8. Debug和Release版本区别

    Debug和Release版本区别 众所周知,我们尽心iOS开发,在Xocde调试程序时,分为两种方式Debug和Release,在Target的Setting中相信大家应该能看到很多选项分别为Deb ...

  9. HDU4035(概率期望、树形、数学)

    和ZOJ3329有些像,都是用期望列出来式子以后,为了解式子,设A[i],B[i],此题又多了C[i],然后用递推(此题是树形dp)去求得ABC,最后结果只跟ABC有关,跟列写的期望数组根本无关. 虽 ...

  10. 2017 Multi-University Training Contest - Team 1 Balala Power!

    Talented Mr.Tang has n strings consisting of only lower case characters. He wants to charge them wit ...