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. maven构建java项目、web项目

    maven构建java项目.web项目 一.mvn构建web项目 1安装mvn(包括path) 2命令:mvn archetype:create -DgroupId=cn.edu.sdau.neat ...

  2. MyEclipse控制台console自动跳动的解决方案

    有时候Eclipse启动,控制台console不会自动跳出来,需要手工点击该选项卡才行 按下面的设置,可以让它自动跳出来(或不跳出来): windows  ->   preferences   ...

  3. vue中使用chart.js

    1,安装chart.js和vue-chart.js npm install chart.js --save npm install vue-chart.js --save 2,独立文件,方便修改 封装 ...

  4. HTTP请求信息和响应信息的格式

    请求: (1)请求行信息 Request URL: 发起请求的路径 Request Method:请求的方式(get  post  head put  delete  trace  options等) ...

  5. WindApi2 , WindOriginalApiLibrary 突然不兼容问题

    1. 在新的电脑上从tfs拉下代码后编译, windoriginalapilibrary 这个工程弹出对话框,要求转为vs2013编译,选择同意,编译成功 2.WindApi2 的Reference列 ...

  6. Node.js 内置模块fs(文件系统)

    fs模块的三个常用方法 1.fs.readFile() -- 读文件 2.fs.writeFile() -- 写文件 3.fa.stat() -- 查看文件信息 fs模块不同于其它模块的地方是它有异步 ...

  7. ios代码大全

    http://blog.csdn.net/kepoon/article/details/7763106

  8. Visual Studio 2015、2013、2012、2010、2008、2005各版本下载+有效密钥激活

    Visual Studio是微软发布的一个集成开发工具,业内一般简称为VS,广泛应用于Windows软件开发.网站开发等,是目前十分流行的windows应用程序的集成开发工具,如果大家不了解,可以简单 ...

  9. Java并发编程面试题1

    package com.mozq.thread.producer2; /* * 面试题2:以下代码是否存在错误 class ThreadTest implements Runnable{ public ...

  10. [題解](二分答案/單調隊列)luogu_P1419尋找段落

    果然又抄的題解... 顯然答案具有單調性,而對于平均數計算的式子我們移一下項, 若s[l..r]>mid*(r-l+1)无解, 於是我們把每個數都減去一個mid,看和的正負即可,如果為正就可能有 ...