poj 2965

题意:给一个4x4的方格,‘+’符号代表关闭,‘-’符号代表打开,当所有的手柄都为符号‘-’,冰箱门才可以打开,每次对一个点进行操作,与这个点在同一行同一列的点全                部进行状态转变,问将门开打的最少操作次数;

思路:意思就只需要把所有的‘+’符号变成‘-’符号就行了,创建一个bool数组,每次遇到‘+’符号的话将这一行这一列全部进行!操作,最后bool数组中所有为true的坐标            即为要操作的点。

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cmath>
 4 using namespace std;
 5 const int sasuke=4;
 6 bool num[5][5];
 7 int main()
 8 {
 9     char str[5][5];
10     for(int i=1;i<=sasuke;++i){
11         for(int j=1;j<=sasuke;++j)
12             str[i][j]=cin.get();
13             cin.get();
14     }
15
16
17     for(int j,i=1;i<=sasuke;++i)
18         for(j=1;j<=sasuke;++j){
19             if(str[i][j]==‘+‘){
20                 num[i][j]=!num[i][j];
21                 for(int k=1;k<=sasuke;++k){
22                     num[i][k]=!num[i][k];
23                     num[k][j]=!num[k][j];
24                 }
25
26             }
27         }
28     int a[20],b[20];int t=0;
29     int count=0;
30     for(int i=1;i<=sasuke;++i)
31         for(int j=1;j<=sasuke;++j)
32             if(num[i][j]){
33                 ++count;a[t]=i;b[t]=j;++t;
34             }
35     cout << count << endl;
36     for(int i=0;i<t;++i)
37         cout << a[i] << " " << b[i] << endl;
38 }
时间: 2024-12-22 15:50:25

poj 2965的相关文章

The Pilots Brothers&#39; refrigerator - poj 2965

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20325   Accepted: 7830   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a refrigerator. There are 16 handle

poj 2965 The Pilots Brothers&#39; refrigerator[ 枚举 ]

传送门:http://poj.org/problem?id=2965 思路:二进制枚举,递归输出路径.G++ 900+Ms勉强过,C++超时. 代码: #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<stack> #include<map>

POJ 2965 The Pilots Brothers&#39; refrigerator

原题链接:http://poj.org/problem?id=2965 简单的dfs,因为是要求最小值,枚举深度来得到递归终止条件,和 poj1753很像,毕竟是放在一起的. #include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <cmath> #include <cstdlib> #include <vector&g

POJ 2965:The Pilots Brothers&#39; refrigerator

The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18080   Accepted: 6855   Special Judge Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a player needs to o

POJ 2965 The Pilots Brothers&#39; refrigerator (想法题)

POJ 2965 题意: 输入一个形如: -+-- ---- ---- -+-- 4*4图案,+表示close,-表示open,定义一种操作为:改变某个单元格符号(+变-,-变+),同时单元格所在行与所在列的所有单元格符号都会发生改变. 求最少操作次数能使所有单元格内都是'-'.并输出要操作的单元格. 思路: 正常的做法和POJ 1573类似,dfs枚举即可,见code1. 这里提供一种高效的做法: 通过思考我们可以验证,某一个单元格内符号为'+',同时对其所在行与所在列的所有单元格进行操作(其

poj 2965 The Pilots Brothers&#39; refrigerator(dfs 枚举 +打印路径)

链接:poj 2965 题意:给定一个4*4矩阵状态,代表门的16个把手,'+'代表关,'-'代表开,当16个把手都为开(即'-')时,门才能打开,问至少要几步门才能打开 改变状态规则:选定16个把手中的任意一个,可以改变其本身以及同行同列的状态(即若为开,则变为关,若为关,则变为开),这一次操作为一步. 分析:这题与poj 1753思路差不多,每个把手最多改变一次状态, 所有整个矩阵最多改变16次状态 思路:直接dfs枚举所有状态,直到找到目标状态 但是要打印路径,所有应在dfs时记录路径 注

【POJ 2965】 The Pilots Brothers&#39; refrigerator

[POJ 2965] The Pilots Brothers' refrigerator 跟1753(我博客里另一篇有讲)棋盘问题一个做法 预处理后用二进制(BFS)暴力枚举 用到异或运算 很方便 大大缩短代码量 代码如下 #include <cstdio> #include <queue> #include <cstring> #include <stack> #define INF 0x3f3f3f3f using namespace std; type

poj 2965 The Pilots Brothers&amp;#39; refrigerator

The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18040   Accepted: 6841   Special Judge Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a player needs to o

poj 2965 The Pilots Brothers&#39; refrigerator(高斯消元)

The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18641   Accepted: 7145   Special Judge Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a player needs to o

POJ 2965 The Pilots Brothers&#39; refrigerator 搜索+枚举

Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a player needs to open a refrigerator. There are 16 handles on the refrigerator door. Every handle can be in one of two states: open or closed. The refri