POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)
今天真是完美的一天,这是我在poj上的100A,留个纪念,马上就要期中考试了,可能后面几周刷题就没这么快了,不管怎样,为下一个200A奋斗,
这个题是大白上的牛翻转颜色的题(P153)的弱化版,典型的开关问题;
- /*
- * Created: 2016年04月05日 22时28分26秒 星期二
- * Author: Akrusher
- *
- */
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <cmath>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <vector>
- #include <deque>
- #include <list>
- #include <set>
- #include <map>
- #include <stack>
- #include <queue>
- #include <numeric>
- #include <iomanip>
- #include <bitset>
- #include <sstream>
- #include <fstream>
- using namespace std;
- #define rep(i,a,n) for (int i=a;i<n;i++)
- #define per(i,a,n) for (int i=n-1;i>=a;i--)
- #define in(n) scanf("%d",&(n))
- #define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
- #define in3(x1,x2,x3) scanf("%d%d%d",&(x1),&(x2),&(x3))
- #define inll(n) scanf("%I64d",&(n))
- #define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
- #define inlld(n) scanf("%lld",&(n))
- #define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
- #define inf(n) scanf("%f",&(n))
- #define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
- #define inlf(n) scanf("%lf",&(n))
- #define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
- #define inc(str) scanf("%c",&(str))
- #define ins(str) scanf("%s",(str))
- #define out(x) printf("%d\n",(x))
- #define out2(x1,x2) printf("%d %d\n",(x1),(x2))
- #define outf(x) printf("%f\n",(x))
- #define outlf(x) printf("%lf\n",(x))
- #define outlf2(x1,x2) printf("%lf %lf\n",(x1),(x2));
- #define outll(x) printf("%I64d\n",(x))
- #define outlld(x) printf("%lld\n",(x))
- #define outc(str) printf("%c\n",(str))
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define se second
- #define SZ(x) ((int)(x).size())
- #define mem(X,Y) memset(X,Y,sizeof(X));
- typedef vector<int> vec;
- typedef long long ll;
- typedef pair<int,int> P;
- const int dx[]={-,,,,},dy[]={,-,,,};
- const int INF=0x3f3f3f3f;
- const ll mod=1e9+;
- ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
- const bool AC=true;
- const int M=;
- const int N=;
- int tile[][];
- int opt[][];
- int flip[][];
- int k;
- int get(int x,int y){
- int c=tile[x][y];
- rep(i,,){
- int nx=x+dx[i],ny=y+dy[i];
- if(nx>=&&ny>=&&nx<M&&ny<N){
- c+=flip[nx][ny];
- }
- }
- return c%;
- }
- int calc(){
- rep(i,,M){
- rep(j,,N){
- if(get(i-,j)) flip[i][j]=;
- }
- }
- rep(j,,N){
- if(get(M-,j)){
- return -;
- }
- }
- int res=;
- rep(i,,M)
- rep(j,,N)
- if(flip[i][j]) res++;
- return res;
- }
- void solve(){
- int res=-;
- rep(i,,<<N){
- mem(flip,);
- rep(j,,N){
- flip[][N-j-]=(i>>j)&;
- }
- int num=calc();
- if(num>=&&(res<||res>num)){ //此处可能为0
- res=num;
- memcpy(opt,flip,sizeof(flip));
- }
- }
- printf("PUZZLE #%d\n",k);
- rep(i,,M){
- rep(j,,N){
- printf("%d ",opt[i][j]);
- }
- printf("\n");
- }
- }
- int main()
- {
- int t;
- in(t);
- k=;
- while(t--){
- k++;
- rep(i,,M)
- rep(j,,N){
- in(tile[i][j]);
- }
- solve();
- }
- return ;
- }
POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)的更多相关文章
- POJ 1222 EXTENDED LIGHTS OUT(高斯消元解异或方程组)
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10835 Accepted: 6 ...
- Poj 1222 EXTENDED LIGHTS OUT
题目大意:给你一个5*6的格子,每个格子中有灯(亮着1,暗着0),每次你可以把一个暗的点亮(或者亮的熄灭)然后它上下左右的灯也会跟着变化.最后让你把所有的灯熄灭,问你应该改变哪些灯. 首先我们可以发现 ...
- POJ 1222 EXTENDED LIGHTS OUT(高斯消元)题解
题意:5*6的格子,你翻一个地方,那么这个地方和上下左右的格子都会翻面,要求把所有为1的格子翻成0,输出一个5*6的矩阵,把要翻的赋值1,不翻的0,每个格子只翻1次 思路:poj 1222 高斯消元详 ...
- POJ 1222 EXTENDED LIGHTS OUT(反转)
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12616 Accepted: 8 ...
- POJ 1222 EXTENDED LIGHTS OUT (熄灯问题)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8417 Accepted: 5441 Description In an ...
- poj 1222 EXTENDED LIGHTS OUT(位运算+枚举)
http://poj.org/problem?id=1222 题意:给一个确定的5*6放入矩阵.每一个格子都有一个开关和一盏灯,0表示灯没亮,1表示灯亮着.让你输出一个5*6的矩阵ans[i][j], ...
- 【高斯消元】Poj 1222:EXTENDED LIGHTS OUT
Description In an extended version of the game Lights Out, is a puzzle with 5 rows of 6 buttons each ...
- OpenJudge 2811 熄灯问题 / Poj 1222 EXTENDED LIGHTS OUT
1.链接地址: http://bailian.openjudge.cn/practice/2811 http://poj.org/problem?id=1222 2.题目: 总时间限制: 1000ms ...
- POJ 1222 EXTENDED LIGHTS OUT(高斯消元)
[题目链接] http://poj.org/problem?id=1222 [题目大意] 给出一个6*5的矩阵,由0和1构成,要求将其全部变成0,每个格子和周围的四个格子联动,就是说,如果一个格子变了 ...
随机推荐
- Apache Struts 多个开放重定向漏洞(CVE-2013-2248)
漏洞版本: Struts < 2.3.15.1 漏洞描述: BUGTRAQ ID: 61196 CVE(CAN) ID: CVE-2013-2248 Struts2 是第二代基于Model-Vi ...
- 「Poetize7」Freda的访客
描述 Description 小猫们看到蛋糕比饼干大之后,普遍认为蛋糕比饼干要好>.<.所以,如果Freda 给了第i 只小猫蛋糕且这个小猫是第一个吃到蛋糕的,那么就必须给第i+2,i+4 ...
- UVA 796 Critical Links(无向图求桥)
题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号 (与这个点相连的点的个数m) 依次是m个点的 输入到文件结束. 桥输出的时候需要排序 知识汇总: 桥: 无向连通 ...
- 【转】android开发中如何结束所有的activity
原文网址:http://java--hhf.iteye.com/blog/1826880 每一个activity都有自己的生命周期,被打开了最终就要被关闭. 四种结束当前的activity方法 //关 ...
- 【最短路】Vijos P1022Victoria的舞会2
题目链接: https://vijos.org/p/1022 题目大意: 给一张N个点的有向图,求有几块强连通分量.(N<=200) 题目思路: [动态规划] n比较小,可以用floyd暴力把每 ...
- Merge Intervals——LeetCode
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...
- C++排序
浅谈C++之冒泡排序.希尔排序.快速排序.插入排序.堆排序.基数排序性能对比分析(好戏在后面,有图有真相) 最近一段时间去武汉参加了N多笔试,在几次试题中都出现了排序.偏偏出现了我没怎么看的插入排序, ...
- RAII(Resource Acquisition Is Initialization)资源获得式初始化
当在编写代码中用到异常,非常重要的一点是:“如果异常发生,程序占用的资源都被正确地清理了吗?” 大多数情况下不用担心,但是在构造函数里有一个特殊的问题:如果一个对象的构造函数在执行过程中抛出异常,那么 ...
- 《University Calculus》-chaper8-无穷序列和无穷级数-等比级数
前言:其实无穷序列和无穷级数和数列{an}以及我们接触微积分就给出的极限概念lim有着紧密的联系,它对于我们在具体的问题当中进行建模和数据分析有着非常重要的作用. 无穷序列: 最简单的一种说法,就是一 ...
- poj1611 并查集
题目链接:http://poj.org/problem?id=1611 #include <cstdio> #include <cmath> #include <algo ...