当前位置:网站首页>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;
}
}

边栏推荐
- 有点牛逼,一个月13万+
- JS工具函数大全
- [GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)
- Fluent custom popupmenubutton
- Does flinkcdc now support sqlserver instance name connection?
- When developing flutter, idea_ ID cannot solve the problem
- Redis advanced
- 22-07-12 personal training match 1 competition experience
- QT note 2
- Kotlin variables and constants
猜你喜欢

关于期刊论文所涉及的一些概念汇编+期刊查询方法

Basic music theory rhythm connection problem, very important

Basic configuration of BGP

内存管理-动态分区分配方式模拟

Mysql/mariadb (Galera multi master mode) cluster construction

Date and time function of MySQL function summary

Nodejs2day(nodejs的模块化,npm下载包,模块加载机制)

为什么要在时钟输出上预留电容的工位?

BGP routing principle
![[time complexity, space complexity]](/img/f2/f82c7e0a6ab9f893023c2ddbac3431.png)
[time complexity, space complexity]
随机推荐
Why reserve a capacitor station on the clock output?
Sed job
On some concepts involved in journal papers compilation + journal query methods
QT note 2
If Yi Lijing spits about programmers
Flex three column layout
2022-7-9 personal qualifying 6 competition experience
【时间复杂度空间复杂度】
Bee guitar score high octave and low octave
[time complexity, space complexity]
2022/7/11 exam summary
shell编程
JS工具函数大全
2022-7-7 personal qualifying 4 competition experience
Please tell me if there is any way to increase the write out rate when the Flink SQL client is in the sink table. When synchronizing through sink table
Vscode domestic image server acceleration
Daily Note (11) -- word formula input arbitrary matrix
Alphabetic string
全网最全:Mysql六种约束详解
Mysql8 dual master and dual slave +mycat2 read / write separation