Codeforces C The Game of Efil (暴力枚举状态)
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 (暴力枚举状态)的更多相关文章
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
- Codeforces Round #253 (Div. 2)B(暴力枚举)
就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include< ...
- codeforces 869A The Artful Expedient【暴力枚举/亦或性质】
A. time limit per test 1 second memory limit per test 256 megabytes input standard input output stan ...
- 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 ...
- Codeforces Round #258 (Div. 2)C(暴力枚举)
就枚举四种情况,哪种能行就是yes了.很简单,关键是写法,我写的又丑又长...看了zhanyl的写法顿时心生敬佩.写的干净利落,简直美如画...这是功力的体现! 以下是zhanyl的写法,转载在此以供 ...
- CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)
[题目链接]:click here~~ [题目大意] 一组题目的数目(n<=15),每一个题目有对应的难度,问你选择一定的题目(大于r个且小于l个)且选择后的题目里最小难度与最大难度差不小于x, ...
- HDU 4462:Scaring the Birds(暴力枚举+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=4462 题意:有一个n*n的地图,有k个空地可以放稻草人,给出每个空地可以放的稻草人属性,属性中有个R代表这个位置 ...
- Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...
- 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 ...
随机推荐
- E20180603-hm
breadth n. 宽度; 宽容; (知识.兴趣等的) 广泛; depth n. 深度; 深处,深海; 深奥,奥妙; 进深; deep adj. 深的; 深远的,深奥; 重大的,深刻的; 强烈的 ...
- Qt中csv文件的导入与导出
转自:http://blog.csdn.net/mingxia_sui/article/details/7683030 CSV 1.简介: 全称:Comma Separated Values. 是“逗 ...
- 【Unity3D】3D角色换装++ Advance
http://www.cnblogs.com/dosomething/archive/2012/12/15/2818897.html 本文在之前的文章Unity3D角色换装的原理 基础上做一个补充 给 ...
- Pycharm 配置autopep8到菜单
Pycharm 可以自动检测PEP8规范. 我们可以安装autopep8来自动修改文件实现PEP8规范. 1.通过Pycharm安装autopep8 2.File->Setting->Ex ...
- bzoj 4464: [Jsoi2013]旅行时的困惑【贪心】
据说正解是有上下界最小流,但是这种1e5的玩意问什么要跑网络流啊-- 贪心即可,注意一点是可以有多条路径经过一条边-- 以1为根,设d[u][0/1]为u到父亲的边是向下/向上,g记录这个点儿子中不能 ...
- 洛谷P4884 多少个1?(BSGS)
传送门 模数好大……__int128好麻烦……而且BSGS第一次写有点写蒙了…… $11...1(N个1)\equiv k(mod m)$很难算,那么考虑转化一下 先把$11...1(N个1)$写成$ ...
- [Xcode 实际操作]九、实用进阶-(25)使用Storyboard(故事版)的约束功能,使项目快速适配各种分辨率的设备
目录:[Swift]Xcode实际操作 本文将演示使用故事版的约束功能,使项目快速适配各种分辨率的设备. 在项目导航区打开并编辑主故事版[Main.storyboard]. 在当前故事版中,已经存在一 ...
- SpringBoot | 查看默认版本配置
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...
- 并发编程协程(Coroutine)之Gevent
并发编程协程之Gevent Gevent官网文档地址:http://www.gevent.org/contents.html 基本概念 我们通常所说的协程Coroutine其实是corporate r ...
- flask_之参数传递
参数篇 request接收数据 request对象 method:当前请求方法(POST,GET等) url:当前链接地址 path:当前链接的路径 environ:潜在的WSGI环境 headers ...