蓝桥杯2017模拟赛-猜算式
2017-03-16 13:55
183 查看
直接爆了枚举下就好
//答案179 224 716 358 358 40096 public class Main2 { public static void main(String[] args) { for(int i = 100;i<=999;i++){ for(int j = 100;j<=999;j++){ int[] f = new int[10]; int a = i*(j%10); int b = i*(j/10%10); int c = i*(j/100); if(a>=1000||b>=1000||c>=1000||i*j>=100000||a<100||b<100||c<100)continue; //i,j,a,b,c,i*j if(check(i,f)&&check(j,f)&&check(a,f)&&check(b,f)&&check(c,f)&&check(i*j,f)){ System.out.println(i+" "+j+" "+a+" "+b+" "+c+" "+i*j); } } } } public static boolean check(int i,int[] f){ while(i>0){ if(f[i%10]==2){ return false; } f[i%10]++; i/=10; } return true; } }
因为有人要求写下C的,所以我就顺便贴出C的代码,方便查看
代码:
#include<stdio.h> #include<math.h> #include<stdlib.h> int check(int i,int * f){ while(i>0){ if(f[i%10]==2){ return 0; } f[i%10]++; i/=10; } return 1; } int main(){ for(int i = 100;i<=999;i++){ for(int j = 100;j<=999;j++){ int f[10] = {0}; int a = i*(j%10); int b = i*(j/10%10); int c = i*(j/100); if(a>=1000||b>=1000||c>=1000||i*j>=100000||a<100||b<100||c<100)continue; //i,j,a,b,c,i*j if(check(i,f)&&check(j,f)&&check(a,f)&&check(b,f)&&check(c,f)&&check(i*j,f)){ printf("%d %d %d %d %d %d",i,j,a,b,c,i*j); } } } return 0; }
相关文章推荐
- 蓝桥杯模拟赛:猜算式
- 蓝桥杯2017模拟赛-还款计算
- 2017蓝桥杯模拟赛-猜算式
- 蓝桥杯---2017模拟赛-高职高专组题目:猜算式
- 蓝桥杯模拟赛-猜算式
- 蓝桥杯2017模拟赛-风险度量
- 第八届蓝桥杯2017模拟赛 滑动解锁
- 蓝桥杯2017模拟赛-算年龄
- 2017蓝桥杯模拟赛 Problem B: 猜算式(11分)
- 蓝桥杯2017【模拟赛3】排列序数(康托展开式)
- 蓝桥杯2017模拟赛-排列序列
- 蓝桥杯2017模拟赛-滑动解锁
- 蓝桥杯2017模拟题-猜算式
- 蓝桥杯-2017模拟赛本科试题-猜算式-java
- 蓝桥杯2017官方模拟赛 还款计算(思路)
- 算法笔记_127:蓝桥杯2017模拟赛-本科组习题解答(Java)
- 蓝桥杯模拟赛 猜算式
- 2017年 蓝桥杯模拟赛,猜算式(纯暴力)
- 2017蓝桥模拟赛 猜算式
- 时空跳跃者的追捕行动模拟赛