POJ 2965贪心神解
貌似和POj1753一样是一般都是用为位运算+枚举做的。但是捏。这里用了贪心算法很容易。怎么样才能做到只把当前位置的+改为-而不改变其它所有位置的符号呢。嗯。就是把当前位置所在的行和列所在的元素都反转一次。最后统计操作数是记数的位置就是要操作的位置。详见代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char m;
int num[5][5];
int main()
{
memset(num, 0, sizeof(num));
for (int i=0; i<4; ++i)
{
for (int j=0; j<4; ++j)
{
cin >> m;
if (m == '+')
{
for (int k=0; k<4; ++k)
{
num[i][k]++;
num[k][j]++;
}
num[i][j]--;
}
}
}
int tot = 0;
for (int i=0; i<4; ++i)
{
for (int j=0; j<4; ++j)
{
tot += num[i][j] % 2;
}
}
cout << tot << endl;
for (int i=0; i<4; ++i)
{
for (int j=0; j<4; ++j)
{
if (num[i][j] % 2)
{
cout << i+1 << ' ' << j+1 << endl;
}
}
}
return 0;
}
POJ 2965贪心神解的更多相关文章
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- 枚举 POJ 2965 The Pilots Brothers' refrigerator
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- poj 2965 The Pilots Brothers' refrigerator(dfs 枚举 +打印路径)
链接:poj 2965 题意:给定一个4*4矩阵状态,代表门的16个把手.'+'代表关,'-'代表开.当16个把手都为开(即'-')时.门才干打开,问至少要几步门才干打开 改变状态规则:选定16个把手 ...
- POJ 2965 The Pilots Brothers' refrigerator【枚举+dfs】
题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#pro ...
- poj 2965 The Pilots Brothers' refrigerator枚举(bfs+位运算)
//题目:http://poj.org/problem?id=2965//题意:电冰箱有16个把手,每个把手两种状态(开‘-’或关‘+’),只有在所有把手都打开时,门才开,输入数据是个4*4的矩阵,因 ...
- poj 2965
http://poj.org/problem?id=2965 本题要结合poj 1753 来看最好...又有了一点搜索的经验..加油... #include <iostream> #inc ...
- POJ 2965&&1753
最近由于复习备考(然而考得还是很炸),很久没打题目了.现在开始刷寒假作业,不得不搞POJ 话说没有中文真的好烦啊! 先看1753 题目大意是说在一个4*4的格子中有黑白两色的棋子,你可以翻动其中的棋子 ...
- POJ 2965 The Pilots Brothers' refrigerator (枚举+BFS+位压缩运算)
http://poj.org/problem?id=2965 题意: 一个4*4的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...
- poj 2965 The Pilots Brothers' refrigerator (dfs)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17450 ...
随机推荐
- tf.multiply()和tf.matmul()区别
(1)tf.multiply是点乘,即Returns x * y element-wise. (2)tf.matmul是矩阵乘法,即Multiplies matrix a by matrix b, p ...
- Win10 Edge浏览器怎么重装 Win10重装Edge浏览器
具体如下: 重新安装Microsoft Edge 1.按Windows键+ R,打开 输入以下代码,可以直接复制黏贴. %LocalAppData%\Packages\Microsoft.Micros ...
- CDC画图
CDC* pdc: CRect rcBounds: 1. 画直线 pdc->MoveTo(rcBounds.TopLeft());//将画笔移动到左上角这个点,使用这个点作为起点画图 pdc-& ...
- spring boot 启动后执行初始化方法
http://blog.csdn.net/catoop/article/details/50501710 1.创建实现接口 CommandLineRunner 的类 package org.sprin ...
- NS-3 MyFirstScriptExample
安装好了NS-3之后,我根据一些教程学习了NS-3的几个关键的概念,然后照着例子和自己对它的一些理解,尝试的打了我自己的第一个脚本程序:MyFirstScriptExample 具体代码如下: #in ...
- poj 2762 Going from u to v or from v to u? trajan+拓扑
Going from u to v or from v to u? Description In order to make their sons brave, Jiajia and Wind t ...
- Mysql-SqlServer区别
/* sql规范 所有关键字大写 表面跟字段跟数据库对应 一条sql语句结束必须跟;号 */ /*关键字处理*/ --sqlserver SELECT * FROM [Date]; --mysql S ...
- MVC修改视图的默认路径
概述:之前MVC5和之前的版本中,我们要想对View文件的路径进行控制的话,则必须要对IViewEngine接口的FindPartialView或FindView方法进行重写,所有的视图引擎都继承于该 ...
- mysql处理时间戳
select name,telphone,FROM_UNIXTIME(add_time,'%Y-%m-%d %H:%i') as add_time from tf_apply_join order b ...
- SetParent
1.http://bbs.csdn.net/topics/390672855 该帖子中 第15楼: “ MSDN里面说了:if hWndNewParent is not NULL and the wi ...