当前位置:网站首页>Blue Bridge Cup 31 day sprint Day8
Blue Bridge Cup 31 day sprint Day8
2022-04-22 05:56:00 【Tchaikovsky】
Blue Bridge Cup 31 Sky sprint Day8
Magic formula
link : Magic formula .

The idea is simple , It's just a combination of different numbers that list all the digits (4 individual for loop ), Then use the hash table to check each number of the duplicate result , Re statistics
But I stepped on the pit , Special attention : The number beginning with cannot be 0!!!
Code :
public class Magic formula {
public static void main(String[] args) {
// TODO Auto-generated method stub
int count1 = 0;
int count2=0;
int n=0;
// All four numbers are different (i The number that starts with cannot be 0)
for(int i =1;i<=9;i++) {
for(int j =0;j<=9;j++) {
if(j==i)
j++;
if(j>9)
break;
for(int k =0;k<=9;k++) {
while(k==i||k==j)
k++;
if(k>9)
break;
for(int t =0;t<=9;t++) {
while(t==i||t==j||t==k)
t++;
if(t>9)
break;
//1 digit *3 digit
if(j!=0) {
n=i*(100*j+10*k+t);
if(n>1000&&n<9999&&isDifferent(n,i,j,k,t))
count1++;
}
//2 digit *2 digit
if(k!=0) {
n = (i*10+j)*(k*10+t);
if(n>1000&&n<9999&&isDifferent(n,i,j,k,t))
count2++;
}
}
}
}
}
//count2 except 2 It's for weight removal
System.out.println(count1+count2/2);
}
public static boolean isDifferent(int n,int i ,int j,int k,int t) {
int[] hash = new int[10];
hash[n/1000]++;
hash[n%1000/100]++;
hash[n%100/10]++;
hash[n%10]++;
if(hash[i]==1&&hash[j]==1&&hash[k]==1&&hash[t]==1)
return true;
return false;
}
}
Contraction summation
link : Contraction summation .


Because the input will not exceed 1000 position , Not more than 9999, It's safe to use int Calculation . Put... Directly String Turn into char Just calculate the array
Code :
import java.util.*;
public class Contraction summation {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
String s = sc.nextLine();
int n=0;
for(char c : s.toCharArray()) {
n+=c-'0';
}
while(n>=10) {
int num=0;
char[] chars =Integer.toString(n).toCharArray();
for(int i=0;i<chars.length;i++) {
num+=chars[i]-'0';
}
n=num;
}
System.out.println(Integer.toString(n));
}
}
}
Building blocks competition
link : Building blocks competition .

版权声明
本文为[Tchaikovsky]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220537235955.html
边栏推荐
- 蓝桥杯31天冲刺 Day16
- 05-变量及标识符
- Two ways of JS array value
- 卷积神经网络
- Layer closes the pop-up window and refreshes the parent page
- Raspberry pie 4B SSH connection refused
- Explanation of "write a byte to the output stream. The bytes to be written are the eight low bits of parameter B. the 24 high bits of B will be ignored"
- Complete knapsack problem
- Introduction to machine learning -- comparison and fancy indexing in numpy
- Machine learning -- drawing P-R curve and ROC curve with iris data set
猜你喜欢

蓝桥杯冲刺——二进制枚举

C语言--经典100题

LeetCode 2044. Count the number of subsets that can get the maximum value by bit -- depth traversal

Explanation of "write a byte to the output stream. The bytes to be written are the eight low bits of parameter B. the 24 high bits of B will be ignored"

Leetcode interview question 17.09 Number k -- dynamic programming

蓝桥杯31天冲刺 Day17

What compiler is used for beginners of C language (there is a surprise at the end of the article)

LeetCode 面试题 17.09. 第 k 个数--动态规划

Code analysis of STL alloc space allocator

蓝桥杯冲刺——并查集
随机推荐
《最优化理论》:运输问题(一)求最小运费【西北角法、最小元素法、伏格尔法】
golang学习和校招经历
10 - 流程控制-while循环语句
Simple DP questions - cow breeding and super stair climbing
蓝桥杯31天冲刺 Day17
整数拆分问题(动态规划+递归&记录数组)
LeetCode 2044. Count the number of subsets that can get the maximum value by bit -- depth traversal
Pseudo code block writing (for paper writing)
蓝桥杯31天冲刺 Day4
2021 408 changes in postgraduate entrance examination outline
Dynamically create array (c6385 reading invalid data from 'a')
08 - 程序的输入和输出
ShardingException: Cannot find data source in sharding rule, invalid actual data node is
Leetcode 486 Predicting Winners -- dynamic programming + game theory
Layer closes the pop-up window and refreshes the parent page
Judge whether the linked list has a ring (Set & speed pointer)
scikit-learn中的PCA
LeetCode 2055. Plates between candles -- prefix and + interval mark
TCGA下载GBM患者的RNA-seq数据
CONDA command