POJ 1222 EXTENDED LIGHTS OUT

    今天真是完美的一天,这是我在poj上的100A,留个纪念,马上就要期中考试了,可能后面几周刷题就没这么快了,不管怎样,为下一个200A奋斗,

    这个题是大白上的牛翻转颜色的题(P153)的弱化版,典型的开关问题;

  1. /*
  2. * Created: 2016年04月05日 22时28分26秒 星期二
  3. * Author: Akrusher
  4. *
  5. */
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <cmath>
  10. #include <ctime>
  11. #include <iostream>
  12. #include <algorithm>
  13. #include <string>
  14. #include <vector>
  15. #include <deque>
  16. #include <list>
  17. #include <set>
  18. #include <map>
  19. #include <stack>
  20. #include <queue>
  21. #include <numeric>
  22. #include <iomanip>
  23. #include <bitset>
  24. #include <sstream>
  25. #include <fstream>
  26. using namespace std;
  27. #define rep(i,a,n) for (int i=a;i<n;i++)
  28. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  29. #define in(n) scanf("%d",&(n))
  30. #define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
  31. #define in3(x1,x2,x3) scanf("%d%d%d",&(x1),&(x2),&(x3))
  32. #define inll(n) scanf("%I64d",&(n))
  33. #define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
  34. #define inlld(n) scanf("%lld",&(n))
  35. #define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
  36. #define inf(n) scanf("%f",&(n))
  37. #define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
  38. #define inlf(n) scanf("%lf",&(n))
  39. #define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
  40. #define inc(str) scanf("%c",&(str))
  41. #define ins(str) scanf("%s",(str))
  42. #define out(x) printf("%d\n",(x))
  43. #define out2(x1,x2) printf("%d %d\n",(x1),(x2))
  44. #define outf(x) printf("%f\n",(x))
  45. #define outlf(x) printf("%lf\n",(x))
  46. #define outlf2(x1,x2) printf("%lf %lf\n",(x1),(x2));
  47. #define outll(x) printf("%I64d\n",(x))
  48. #define outlld(x) printf("%lld\n",(x))
  49. #define outc(str) printf("%c\n",(str))
  50. #define pb push_back
  51. #define mp make_pair
  52. #define fi first
  53. #define se second
  54. #define SZ(x) ((int)(x).size())
  55. #define mem(X,Y) memset(X,Y,sizeof(X));
  56. typedef vector<int> vec;
  57. typedef long long ll;
  58. typedef pair<int,int> P;
  59. const int dx[]={-,,,,},dy[]={,-,,,};
  60. const int INF=0x3f3f3f3f;
  61. const ll mod=1e9+;
  62. 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;}
  63. const bool AC=true;
  64.  
  65. const int M=;
  66. const int N=;
  67. int tile[][];
  68. int opt[][];
  69. int flip[][];
  70. int k;
  71. int get(int x,int y){
  72. int c=tile[x][y];
  73. rep(i,,){
  74. int nx=x+dx[i],ny=y+dy[i];
  75. if(nx>=&&ny>=&&nx<M&&ny<N){
  76. c+=flip[nx][ny];
  77. }
  78. }
  79. return c%;
  80. }
  81. int calc(){
  82. rep(i,,M){
  83. rep(j,,N){
  84. if(get(i-,j)) flip[i][j]=;
  85. }
  86. }
  87. rep(j,,N){
  88. if(get(M-,j)){
  89. return -;
  90. }
  91. }
  92. int res=;
  93. rep(i,,M)
  94. rep(j,,N)
  95. if(flip[i][j]) res++;
  96. return res;
  97. }
  98. void solve(){
  99. int res=-;
  100. rep(i,,<<N){
  101. mem(flip,);
  102. rep(j,,N){
  103. flip[][N-j-]=(i>>j)&;
  104. }
  105. int num=calc();
  106. if(num>=&&(res<||res>num)){ //此处可能为0
  107. res=num;
  108. memcpy(opt,flip,sizeof(flip));
  109. }
  110. }
  111. printf("PUZZLE #%d\n",k);
  112. rep(i,,M){
  113. rep(j,,N){
  114. printf("%d ",opt[i][j]);
  115. }
  116. printf("\n");
  117. }
  118. }
  119. int main()
  120. {
  121. int t;
  122. in(t);
  123. k=;
  124. while(t--){
  125. k++;
  126. rep(i,,M)
  127. rep(j,,N){
  128. in(tile[i][j]);
  129. }
  130. solve();
  131. }
  132. return ;
  133. }

      

POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)的更多相关文章

  1. POJ 1222 EXTENDED LIGHTS OUT(高斯消元解异或方程组)

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10835   Accepted: 6 ...

  2. Poj 1222 EXTENDED LIGHTS OUT

    题目大意:给你一个5*6的格子,每个格子中有灯(亮着1,暗着0),每次你可以把一个暗的点亮(或者亮的熄灭)然后它上下左右的灯也会跟着变化.最后让你把所有的灯熄灭,问你应该改变哪些灯. 首先我们可以发现 ...

  3. POJ 1222 EXTENDED LIGHTS OUT(高斯消元)题解

    题意:5*6的格子,你翻一个地方,那么这个地方和上下左右的格子都会翻面,要求把所有为1的格子翻成0,输出一个5*6的矩阵,把要翻的赋值1,不翻的0,每个格子只翻1次 思路:poj 1222 高斯消元详 ...

  4. POJ 1222 EXTENDED LIGHTS OUT(反转)

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12616   Accepted: 8 ...

  5. POJ 1222 EXTENDED LIGHTS OUT (熄灯问题)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8417   Accepted: 5441 Description In an ...

  6. poj 1222 EXTENDED LIGHTS OUT(位运算+枚举)

    http://poj.org/problem?id=1222 题意:给一个确定的5*6放入矩阵.每一个格子都有一个开关和一盏灯,0表示灯没亮,1表示灯亮着.让你输出一个5*6的矩阵ans[i][j], ...

  7. 【高斯消元】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 ...

  8. OpenJudge 2811 熄灯问题 / Poj 1222 EXTENDED LIGHTS OUT

    1.链接地址: http://bailian.openjudge.cn/practice/2811 http://poj.org/problem?id=1222 2.题目: 总时间限制: 1000ms ...

  9. POJ 1222 EXTENDED LIGHTS OUT(高斯消元)

    [题目链接] http://poj.org/problem?id=1222 [题目大意] 给出一个6*5的矩阵,由0和1构成,要求将其全部变成0,每个格子和周围的四个格子联动,就是说,如果一个格子变了 ...

随机推荐

  1. Apache Struts 多个开放重定向漏洞(CVE-2013-2248)

    漏洞版本: Struts < 2.3.15.1 漏洞描述: BUGTRAQ ID: 61196 CVE(CAN) ID: CVE-2013-2248 Struts2 是第二代基于Model-Vi ...

  2. 「Poetize7」Freda的访客

    描述 Description 小猫们看到蛋糕比饼干大之后,普遍认为蛋糕比饼干要好>.<.所以,如果Freda 给了第i 只小猫蛋糕且这个小猫是第一个吃到蛋糕的,那么就必须给第i+2,i+4 ...

  3. UVA 796 Critical Links(无向图求桥)

    题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号  (与这个点相连的点的个数m)  依次是m个点的   输入到文件结束. 桥输出的时候需要排序   知识汇总: 桥:   无向连通 ...

  4. 【转】android开发中如何结束所有的activity

    原文网址:http://java--hhf.iteye.com/blog/1826880 每一个activity都有自己的生命周期,被打开了最终就要被关闭. 四种结束当前的activity方法 //关 ...

  5. 【最短路】Vijos P1022Victoria的舞会2

    题目链接: https://vijos.org/p/1022 题目大意: 给一张N个点的有向图,求有几块强连通分量.(N<=200) 题目思路: [动态规划] n比较小,可以用floyd暴力把每 ...

  6. Merge Intervals——LeetCode

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  7. C++排序

    浅谈C++之冒泡排序.希尔排序.快速排序.插入排序.堆排序.基数排序性能对比分析(好戏在后面,有图有真相) 最近一段时间去武汉参加了N多笔试,在几次试题中都出现了排序.偏偏出现了我没怎么看的插入排序, ...

  8. RAII(Resource Acquisition Is Initialization)资源获得式初始化

    当在编写代码中用到异常,非常重要的一点是:“如果异常发生,程序占用的资源都被正确地清理了吗?” 大多数情况下不用担心,但是在构造函数里有一个特殊的问题:如果一个对象的构造函数在执行过程中抛出异常,那么 ...

  9. 《University Calculus》-chaper8-无穷序列和无穷级数-等比级数

    前言:其实无穷序列和无穷级数和数列{an}以及我们接触微积分就给出的极限概念lim有着紧密的联系,它对于我们在具体的问题当中进行建模和数据分析有着非常重要的作用. 无穷序列: 最简单的一种说法,就是一 ...

  10. poj1611 并查集

    题目链接:http://poj.org/problem?id=1611 #include <cstdio> #include <cmath> #include <algo ...