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. docker的安装与卸载

    卸载老版本docker sudo apt-get remove docker docker-engine docker.io /var/lib/docker/目录下存放着 images, contai ...

  2. 1.15-1.16 sqoop action

    一.sqoop action1 http://oozie.apache.org/docs/4.0.0/DG_SqoopActionExtension.html 1.准备文件 ## [root@hado ...

  3. [工作笔记]JDK版本不同导致的SSL异常

    前言 遇到这个问题得说一下笔者的开发环境,笔者所在公司,平时开发用的web容器是jboss,使用的JDK是oracle的JDK,但是测试和生产环境用的是WAS,JDK用的是IBM的JDK,由于项目的不 ...

  4. 20个Flutter实例视频教程-第05节: 酷炫的路由动画-1

    视屏地址: https://www.bilibili.com/video/av39709290/?p=5 博客地址: https://jspang.com/post/flutterDemo.html# ...

  5. tomcat的bin文件夹下的.bat和.sh文件

    tomcat的bin文件夹中存在一份.bat文件和相对应的.sh文件,一个是为了在window系统上执行的文件,另一个是linux下的批处理文件.例如:startup.bat和startup.sh. ...

  6. 使用Try.NET创建可交互.NET文档

    原文地址:Create Interactive .NET Documentation with Try .NET 原文作者:Maria 译文地址:https://www.cnblogs.com/lwq ...

  7. Swift3.0 轮播图

    使用三个UIButton实现无限轮播:https://github.com/LXfeiYu/LXCarouselImages.git 喜欢的朋友给个星!!! 功能: 1.可以选择开启和关闭定时器 2. ...

  8. android通过获取摄像头照片,实时与点传输

    http://blog.csdn.net/csh159/article/details/7926654/ GetIP: [html] view plain copy print? package co ...

  9. Unity 2D骨骼动画2:创建真实动画

    http://bbs.9ria.com/thread-401781-1-1.html 在这个系列,我们将关注Unity引擎提供的基于骨骼动画工具.它的主要思想是为了把它应用到你自己的游戏来介绍和教基本 ...

  10. 干货:排名前16的Java工具类

    在Java中,工具类定义了一组公共方法,这篇文章将介绍Java中使用最频繁及最通用的Java工具类.以下工具类.方法按使用流行度排名,参考数据来源于Github上随机选取的5万个开源项目源码. 一. ...