当前位置:网站首页>Winter vacation homework & Stamp cutting
Winter vacation homework & Stamp cutting
2022-07-26 08:31:00 【StephenYYYou】
Winter homework
package lanqiao.lanqiao_2016;
/**
* Created by ministrong on 2020/3/5.
*
Winter homework
Now primary school mathematics is not so fun .
Look at this winter vacation assignment :
□ + □ = □
□ - □ = □
□ × □ = □
□ ÷ □ = □
( If it doesn't show up , You can see 【 chart 1.jpg】)
Each square represents 1~13 One of the numbers in , But don't repeat .
such as :
6 + 7 = 13
9 - 8 = 1
3 * 4 = 12
10 / 2 = 5
as well as :
7 + 6 = 13
9 - 8 = 1
3 * 4 = 12
10 / 2 = 5
Even if there are two solutions .( Add , The commutative law of multiplication is followed by different schemes )
How many solutions have you found ?
Please fill in the integer representing the number of schemes .
Be careful : You should submit an integer , Don't fill in any extra content or explanatory text .
answer :64
*/
import java.util.Arrays;
/***
* Or the problem of full arrangement ,1~13 Full Permutation
* Find out the match a【0】+a【1】=a【2】;a【3】-a【4】=a【5】,a【6】*a【7】=a【8】,a【9】/a【10】=a【11】
*/
public class Q6_2016_7_hanjia {
public static int[] a=new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13};
public static void main(String[] args) {
long t1=System.currentTimeMillis();
int res=0;
do{
if(a[0]+a[1]==a[2] && a[3]-a[4]==a[5] && a[6]*a[7]==a[8] && a[9]/a[10]==a[11]) res++;
}while(nextque());
System.out.println(res);
long t2=System.currentTimeMillis();
System.out.println(t2-t1);
}
public static boolean nextque(){
int x=-1;
for(int i=a.length-1;i>0;i--){
if(a[i]>a[i-1]){
x=i-1;
break;
}
}
if(x==-1) return false;
int y=-1;
for(int i=a.length-1;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;
}
}
13 It takes time to arrange all the numbers , About a minute and a half , Consider using pruning to optimize . But the Blue Bridge Cup is unnecessary , It's OK to calculate it within the examination time .
Cutting stamps
From left to right are figures 1、 chart 2、 chart 3.
package lanqiao.lanqiao_2016;
/**
* Created by ministrong on 2020/3/28.
*/
/***
*
Cutting stamps
Such as 【 chart 1.jpg】, Yes 12 Zhang Lian together 12 Zodiac Stamps .
Now you're going to cut it out 5 Zhang Lai , The requirements must be connected .
( Just connecting one corner doesn't make a connection )
such as ,【 chart 2.jpg】,【 chart 3.jpg】 in , The part shown in pink is a qualified cut .
Please calculate , How many different clipping methods are there .
Please fill in the integer representing the number of schemes .
Be careful : You should submit an integer , Don't fill in any extra content or explanatory text .
answer :116
*/
import java.util.Arrays;
/****
* The train of thought is : from 1~12 Middle selection 5 Number , Then see if they are connected
* As for how 12 choose 5, One idea is to use full permutation
* For arrays {0,0,0,0,0,0,0,1,1,1,1,1} Arrange them all ,1 The subscript of corresponds to the number selected each time
* In this way, all the options can be listed
* And then through dfs Verify whether it is connected
*/
public class Q7_2016_7_jianyoupiao {
public static int[] a=new int[]{0,0,0,0,0,0,0,1,1,1,1,1};
public static int num=0;
public static void main(String[] args) {
int res=0;
do{
if(isok()) res++;
}while(nextque());
System.out.println(res);
}
// Is it connected
public static boolean isok(){
boolean[][] t=new boolean[3][4];
int startx=0;
int starty=0;
for(int i=0;i<a.length;i++){
if(a[i]==1){
t[i/4][i%4]=true;
startx=i/4;
starty=i%4;
//System.out.println(i+1);
}
}
num=0;
return isconnect(t,startx,starty);
}
public static boolean isconnect(boolean[][] t,int x,int y){
if(x>=0 && x<3 && y>=0 && y<4 && t[x][y]) {
num++;
if(num==5) return true;
t[x][y]=false;
boolean l= isconnect(t,x+1,y)||isconnect(t,x-1,y)||isconnect(t,x,y+1)||isconnect(t,x,y-1);
//t[x][y]=true;
return l;
}
else return false;
}
// Find the next complete permutation .
public static boolean nextque(){
int x=-1;
for(int i=a.length-1;i>0;i--){
if(a[i]>a[i-1]){
x=i-1;
break;
}
}
if(x==-1) return false;
int y=-1;
for(int i=a.length-1;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;
}
}
边栏推荐
- NLP (natural language processing) natural language processing learning
- Shell programming
- 日常一记(11)--word公式输入任意矩阵
- [C language] programmer's basic skill method - "creation and destruction of function stack frames"
- Use of room database in kotlin
- 22-07-16 personal training match 3 competition experience
- Uninstallation of dual systems
- 23.5 event listeners of application events and listeners
- 请问现在flinkcdc支持sqlserver实例名方式连接吗?
- Summary of common skills
猜你喜欢
小蜜蜂吉他谱 高八度和低八度
Prefix infix suffix expression (written conversion)
Write common API tools swagger and redoc
Mycat2 sub database and sub table
2022-7-6 personal qualifying 3 competition experience
基础乐理 节奏联系题,很重要
Lesson 3: gcc compiler
苹果强硬新规:用第三方支付也要抽成,开发者亏大了!
Special lecture 2 dynamic planning learning experience (should be updated for a long time)
Grid segmentation
随机推荐
Take out brother is the biggest support in this society
基础乐理 节奏联系题,很重要
Lesson 3: gcc compiler
Flutter upgrade 2.10
vim跨行匹配搜索
Sed job
Shell第二天作业
2022 national vocational college skills competition "network security" competition question file upload penetration test answer flag
2022-7-8 personal qualifying 5 competition experience (supplementary)
Alphabetic string
The first ide overlord in the universe, replaced...
Use of room database in kotlin
2022/7/12 exam summary
[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)
23.2 customizing the banner control display hidden banner modify banner
Write common API tools swagger and redoc
How to safely delete a useless activity in Android studio
QT note 2
Function default parameters, arrow functions, and remaining parameters in ES6 - explanation
关于期刊论文所涉及的一些概念汇编+期刊查询方法