POJ 2965:The Pilots Brothers' refrigerator:棋盘题目2
2014-04-06 15:19
477 查看
The Pilots Brothers' refrigerator
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
Source
Northeastern Europe 2004, Western Subregion
关键还是充分理解行或者列翻转两次相当于不翻转~~然后就能得出其中的关系式,瞬间求解。
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 17342 | Accepted: 6557 | Special Judge |
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
Northeastern Europe 2004, Western Subregion
关键还是充分理解行或者列翻转两次相当于不翻转~~然后就能得出其中的关系式,瞬间求解。
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<string.h> int a[5][5],b[5][5],heng[5],shu[5],num; char t[5]; void init() { int i,j; int m,n; memset(heng,0,sizeof(heng)); memset(shu,0,sizeof(shu)); for(i=1;i<=4;i++) { scanf("%s",t); for(j=0;j<4;j++) { if(t[j]=='+') { a[i][j+1]=1; heng[i]=(heng[i]+1)%2; shu[j+1]=(shu[j+1]+1)%2; } else a[i][j+1]=0; } } num=0; } void print() { int i,j; printf("%d\n",num); for(i=1;i<=4;i++) for(j=1;j<=4;j++) if(b[i][j]) printf("%d %d\n",i,j); } int main() { int i,j; init(); for(i=1;i<=4;i++) { for(j=1;j<=4;j++) { b[i][j]=(a[i][j]+heng[i]+shu[j])%2; if(b[i][j]) num++; } } print(); return 0; }
相关文章推荐
- {A} + {B}
- 有很大的关系的网站关键词的排名和网站内容
- Tkprof
- win8.1配置java环境
- em配制
- win8.1配置java环境个人 win8.1
- VS的常用快捷键如下:
- POJ 3414
- POJ 3450 Corporate Identity(KMP:最长连续公共子序列)
- 移动应用测试中 模块测试开始的标准
- 抱歉
- Template /template/ajax/head.ftl not found.
- ZooKeeper源码阅读之Eclipse工程搭建
- UVA - 10300 - Ecological Premium
- The area
- struts2中action跳转到另一个action的方法
- httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。
- 设计模式之工厂设计模式(一:简单工厂模式与工厂方法模式)
- GCC编译器选项
- ViewPager向导demo