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. Fedora 19 vim c语言开发环境

    1. Fedora 19 居然没有自带 gcc 和 g++: sudo yum -y install gcc gcc-c++ 2. 安装 vim 和 cvim 插件: sudo yum -y vim ...

  2. Debug Intro

    The ABAP Debugger is used tool to execute and analyze programs line by line. Using it we can check t ...

  3. iOS程序的生命周期

    任何程序的生命周期都是指程序加载到程序结束这一段时间. 在iOS应用程序中,通过单击主页面上的图标的方式可以启动一个程序.单击后,系统会显示一个过渡界面,然后调用main()函数来加载程序.从这一刻开 ...

  4. Hbase 0.95.2介绍及下载地址

    HBase是一个分布式的.面向列的开源数据库,该技术来源于Google论文“Bigtable:一个结构化数据的分布式存储系统”.就像Bigtable利用了Google文件系统(File System) ...

  5. js实现雪花飘落效果的代码

    使用js实现雪花飘落的效果,用html5绘布加js写的雪花飘效果 . 代码: <html> <head> <script> /** * js与html5实现的雪花飘 ...

  6. python 数字、字符串、列表常用函数

    一.数字的标准类型: cmp():比较两个数的大小:返回值(-1,0,1). str():数字转化成字符串. type():返回数字类型. 转换工厂函数: int(obj,base=10) long( ...

  7. Android Studio笔记(2)——快捷键

    在朋友推荐下,上个星期黄老师我用上了Google的新黑暗工具,基于Intellij idea的新Android开发集成开发环境 ——Android Studio,用下来感觉还算不错,但作为一个ADT ...

  8. Microsoft Press Free eBook

    微软的免费的电子书, 都是Microsoft Press 出版的 有以下价格方面 Windows Server(大体上都是Windows Server 2012 ) Microsoft Azure(好 ...

  9. C# 实现Oracle中的数据与Excel之间的转换

    最近项目要求实现数据库之间数据在各个数据库之间导入导出,在此做个笔记 1. 将Oracle中的表导入到Excel中,反之亦然  private static readonly string conne ...

  10. spring中Bean的注入类型

    1.属性注入    即通过setXxx()方法注入Bean的属性值或依赖对象,由于属性注入方式具有可选择性和灵活性高的优点,因此属性注入是实际应用中最常采用的注入方式.    属性注入要求Bean提供 ...