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 ...
随机推荐
- MDX : Non Empty v/s NonEmpty
MDX : Non Empty v/s NonEmpty User Rating: / 50 PoorBest Written by Jason Thomas Friday, 07 May 20 ...
- protobuf编译报错
在下载protobuf进行编译的时候会出现如图所示的错误 修改 C:\protobuf-2.4.1\gtest\include\gtest\internal\gtest-tuple.h(C:是我解压p ...
- JQ 选择器大全
一.基本选择器 选择器 描 述 返回 示例 #id 根据给定id匹配一个元素 单个元素 $("#test") 选取id为test的元素 .class 根据给定类名匹配一个元素 集合 ...
- linux lsof命令的使用
lsof(list open files)是一个列出当前系统打开文件的工具.在UNIX环境下,任何事物都是以文件的形式存在的,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件. 像传输协议(T ...
- windows不能在本地计算机启动apache
今天,配置eclipse PHP studio 3.0的时候更改了apache http server 中的httpd.conf文件: 将DocumentRoot 的路径设错了,为一个不存在目录 .更 ...
- WCF完全解析读书笔记第2章地址
1. 使用同一个绑定对象实现地址跨终结点共享 2. 地址报头帮助辅助寻址 3. 使用端口共享为多个服务使用相同端口 4. WCF终结点地址分为逻辑地址和物理地址, 客户端使用ClientViaBeha ...
- SpringUtil
/** SpringUtil.java {{IS_NOTE Purpose: Description: History: Thu Jun 1 13:53:53 2006, Created by hen ...
- 每日一“酷”之textwrap
介绍:需要美观打印时,可以使用textwrap模块来格式化要输出的文本,这个模块允许通过编程提高类似段落自动换行或填充特性等功能. 1 创建实例数据 sample_text = ''' I’m ver ...
- raiserror的用法
描述:raiserror :是用于抛出一个错误 第一个参数:{ msg_id | msg_str | @local_variable } msg_id:表示可以是一个sys.messages表中定义的 ...
- linux驱动路径
1. 按键驱动 \drivers\input\keyboard\utu2440_buttons.c 2. LED驱动 \drivers\char\utu2440-led.c 3. DM9000网卡驱动 ...