当前位置:网站首页>Number of briquettes & Birthday Candles & building blocks
Number of briquettes & Birthday Candles & building blocks
2022-07-26 08:30:00 【StephenYYYou】
Number of coal balls
2016 The difficulty of the year title is obviously higher than 2017 It's much simpler in .
package lanqiao.lanqiao_2016;
/**
* Created by ministrong on 2020/3/4.
*
*
Number of coal balls
There's a bunch of coal balls , Pile up in a triangular pyramid . Specifically :
On the first floor 1 individual ,
The second floor 3 individual ( In a triangle ),
The third level 6 individual ( In a triangle ),
The fourth level 10 individual ( In a triangle ),
....
If there is 100 layer , How many coal balls are there ?
Please fill in the number of coal balls .
Be careful : You should submit an integer , Don't fill in any extra content or explanatory text .
answer :171700
*/
public class Q1_2016_7_meiqiu {
public static void main(String[] args) {
int res=0;// in total
int t=0;// Each layer
for(int i=1;i<101;i++){
t=t+i;
res+=t;
}
System.out.println(res);
}
}
birthday candle
package lanqiao.lanqiao_2016;
/**
* Created by ministrong on 2020/3/4.
*
*
birthday candle
From a certain year on, you hold a birthday every year party, And blow out the same number of candles with the same age every time .
Now count , He blew it out altogether 236 A candle .
Excuse me, , How old was his birthday party Of ?
Please fill in his birthday party The age of .
Be careful : You should submit an integer , Don't fill in any extra content or explanatory text .
answer :26
*/
public class Q2_2016_7_shengri {
public static void main(String[] args) {
for(int i=1;i<200;i++){
int res=0;
for(int j=i;j<200;j++){
res+=j;
if(res==236) System.out.println(i);
}
}
}
}
Building blocks
package lanqiao.lanqiao_2016;
/**
* Created by ministrong on 2020/3/4.
*
Building blocks
Xiao Ming likes to build digital blocks recently ,
Altogether 10 A building block , There's a number on each block ,0~9.
Building block rules :
Each block is placed on top of the other two blocks , And it must be smaller than the two building block numbers below .
Finally, it was built into 4 The pyramid of layers , All the building blocks have to be used up .
Here are two qualified methods :
0
1 2
3 4 5
6 7 8 9
0
3 1
7 5 2
9 8 6 4
Please calculate the total number of such methods ?
Please fill in the number indicating the total number .
Be careful : You should submit an integer , Don't fill in any extra content or explanatory text .
answer :768
*/
import java.lang.reflect.Array;
import java.util.Arrays;
/***
* Yes 1~9 Full Permutation , requirement ,a[0]<a[2] and a[3],a[1]<a[3] and a[4],a[2]<a[5] and a[6],a[3]<a[6] and a[7],a[4]<a[7] and a[8]
*/
public class Q3_2016_7_jimu {
public static int[] a=new int[]{1,2,3,4,5,6,7,8,9};
public static void main(String[] args) {
int res=0;
do{
if(isok(a)) res++;
}while(nextque());
System.out.println(res);
}
public static boolean isok(int[] a){
return a[0]<a[2] && a[0]<a[3] && a[1]<a[3] && a[1]<a[4] && a[2]<a[5] && a[2]<a[6] && a[3]<a[6] && a[3]<a[7] && a[4]<a[7] && a[4]<a[8];
}
public static boolean nextque(){
int x=-1;
for(int i=8;i>0;i--){
if(a[i]>a[i-1]){
x=i-1;
break;
}
}
if(x==-1) return false;
int y=-1;
for(int i=8;i>x;i--){
if(a[i]>a[x]){
y=i;
break;
}
}
int t=a[x];
a[x]=a[y];
a[y]=t;
Arrays.sort(a,x+1,a.length);
return true;
}
}
Lexicographic order for complete arrangement : With a[5]={35876} For example
1. Find the first decreasing adjacent number from right to left , Write down the subscript of the number on the left i: here 58 First decline , Record 5 The subscript of is i=1.
2. Find the first one from right to left a[i] Big numbers , Record its subscript j: here 6 It's the first one 5 Big , Record 6 The subscript j=4.
3. In exchange for a[i] and a[j] The number of , The sequence becomes :36875.
4. Then subscript i The following sequence is arranged from small to large , Get the results :36578.
ps: If the decreasing adjacent number is not found in the first step , It means that this arrangement is the last one .
边栏推荐
- 分享高压超低噪声LDO测试结果(High Voltage Ultra-low Noise LDO)
- Day 4 homework
- [GUI] swing package (window, pop-up window, label, panel, button, list, text box)
- The data read by Flink Oracle CDC is always null. Do you know
- 【时间复杂度空间复杂度】
- Error handling response: Error: Syntax error, unrecognized expression: .c-container /deep/ .c-contai
- Fluent custom popupmenubutton
- The second lesson is the construction of development environment
- Flutter text is left aligned with no blank space in the middle
- 正则表达式作业
猜你喜欢

The second lesson is the construction of development environment

22-07-16 personal training match 3 competition experience

Why reserve a capacitor station on the clock output?

SPSS用KMeans、两阶段聚类、RFM模型在P2P网络金融研究借款人、出款人行为规律数据

Kotlin function
![[time complexity, space complexity]](/img/f2/f82c7e0a6ab9f893023c2ddbac3431.png)
[time complexity, space complexity]

苹果强硬新规:用第三方支付也要抽成,开发者亏大了!

Let's talk about the three core issues of concurrent programming.
分享高压超低噪声LDO测试结果(High Voltage Ultra-low Noise LDO)

2022-7-9 personal qualifying 6 competition experience
随机推荐
JS tool function Encyclopedia
2022-024arts: Longest valid bracket
Kotlin function
Beauty naked chat for a while, naked chat over the crematorium!
BGP routing principle
Error handling response: Error: Syntax error, unrecognized expression: .c-container /deep/ .c-contai
vim跨行匹配搜索
22-07-16 personal training match 3 competition experience
import error: ‘Icon‘ is not exported from ‘antd‘. Import icon error
vscode国内的镜像服务器加速
2022 / 7 / 16 exam summary
Awk operation
Special lecture 2 dynamic planning learning experience (should be updated for a long time)
2022-024ARTS:最长有效括号
Redis进阶
Shell programming
23.5 event listeners of application events and listeners
2022-7-7 personal qualifying 4 competition experience
Flex three column layout
Take out brother is the biggest support in this society