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 ...
随机推荐
- 关于MD5加密的小知识
- (NSString *)MD5Hash { const char *cStr = [self UTF8String]; unsigned char result[16]; CC_MD5(cStr, ...
- uniform 中checkbox通过jquery 选中
你是否曾经为不能修改多选框.单选框.文件选择框的样式而郁闷呢,是否想过控制它们的样式且兼容所有浏览器呢?我现在给你推荐的这个jQuery表单美化插件Uniform就可以解决这些问题. Uniform可 ...
- Entity Framework 并发处理借鉴
如下博客 http://www.cnblogs.com/Bce-/p/3725868.html
- 【原】使用ajax的get异常获取数据的时候,IE浏览器总是有缓存
//HTML里有下面这样一段代码 //异步获取准备人信息 $.get("PrepSetpNew/PrepareMainCrew.ashx?Method=GetPrepUserInfo&quo ...
- 安装配置 redis
1. cd /usr/ley/softwares 2. wget http://download.redis.io/redis-stable.tar.gz 3. tar –xzf redis- ...
- string和json转换的简单应用
import com.alibaba.fastjson.JSON; String strjson = request.getParameter("param"); //url-js ...
- CentOS 普通用户设置sudo权限
1.先切换到root用户下,输入命令 su 2.添加sudo文件的写权限,命令是: chmod u+w /etc/sudoers 3.编辑sudoers文件 vi /etc/sudoers 找到 ro ...
- JS遇到的问题解决
1.input 里使用onclick事件,整整花了1个半小时,onclick里面直接用Location.href不需要加<script></script> <?php / ...
- 动画气泡指示当前滑动值--第三方开源--DiscreteSeekbar
DiscreteSeekbar在github上的项目主页是:https://github.com/AnderWeb/discreteSeekBar DiscreteSeekbar可以自定制的属性很多, ...
- WPF自定义控件(二)——TextBox
和之前一样,先来看看效果: 这个TextBox可设置水印,可设置必填和正则表达式验证. 验证?没错,就是验证! 就是在输入完成后,控件一旦失去焦点就会自动验证!会根据我开放出来的“是否可以为空”属性进 ...