hdu1272 java 穷举法
来源:互联网 发布:数据库实例 schema关系 编辑:程序博客网 时间:2024/05/19 19:59
import java.util.Scanner;
public class P1172 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while (sc.hasNext()) {
int n=sc.nextInt();
if(n==0){
return;
}
int a[]=new int[n+1];
int b[]=new int[n+1];
int c[]=new int[n+1];
for(int i=1;i<=n;i++){
a[i]=sc.nextInt();
b[i]=sc.nextInt();
c[i]=sc.nextInt();
}
int count=0;
int result = 0;
boolean flag = false;
for(int i=1000;i<=9999;i++){
for(int j=1;j<=n;j++){
flag=judge(i,a[j],b[j],c[j]);
if(!flag){
break;
}
}
if (flag) {
count++;
result = i;
}
}
if(count==1){
System.out.println(result);
}else{
System.out.println("Not sure");
}
}
}
private static boolean judge(int number, int a, int b, int c) {
int num1[]=new int[5];
int num2[]=new int[5];
boolean mark[]=new boolean[5];
for(int i=0;i<=4;i++){
mark[i]=false;
}
num1[1]=number/1000;
num1[2]=(number/100)%10;
num1[3]=(number/10)%10;
num1[4]=(number%10);
num2[1]=a/1000;
num2[2]=(a/100)%10;
num2[3]=(a/10)%10;
num2[4]=(a%10);
int count=0;
for(int i=1;i<=4;i++){
if(num1[i]==num2[i]){
count++;
}
}
if(count!=c){
return false;
}
count=0;
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if(num1[i]==num2[j]&&!mark[j]){
mark[j]=true;
count++;
break;
}
}
}
if(count!=b){
return false;
}
return true;
}
}
- hdu1272 java 穷举法
- java穷举法小案例
- hdu1272
- hdu1272
- hdu1272
- hdu1272
- hdu1272
- HDU1272
- hdu1272
- hdu1272
- HDU1272
- hdu1272
- HDU1272
- hdu1272
- hdu1272
- hdu1272
- hdu1272
- HDU1272
- macOS 下完全卸载 Android Studio
- Java HashSet源码解析
- 嵌入式 CC2543 RF中断详解
- 百度地图zhang
- github常见操作和常见错误!错误提示:fatal: remote origin already exists.
- hdu1272 java 穷举法
- Android源代码编译
- poj 1845 Sumdiv(同余模公式)
- eval 捕获dbi错误
- Windows平台 破解starUML
- formatter
- Android Studio 使用技巧总结
- xUtils3下载图片
- Android标题透明沉浸式UI