poj2965枚举
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 20398 | Accepted: 7857 | Special Judge |
Description
The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a refrigerator.
There are 16 handles on the refrigerator door. Every handle can be in one of two states: open or closed. The refrigerator is open only when all handles are open. The handles are represented as a matrix 4х4. You can change the state of a handle in any location [i, j] (1 ≤ i, j ≤ 4). However, this also changes states of all handles in row i and all handles in column j.
The task is to determine the minimum number of handle switching necessary to open the refrigerator.
Input
The input contains four lines. Each of the four lines contains four characters describing the initial state of appropriate handles. A symbol “+” means that the handle is in closed state, whereas the symbol “−” means “open”. At least one of the handles is initially closed.
Output
The first line of the input contains N – the minimum number of switching. The rest N lines describe switching sequence. Each of the lines contains a row number and a column number of the matrix separated by one or more spaces. If there are several solutions, you may give any one of them.
Sample Input
-+--
----
----
-+--
Sample Output
6
1 1
1 3
1 4
4 1
4 3
4 4
Source
本题主要是当需要改变某个+为-时,需要将他所在的行与所在的列都需要反转一次,如果反转两次相当与没反,所以每一反转的情况便可以的
最后判断%2时候的情况,==1便是需要反转的,否则不需要反转
‘#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int temp[4][4],ans[4][4];
char a[4][4];
int main(){
memset(temp,0,sizeof(temp));
memset(a,0,sizeof(a));
memset(ans,0,sizeof(ans));
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
scanf("%c",&a[i][j]);
if(a[i][j]=='+')
temp[i][j]=1;
else
temp[i][j]=0;
}
getchar();
}
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(temp[i][j]==1){
for(int k=0;k<4;k++){
ans[i][k]+=1;
ans[k][j]+=1;
}
ans[i][j]-=1;
}
}
}
int x[16],y[16];
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
int count=0;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(ans[i][j]%2==1){
x[count]=i;
y[count]=j;
count++;
}
}
}
cout<<count<<endl;
for(int i=0;i<count;i++){
cout<<x[i]+1<<" "<<y[i]+1<<endl;
}
return 0;
}
poj2965枚举的更多相关文章
- 假期训练八(poj-2965递归+枚举,hdu-2149,poj-2368巴什博奕)
题目一(poj-2965):传送门 思路:递归+枚举,遍历每一种情况,然后找出最小步骤的结果,与poj-1753类似. #include<iostream> #include<cst ...
- poj2965 The Pilots Brothers' refrigerator(直接计算或枚举Enum+dfs)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://poj.org/problem? id=2965 ---- ...
- dfs+枚举,flip游戏的拓展POJ2965
POJ 2965 The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: fo ...
- poj2965 【枚举】
The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to op ...
- POJ-2965 The Pilots Brothers' refrigerator---思维题
题目链接: https://vjudge.net/problem/POJ-2965 题目大意: 一个冰箱上有4*4共16个开关,改变任意一个开关的状态(即开变成关,关变成开)时,此开关的同一行.同一列 ...
- poj2965 The Pilots Brothers' refrigerator —— 技巧性
题目链接:http://poj.org/problem?id=2965 题解:自己想到的方法是枚举搜索,结果用bfs和dfs写都超时了.网上拿别人的代码试一下只是刚好不超时的,如果自己的代码在某些方面 ...
- Swift enum(枚举)使用范例
//: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...
- 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)
建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...
- Objective-C枚举的几种定义方式与使用
假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...
随机推荐
- Objective-C Runtime(转)
博主地址: http://yulingtianxia.com/blog/2014/11/05/objective-c-runtime/ 曾经觉得Objc特别方便上手,面对着 Cocoa 中大量 API ...
- linux oracle磁盘满了
最近,查看我们一台linux服务器,发现硬盘空间都已经使用了95%,很是疑惑啊,怎么回事那?难道是数据库文件太大了? Filesystem Size Used Avail Us ...
- ”耐撕“团队 2016.3.21 站立会议3 2 1 GO!
”耐撕“团队 2016.3.21 站立会议 时间:2016.3.21 ① 17:20-17:45 ②17:55-18:10 总计40分钟 成员: Z 郑蕊 * 组长 (博客:http://www ...
- new-nav-js
'use strict';define([ 'jquery'], function($) { var nav = { init : function() { $("#burger-menu& ...
- winform之权限判断小技巧
每个页面都要判断用户是否登陆并且判断用户是否拥有相应的权限,,以至于每个页面都要判断Session["user"]是否为空,后期不好维护 小技巧: 因为每个页面都继承与Page类, ...
- 【HDU 2222】Keywords Search AC自动机模板题
参考iwtwiioi的模板写出来的.上午gty讲的并没有听懂,只好自己慢慢对着模板理解. 在HDU上为什么相同的程序提交有时T有时A!!! 奉上sth神犇的模板(不是这道题): var ch:char ...
- Html-Css-li标签增加图片
制作一个需要显示颜色的圆点. <style> .item1 ul{list-style:none} .item1 li{padding-left:20px;background:url(圆 ...
- Session解析
1.除非关闭所有页面 或者超时session才销毁 2.在几个页面之间切换的时候 session保存用户状态. 3.遍历数组时候for循环中从0开始小于长度,不等于长度,用Matlab用习惯了,竟然从 ...
- 界面原型Axure
页面原型工具 Axure 超实用页面原型工具.好的页面原型是项目组成员顺利沟通的一个非常重要因素,Axure能快速制作页面原型,还能界面手动式加上事件,链接跳转,弹出层等等一切HTML开发中常用功能, ...
- wifi共享小工具
MainForm.cs: using System;using System.Collections.Generic;using System.ComponentModel;using System. ...