POJ-2965 The Pilots Brothers' refrigerator【模拟法】
来源:互联网 发布:seo网站分析案例 编辑:程序博客网 时间:2024/05/24 04:26
1.思路分析
根据题目所说每次翻动同行同列,发现当你将同行同列的所有格子按照要求都做一遍后,其他的格子不变,只有作为基点的格子改变了。然后根据这个结论,还有翻动两次等于没有翻动的结论就可以解决了。
2.方法设计及性能衡量
每当记录到+时,将记录次数的数组同行同列的所有格子加1,然后该格子减一,最后扫描棋盘,如果为奇数则代表需要翻转。
3.实现部分
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>char temp[5][5],t[4][4]; void fun(int a1,int a2){ int i; for(i=0;i<4;i++){ t[a1][i]++; t[i][a2]++; } t[a1][a2]--;}int main(){ int i,j=0,count=0; for(i=0;i<4;i++){ scanf("%s",temp[i]); for(j=0;j<4;j++) if(temp[i][j]=='+')fun(i,j); } for(i=0;i<4;i++){ for(j=0;j<4;j++){ if(t[i][j]%2!=0) count++; } } printf("%d\n",count); for(i=0;i<4;i++){ for(j=0;j<4;j++){ if(t[i][j]%2!=0) printf("%d %d\n",i+1,j+1); } } return 0;}
阅读全文
0 0
- POJ-2965 The Pilots Brothers' refrigerator【模拟法】
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- poj 2965The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator 枚举
- POJ-2965-The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- POJ-2965-The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965:The Pilots Brothers' refrigerator
- Poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator(枚举)
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator 枚举
- 点击按钮对数据进行操作(2)
- JSP交互---EL表达式
- UVa11729
- 无线轮播图+触摸事件+地下小圆点
- php redis秒杀
- POJ-2965 The Pilots Brothers' refrigerator【模拟法】
- 一个项目中遇到bug
- MySQL自动备份及灾难恢复
- 关于%f与%lf
- AngularJS服务$http,$interval,$timeout
- sniff
- 用$http的方法请求json数据(angularjs)附加时间间隔和时间等待
- Reverse Integer--LeetCode
- 我的第一篇博客