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的更多相关文章

  1. POJ2965The Pilots Brothers' refrigerator(枚举+DFS)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22057 ...

  2. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  3. The Pilots Brothers' refrigerator(dfs)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19718 ...

  4. 枚举 POJ 2965 The Pilots Brothers' refrigerator

    题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...

  5. 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 ...

  6. The Pilots Brothers' refrigerator

    2965 he Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1 ...

  7. POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16868 ...

  8. POJ2965——The Pilots Brothers' refrigerator

    The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: following the stripy el ...

  9. POJ 2965 The Pilots Brothers' refrigerator 位运算枚举

      The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 151 ...

随机推荐

  1. USB接口介绍

        USB设备系统分为两个部分,USB Host端和USB Device端,以USB接口的U盘为例子,U盘自身是一个USB Device,PC机的USB接口以及相关的控制电路为USB Host部分 ...

  2. App性能提升方法

    总体思路:精简请求数 1.css sprit 图像拼合,将所有可拼接的所有图像拼接为一整张图像,然后再利用css中的position定位来处理,降低图片的请求数 2.懒加载:只渲染客户端用户可见区域[ ...

  3. 2.servlet 生命周期

    1.建Web project“2Servlet_Basic” 2.建包com.amaker.servlet 3.建类“ServletBasic.java” package com.amaker.ser ...

  4. Java抽象类和抽象方法例子

    题目:定义Shape类表示一般二维图形.Shape具有抽象方法area和perimeter,分别计算形状的面积和周长.试定义一些二维形状类(如矩形.三角形.圆形等),这些均为Shape类的子类并计算出 ...

  5. gulp插件

    gulp是趋势 gulp完全开发指南 => 快来换掉你的Grunt吧 gulp的工作流程:文件流--文件流--文件流......因为grunt操作会创建临时文件,会有频繁的IO操作,而gulp使 ...

  6. 版本控制器 (Svn,Git)

    Svn: 集中式版本控制器,首先开发者在开始新一天的工作之前必须从服务器获取代码,然后进入自己的分支开发,开发完成后把自己的分支合并到主分支上进行提交,解决冲突.所有的版本信息都放在服务器上.如果脱离 ...

  7. postgresql 开启远程访问

    1.如果服务器启用了防火墙,需要在防火墙上开启 5432 端口. 2.修改 PostgreSQL 配置文件 postgresql.conf.postgresql.conf,Linux 配置文件所在路径 ...

  8. wpf MVVM ViewModel 关闭View显示

    上次说到了不同wpf窗体之间的交互,这个在MVVM模式之中用起来会方便很多 下面我来说下在ViewModel中关闭View的方法,其实也很简单的,注释照样不写,一看就懂的 public partial ...

  9. 使用Azure portal Create Virtual Machine

    使用简单快速的方式穿件的Virtual Machine 这个步骤隐藏的了很多步骤,例如的创建的云服务(Cloud Service) 创建存储(Storage) 存储名为系统自动产生 可以通过存储看到含 ...

  10. uImage、zImage、bzImage、vlinzx区别

    在网络中,不少服务器采用的是Linux系统.为了进一步提高服务器的性能,可能需要根 据特定的硬件及需求重新编译Linux内核.编译Linux 内核,需要根据规定的步骤进行,编译内核过程中涉及到几个重要 ...