• 1221. Malevich Strikes Back! 夜


    递推水题

    import java.util.*;
    import java.math.*;
    
    public class Main {
    
    	public static void main(String[] args) {
    		int n;
    		Scanner in = new Scanner(System.in);
    		while (in.hasNext()) {
    			n = in.nextInt();
    			if (n == 0) {
    				break;
    			}
    			int num0[][] = new int[n + 1][n + 1];//图形从上向下 此列连续的 0 的个数
    			int num1[][] = new int[n + 1][n + 1];//图形从上到下 此列所有的 1 的个数
    			int a[][] = new int[n + 1][n + 1];
    			for (int i = 1; i <= n; ++i) {
    				for (int j = 1; j <= n; ++j) {
    					a[i][j] = in.nextInt();
    				}
    			}
    			for (int j = 1; j <= n; ++j) {
    				num0[0][j] = num1[0][j] = 0;
    			}
    			for (int i = 1; i <= n; ++i) {
    				for (int j = 1; j <= n; ++j) {
    					if (a[i][j] == 0) {
    						num1[i][j] = num1[i - 1][j];
    						num0[i][j] = num0[i - 1][j] + 1;
    					} else {
    						num1[i][j] = num1[i - 1][j] + 1;
    						num0[i][j] = 0;
    					}
    
    				}
    			}
    			int ans = -1;
    			for (int i = 1; i <= n; ++i) {
    				for (int j = 1; j <= n; ++j) {
    					int temp = num0[i][j];
    					if (temp > 1 && temp % 2 == 1) {
    						if (j + temp / 2 > n || j - temp / 2 < 1) {
    							continue;
    						}
    						// System.out.println(i+" "+j+" "+temp);
    						boolean yes = true;
    						int pre = temp;
    						for (int k = 1; k <= temp / 2; ++k) {
    							// System.out.println(pre);
    							if (!(num0[i - k][j + k] + 2 == pre && num1[i][j
    									+ k]
    									- num1[i - temp][j + k] == temp
    									- num0[i - k][j + k])) {
    								yes = false;
    								// System.out.println(k);
    								// System.out.println((num0[i-k][j+k])+" "+pre);
    							}
    							if (!(num0[i - k][j - k] + 2 == pre && num1[i][j
    									- k]
    									- num1[i - temp][j - k] == temp
    									- num0[i - k][j - k])) {
    								yes = false;
    							}
    							pre = pre - 2;
    						}
    						if (yes == true && temp > ans) {
    							ans = temp;
    						}
    
    					}
    				}
    			}
    			if (ans == -1) {
    				System.out.println("No solution");
    			} else {
    				System.out.println(ans);
    			}
    
    		}
    	}
    
    }
    
  • 相关阅读:
    View Documentation in Web Using [openoffice.org 3+swftools+flexpaper]
    swfobject.js
    Java 文件上传组件 Apache Commons FileUpload 应用指南
    模拟HTML表单上传文件(RFC 1867)
    Using CURL to download a remote file from a valid URL in c++
    GUN tar for windows Practice
    Using libcurl in VC++
    Zlib Practice
    解决HtmlAgilityPack中文乱码
    Windows 7,Windows Server 2008 MSDTC配置
  • 原文地址:https://www.cnblogs.com/liulangye/p/2705057.html
Copyright © 2020-2023  润新知