POJ2965The Pilots Brothers' refrigerator
http://poj.org/problem?id=2965
这个题的话,一开始也不会做,旁边的人说用BFS,后来去网上看了众大神的思路,瞬间觉得用BFS挺简单易;因为要让一个“+”变为“-”,只要将加号所在的位置(i,j)的行和列上的7个元素全部改变一次,这样的话(i,j)这个点将会变化7次,而 i 行上和 j 列另外六个元素将会变化4次,剩下的那些会变化2次,显而易见的是,一个位置上若翻转偶数次相当于没翻转,所以,只要记录下奇数次的翻转进行相加就可以了。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
using namespace std ;
char ans[][];
int flag[][];
int main()
{
memset(flag,,sizeof(flag));
for(int i = ; i <= ; i++)
{
scanf("%s",ans[i]);//这个题输入的时候我用的两个for循环输入数组里,但是错了。。
}
for(int i = ; i <= ; i++)
{
for(int j = ; j <= ; j++)
{
//scanf("%c",&ans) ;
if(ans[i][j] == '+')
{
for(int k = ; k <= ; k++)
{
//加号所在的位置行列的翻转次数全加一。
flag[i][k]++ ;
flag[k][j]++ ;
}
flag[i][j]-- ;//上边两次多加了一次这个,所以在这里减1 ;
}
}
}
int sum = ;
for(int i = ; i <= ; i++)
{
for(int j = ; j <= ; j++)
{
sum += flag[i][j]% ;//遍历整个数组,凡是为奇数次的位置之和即为总的操作次数
}
}
printf("%d\n",sum) ;
for(int i = ; i <= ; i++)
{
for(int j = ; j <= ; j++)
{
if(flag[i][j]% == )
{
cout<<i+<<' '<<j+<<endl ;
}
}
}
return ;
}
POJ2965The Pilots Brothers' refrigerator的更多相关文章
- POJ2965The Pilots Brothers' refrigerator(枚举+DFS)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22057 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- The Pilots Brothers' refrigerator(dfs)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19718 ...
- 枚举 POJ 2965 The Pilots Brothers' refrigerator
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- The Pilots Brothers' refrigerator 分类: POJ 2015-06-15 19:34 12人阅读 评论(0) 收藏
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20304 ...
- The Pilots Brothers' refrigerator
2965 he Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
- POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16868 ...
- POJ2965——The Pilots Brothers' refrigerator
The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: following the stripy el ...
- POJ 2965 The Pilots Brothers' refrigerator 位运算枚举
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 151 ...
随机推荐
- c++ string 拼接 int错误
程序中用到字符串和int合成字符串,受java习惯的影响,直接进行了字符串与int的+操作,结果不正确.查了一下才明白问题所在,记录一下string str=”abc”+1;输出为:bc,因为”abc ...
- IEEE Floating Point Standard (IEEE754浮点数表示法标准)
浮点数与定点数表示法是我们在计算机中常用的表示方法 所以必须要弄懂原理,特别是在FPGA里面,由于FPGA不能像在MCU一样直接用乘除法. 定点数 首先说一下简单的定点数,定点数是克服整数表示法不能表 ...
- ExtJS实战 01——HelloWorld
前言 Extjs5的发布已经有些日子了,目前的最新稳定版本是Extjs5.1.0,我们可以在官方网站进行下载.不过笔者今天访问得到的是502Bad Gateway,原因可能是sencha的nigix没 ...
- 支持IE6的树形节结构TreeTable
关于TreeTable实际应用的案例:http://www.cnblogs.com/qigege/p/5213689.html treeTable是跨浏览器.性能很高的jquery的树表组件,它使用非 ...
- CentOS 7 yum nginx MySQL PHP 简易环境搭建
用centos自带的yum源来安装nginx,mysql和php,超级方便,省去编译的麻烦,省去自己配置的麻烦,还能节省非常多的时间. 我们先把yum源换成国内的阿里云镜像源(当然不换也可以),先备份 ...
- 51nod贪心算法入门-----完美字符串
约翰认为字符串的完美度等于它里面所有字母的完美度之和.每个字母的完美度可以由你来分配,不同字母的完美度不同,分别对应一个1-26之间的整数. 约翰不在乎字母大小写.(也就是说字母F和f)的完美度相同. ...
- (转)android底部弹出iOS7风格对话选项框(QQ对话框)--第三方开源--IOS_Dialog_Library
本文转载于:http://blog.csdn.net/zhangphil/article/details/44940339 完成这个效果的是使用了 IOS_Dialog_Library 下载地址:ht ...
- Eclipse 下 opennms 开发环境搭建
1.eclipse3.5或更高版本,并且使用纯净的java版.下载地址:Eclipse for Java Developers. 2.安装需要的插件.通过Help/Install New Softwa ...
- Visual Studio
1.必备神器http://www.cnblogs.com/stoneniqiu/p/3488546.html 2.常用快捷键http://www.cnblogs.com/TankXiao/p/3468 ...
- mysql 查询
查询数据:select s_name from student limit 1;//限制数量 select * from student where s_id in (select s_id from ...