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 ...
随机推荐
- tcp/ip详解(转)
与UDP不同的是,TCP提供了一种面向连接的.可靠的字节流服务.TCP协议的可靠性主要有以下几点保障: (1)应用数据分割成TCP认为最适合发送的数据块.这部分是通过“MSS”(最大数据包长度)选项来 ...
- HDU - 6016 Count the Sheep 二分图+思维
Count the Sheep 题意: 问题描述 开学翘课固然快乐,然而也有让呃喵抓狂的事,那当然就是考试了!这可急坏了既要翘课又想要打BC还要准备考试的呃喵. 呃喵为了准备考试没有时间刷题,想打BC ...
- eclipse neon 离线安装插件
我的eclipse版本是4.6.3,以安装svn插件为例. 网上查到很多资料都是说找到eclipse目录下"plugins"和"features"文件夹,将下载 ...
- POJ1111【BFS】
在搜1011的时候误搜了1111,简单BFS吧,多一个X就是多四个面,每次看看他的四个面有多少个重复的,然后剪掉,最后答案加上就好了: code: //#include <bits/stdc++ ...
- bzoj 3876: [Ahoi2014&Jsoi2014]支线剧情【有上下界有源汇最小费用最大流】
每条边流量有下界有费用,很显然是有上下界有源汇最小费用最大流 连边(s,1,(0,inf),0),(i,t,(0,inf),0),表示从1出发inf次从每个点结束inf次 连边(i,j,(1,inf) ...
- [Xcode 实际操作]八、网络与多线程-(17)使用网址会话对象URLSession向远程服务器上传图片
目录:[Swift]Xcode实际操作 本文将演示如何通过网址会话对象URLSession向远程服务器上传图片. 网址会话对象URLSession具有在后台上传和下载.暂停和恢复网络操作.丰富的代理模 ...
- 在mpvue框架中使用Vant WeappUI组件库的注意事项
1如何引入组件库 有两种方法 1 npm下载 2 下载代码,下面介绍第二种方法. 在gitHub上, 链接如下 https://github.com/youzan/vant-weapp 首先在自己项目 ...
- 在maven中引入本地jar包的方法
一.第一种方式: 1.电脑安装maven 2.下载jar.例如 gj.jar 3.把jar随便放一个位置 4.在jar包目录下打开cmd输入: mvn install:install-file -Df ...
- CF446B DZY Loves Modification 【思维/优先队列】By cellur925
题目传送门 题目大意:给一个 \(n*m\) 的矩阵,并进行 \(k\) 次操作,每次操作将矩阵的一行或一列的所有元素的值减 \(p\) ,得到的分数为这次修改之前这一列/一行的元素和,求分数最大值. ...
- java的无序机制
简单说一下上面提到的无序写,这是jvm的特性,比如声明两个变量,String a; String b; jvm可能先加载a也可能先加载b.同理,instance = new Singleton();可 ...