POJ1222
来源:互联网 发布:python text 编辑:程序博客网 时间:2024/05/16 06:50
题目:http://acm.pku.edu.cn/JudgeOnline/problem?id=1222
- import java.util.Scanner;
- public class Main {
- int times;
- int[][] puzzle;
- static final int length = 6;
- static final int width = 5;
- int[][] arr;
- int temp;
- int req;
- public Main() {
- Scanner scan = new Scanner(System.in);
- times = scan.nextInt();
- for (int t = 0; t < times; t++) {
- puzzle = new int[width][length];
- arr = new int[width][length];
- for (int i = 0; i < width; i++) {
- for (int j = 0; j < length; j++) {
- puzzle[i][j] = scan.nextInt();
- }
- }
- force();
- System.out.println("PUZZLE #" + (t + 1));
- for (int i = 0; i < width; i++) {
- for (int j = 0; j < length; j++) {
- System.out.print(arr[i][j] + " ");
- }
- System.out.println();
- }
- }
- }
- //穷举第一行数据,推导下面的数据...
- //判断最后一行是否符合要求
- //6列需要最多计算2^6=64次
- public void force() {
- boolean result = false;
- do {
- result = search();
- if (result) {
- return;
- }
- } while (plus(arr[0], 0));
- }
- public boolean search() {
- for (int i = 1; i < width; i++) {
- for (int j = 0; j < length; j++) {
- req = puzzle[i - 1][j];
- temp = 0;
- if (j - 1 >= 0) {
- temp += arr[i - 1][j - 1];
- }
- if (j + 1 < length) {
- temp += arr[i - 1][j + 1];
- }
- if (i - 2 >= 0) {
- temp += arr[i - 2][j];
- }
- temp += arr[i - 1][j];
- if (req != (temp % 2)) {
- arr[i][j] = 1;
- } else {
- arr[i][j] = 0;
- }
- }
- }
- for (int i = 0; i < length; i++) {
- req = puzzle[width - 1][i];
- temp = 0;
- if (i - 1 >= 0) {
- temp += arr[width - 1][i - 1];
- }
- temp += arr[width - 2][i];
- temp += arr[width - 1][i];
- if (i + 1 < length) {
- temp += arr[width - 1][i + 1];
- }
- if (req != (temp % 2)) {
- return false;
- }
- }
- return true;
- }
- public boolean plus(int[] a, int b) {
- if (b == length) {
- return false;
- } else if (a[b] == 0) {
- a[b]++;
- return true;
- } else {
- a[b] = 0;
- return plus(a, ++b);
- }
- }
- public static void main(String[] args) {
- new Main();
- }
- }
- POJ1222
- poj1222
- poj1222
- POJ1222
- POJ1222
- poj1222
- POJ1222
- poj1222
- POJ1222(高斯消元)
- POJ1222高斯消元
- poj1222 高斯消元
- poj1222 高斯消元
- poj1222高斯消元基础题
- poj1222(暴力枚举)
- 反转问题--poj1222
- poj1222 枚举 和 高斯消元
- poj1222 EXTENDED LIGHTS OUT
- POJ1222 EXTENDED LIGHTS OUT
- 计算出你和另一个人的关系
- UI 例子程序
- 2008年第33届ACM/ICPC亚洲区预赛(哈尔滨)网络预选赛 1007__The Accomodation of Students 二分图最大匹配+染色
- 编程排版规范
- 'tasklist' 不是内部或外部命令
- POJ1222
- 暑假实习学习JSP笔记
- POJ1054
- 用好游标
- gnome-commander
- 命名规范
- 为不同版本JRE生成不同版本代码
- 在ORACLE的UCD设计--现在UCD越来越深入人心了
- UNIX一些基本知识