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 ...
随机推荐
- 1.1-1.4 hadoop调度框架和oozie概述
一.hadoop调度框架 Linux Crontab Azkaban https://azkaban.github.io/ Oozie http://oozie.apache.org/ Zeus(阿里 ...
- monkey基本命令及脚本编写
Monkey 是Android自带的黑盒测试工具,一般通过随机触发界面事件,来确定应用是否会发生异常,多用于android应用的稳定性.压力测试 基本命令: adb shell monkey [op ...
- Flutter实战视频-移动电商-29.列表页_商品列表数据模型建立
29.列表页_商品列表数据模型建立 简历数据模型 json生成dart类的网站: https://javiercbk.github.io/json_to_dart/ json数据 {",&q ...
- Makefile研究(二)—— 完整可移植性模板
转自:http://blog.csdn.net/jundic/article/details/17676461 一直想写一个很全很好移植的Makefile模板,我觉得一个完整makefile 应该包含 ...
- Grid++Report应用(引入项目中)
1.将Grid++Report安装文件中(\WebSamples\asp.net(csharp)\App_Code)的ReportData.cs,MssqlReportData.cs两个文件复制到自己 ...
- C++设计模式之工厂方法模式
来自:http://blog.csdn.net/pangshaohua/article/details/38912555 参考写的一个工厂demo 1.定义"背景风格的抽象类".& ...
- 端口渗透·网站渗透过程 --21 ,22,873,3306,6379,8080(8080端口是针对CMS的渗透)
声明:文章渗透网站为模拟环境,文章只为利用过程 文章为信息收集和端口渗透两部分,21端口为ftp版本漏洞 8080端口为CMS的渗透 信息收集: ·使用扫描工具nmap ,PortScan 对整个网段 ...
- MVC3+jquery Uploadify 上传文件
最近做项目用到了上传图片的功能,以前也写过这类代码,不过都是用传统的file标签,今天整理一个好用的插件Uploadify..都做了一些注释,一看便知. 可以去官网下载最新的:Uploadify下载地 ...
- iOS集成支付宝支付
本文由本人原创发表于博客园,转载请注明出处 http://www.cnblogs.com/wangqw/p/5074907.html 一. 开发前准备 iOS 支付宝SDK下载地址:(内含iOS An ...
- 通过java调用Http接口上传图片到服务器
https://blog.csdn.net/jaedons/article/details/78563841 /** * 测试上传png图片 * */ public static void testU ...