zoukankan      html  css  js  c++  java
  • Java实现 洛谷 P1618 三连击(升级版)

    在这里插入图片描述

    import java.util.Arrays;
    import java.util.Scanner;
     
    public class Main {
    	private static Scanner cin;
    	private static boolean hasFound = false; 
    	
    	public static void main(String args[]) throws Exception {
    		cin = new Scanner(System.in);
    		int A = cin.nextInt();
    		int B = cin.nextInt();
    		int C = cin.nextInt();
    		
    		for(int i = 123;i<=987;i++) {
    			if(i%A==0) {
    				if(String.valueOf(i).contains("0")) {
    					continue;
    				}
    				int j = i/A*B;
    				if(j<123 || j>987 || String.valueOf(j).contains("0")) {
    					continue;
    				}else {
    					int k = i/A*C;
    					if(k<123 || k>987 || String.valueOf(k).contains("0")) {
    						continue;
    					}else {
    						checkDigit(i,j,k);
    					}
    				}
    			}
    		}
    		if(!hasFound) {
    			System.out.println("No!!!");
    		}
    				
    	}
    	
    	//check if i,j,k has different digits from 1 to 9
    	public static void checkDigit(int i,int j,int k) {
    		int[] digits = new int[9];
    		Arrays.fill(digits, 0);
    		int a = i/100;
    		int b = (i-a*100)/10;
    		int c = (i-a*100 - b*10);
    		if(a == b || b== c || a==c) {
    			return;
    		}
    		if(digits[a-1] ==1 || digits[b-1] == 1 || digits[c-1] == 1) {
    			return;
    		}else {
    			digits[a-1] = 1;
    			digits[b-1] = 1;
    			digits[c-1] = 1;
    			a = j/100;
    			b = (j-a*100)/10;
    			c = (j-a*100 - b*10);
    			if(a == b || b== c || a==c) {
    				return;
    			}
    			if(digits[a-1] ==1 || digits[b-1] == 1 || digits[c-1] == 1) {
    				return;
    			}else {
    				digits[a-1] = 1;
    				digits[b-1] = 1;
    				digits[c-1] = 1;
    				a = k/100;
    				b = (k-a*100)/10;
    				c = (k-a*100 - b*10);
    				if(a == b || b== c || a==c) {
    					return;
    				}
    				if(digits[a-1] ==1 || digits[b-1] == 1 || digits[c-1] == 1) {
    					return;
    				}else {
    					System.out.println(String.format("%d %d %d", i,j,k));
    					if(!hasFound) {
    						hasFound = true;
    					}
    				}
    			}
    		}
    	}
    }
    
  • 相关阅读:
    18.9.22 noip模拟赛
    POJ 2299 Ultra-QuickSort
    美团2018年CodeM大赛-初赛B轮 B 配送(最短路)
    Wannafly挑战赛18 E 极差(线段树、单调栈)
    Foj 2299 Prefix(AC自动机、DP)
    求独立矩形个数
    Zoj 3777 Problem Arrangement
    Luogu 2444 [POI2000]病毒 & Zoj 3784
    [ZJOI2007]Hide 捉迷藏
    双联通分量学习笔记
  • 原文地址:https://www.cnblogs.com/a1439775520/p/12947121.html
Copyright © 2011-2022 走看看