-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: daoxi365 <[email protected]>
- Loading branch information
0 parents
commit 2475cbd
Showing
452 changed files
with
38,529 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
【提高】素数环 | ||
题目描述 | ||
从`1~n(2<=n<=10)`这`n`个数,摆成一个环,要求相邻的两个数的和是素数,按照由小到大请输出所有可能的摆放形式。 | ||
|
||
比如:`n = 4`,输出形式如下 | ||
|
||
``` | ||
1:1 2 3 4 | ||
2:1 4 3 2 | ||
3:2 1 4 3 | ||
4:2 3 4 1 | ||
5:3 2 1 4 | ||
6:3 4 1 2 | ||
7:4 1 2 3 | ||
8:4 3 2 1 | ||
total:8 | ||
``` | ||
|
||
比如:`n = 6`,输出形式如下 | ||
|
||
``` | ||
1:1 4 3 2 5 6 | ||
2:1 6 5 2 3 4 | ||
3:2 3 4 1 6 5 | ||
4:2 5 6 1 4 3 | ||
5:3 2 5 6 1 4 | ||
6:3 4 1 6 5 2 | ||
7:4 1 6 5 2 3 | ||
8:4 3 2 5 6 1 | ||
9:5 2 3 4 1 6 | ||
10:5 6 1 4 3 2 | ||
11:6 1 4 3 2 5 | ||
12:6 5 2 3 4 1 | ||
total:12 | ||
``` | ||
|
||
输入 | ||
一个整数n`(2<=n<=10)` | ||
|
||
输出 | ||
前若干行,每行输出一个素数环的解,最后一行,输出解的总数 | ||
|
||
样例 | ||
输入 | ||
|
||
``` | ||
4 | ||
``` | ||
|
||
输出 | ||
``` | ||
1:1 2 3 4 | ||
2:1 4 3 2 | ||
3:2 1 4 3 | ||
4:2 3 4 1 | ||
5:3 2 1 4 | ||
6:3 4 1 2 | ||
7:4 1 2 3 | ||
8:4 3 2 1 | ||
total:8 | ||
``` | ||
|
||
> 思路: | ||
> 先将其看成全排列,在获得一个解的时候枚举判断相邻两个数之和是否都是素数。如果是,就找到了一组素数环,输出。 | ||
|
||
```cpp | ||
// Author:PanDaoxi | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
const int inf = 11; | ||
int n, use[inf], f=0; | ||
bool vis[inf]; | ||
void print(){ | ||
printf("%d:", ++f); | ||
for(int i=1; i<=n; i++){ | ||
printf("%d ", use[i]); | ||
} | ||
printf("\n"); | ||
} | ||
bool prime(int n){ | ||
if(n <= 1){ | ||
return false; | ||
} | ||
for(int i=2; i*i<=n; i++){ | ||
if(n%i == 0){ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
void dfs(int k){ | ||
if(k == n){ | ||
bool flag = false; | ||
for(int i=1; i<n; i++){ | ||
if(!prime(use[i] + use[i+1])){ | ||
flag = true; | ||
} | ||
} | ||
if(!flag && prime(use[1] + use[n])){ | ||
print(); | ||
} | ||
} | ||
for(int i=1; i<=n; i++){ | ||
if(!vis[i]){ | ||
vis[i] = true; | ||
use[k+1] = i; | ||
dfs(k+1); | ||
vis[i] = false; | ||
} | ||
} | ||
} | ||
int main(){ | ||
cin >> n; | ||
dfs(0); | ||
printf("total:%d", f); | ||
return 0; | ||
} | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
【提高】素数环 | ||
题目描述 | ||
从`1~n(2<=n<=10)`这`n`个数,摆成一个环,要求相邻的两个数的和是素数,按照由小到大请输出所有可能的摆放形式。 | ||
|
||
比如:`n = 4`,输出形式如下 | ||
|
||
``` | ||
1:1 2 3 4 | ||
2:1 4 3 2 | ||
3:2 1 4 3 | ||
4:2 3 4 1 | ||
5:3 2 1 4 | ||
6:3 4 1 2 | ||
7:4 1 2 3 | ||
8:4 3 2 1 | ||
total:8 | ||
``` | ||
|
||
比如:`n = 6`,输出形式如下 | ||
|
||
``` | ||
1:1 4 3 2 5 6 | ||
2:1 6 5 2 3 4 | ||
3:2 3 4 1 6 5 | ||
4:2 5 6 1 4 3 | ||
5:3 2 5 6 1 4 | ||
6:3 4 1 6 5 2 | ||
7:4 1 6 5 2 3 | ||
8:4 3 2 5 6 1 | ||
9:5 2 3 4 1 6 | ||
10:5 6 1 4 3 2 | ||
11:6 1 4 3 2 5 | ||
12:6 5 2 3 4 1 | ||
total:12 | ||
``` | ||
|
||
输入 | ||
一个整数n`(2<=n<=10)` | ||
|
||
输出 | ||
前若干行,每行输出一个素数环的解,最后一行,输出解的总数 | ||
|
||
样例 | ||
输入 | ||
|
||
``` | ||
4 | ||
``` | ||
|
||
输出 | ||
``` | ||
1:1 2 3 4 | ||
2:1 4 3 2 | ||
3:2 1 4 3 | ||
4:2 3 4 1 | ||
5:3 2 1 4 | ||
6:3 4 1 2 | ||
7:4 1 2 3 | ||
8:4 3 2 1 | ||
total:8 | ||
``` | ||
|
||
> 思路: | ||
> 先将其看成全排列,在获得一个解的时候枚举判断相邻两个数之和是否都是素数。如果是,就找到了一组素数环,输出。 | ||
|
||
```cpp | ||
// Author:PanDaoxi | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
const int inf = 11; | ||
int n, use[inf], f=0; | ||
bool vis[inf]; | ||
void print(){ | ||
printf("%d:", ++f); | ||
for(int i=1; i<=n; i++){ | ||
printf("%d ", use[i]); | ||
} | ||
printf("\n"); | ||
} | ||
bool prime(int n){ | ||
if(n <= 1){ | ||
return false; | ||
} | ||
for(int i=2; i*i<=n; i++){ | ||
if(n%i == 0){ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
void dfs(int k){ | ||
if(k == n){ | ||
bool flag = false; | ||
for(int i=1; i<n; i++){ | ||
if(!prime(use[i] + use[i+1])){ | ||
flag = true; | ||
} | ||
} | ||
if(!flag && prime(use[1] + use[n])){ | ||
print(); | ||
} | ||
} | ||
for(int i=1; i<=n; i++){ | ||
if(!vis[i]){ | ||
vis[i] = true; | ||
use[k+1] = i; | ||
dfs(k+1); | ||
vis[i] = false; | ||
} | ||
} | ||
} | ||
int main(){ | ||
cin >> n; | ||
dfs(0); | ||
printf("total:%d", f); | ||
return 0; | ||
} | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
![在这里插入图片描述](https://pic.2ge.org/cdn/?url=https://img-blog.csdnimg.cn/9630588c30eb41f89285f028a08e0a29.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5r2Y6YGT54a5,size_20,color_FFFFFF,t_70,g_se,x_16) | ||
(这是一道真题) | ||
|
||
```cpp | ||
//Author:PanDaoxi | ||
#include <iostream> | ||
using namespace std; | ||
int main(){ | ||
int n,a,b,c; | ||
cin>>n; | ||
while(n!=0){ | ||
a=n%10; //获取末位 | ||
b=c*10+a; | ||
c=b; | ||
n/=10; //递除 | ||
} | ||
cout<<c; | ||
} | ||
``` | ||
![在这里插入图片描述](https://pic.2ge.org/cdn/?url=https://img-blog.csdnimg.cn/278e606011a3471a8c05188e35f991c3.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5r2Y6YGT54a5,size_20,color_FFFFFF,t_70,g_se,x_16) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
请大家先安装模块`pip3 install autopy`。 | ||
我们打开编辑器,输入以下代码: | ||
|
||
```python | ||
import autopy | ||
autopy.mouse.move(100,100) | ||
``` | ||
或者 | ||
|
||
```python | ||
import autopy | ||
autopy.mouse.smooth_move(100,200) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
![在这里插入图片描述](https://pic.2ge.org/cdn/?url=https://img-blog.csdnimg.cn/3fa78e2e26cc4ecaa1ac28736e7486b2.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5r2Y6YGT54a5,size_20,color_FFFFFF,t_70,g_se,x_16) | ||
|
||
```cpp | ||
//Author:PanDaoxi | ||
#include<cstdio> | ||
#include<cmath> | ||
#include<cstring> | ||
#include<algorithm> | ||
#include<iostream> | ||
using namespace std; | ||
long long b[1000010]; | ||
long long r[1000010]; | ||
long long pell(int n){ | ||
if(n<3) return n; | ||
if(b[n]==0) b[n]=(2*pell(n-1)+pell(n-2))%100000; | ||
return (b[n]%32767); | ||
} | ||
int main(){ | ||
int n,x; | ||
cin>>n; | ||
for(int i=1;i<=n;i++){ | ||
cin>>x; | ||
r[i]=pell(x); | ||
} | ||
for(int j=1;j<=n;j++){ | ||
cout<<r[j]<<endl; | ||
} | ||
} | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
> 输入n,输出1~n(包含1和n)之间所有的回文数,并统计回文数的个数。个数之前要加星号。 | ||
> 输入: 100 | ||
> 输出:(下面是需要换行的) | ||
> 1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99 | ||
> *18 | ||
这道题我挖掘了两种做法,一种好理解但是运行内存和时间可能要差点;另一种稍微费点劲,但是可以放到比赛里用。 | ||
|
||
方法一: | ||
|
||
```cpp | ||
// Author:PanDaoxi | ||
#include <iostream> | ||
using namespace std; | ||
bool hw(int n){ | ||
int a[11],b[11],m=n,i=0; | ||
while(m){ | ||
a[i++]=m%10; // 获取到每一位的数字,储存在数组 | ||
m/=10; | ||
} | ||
for(int j=0;j<i;j++){ // 数组b将数组a的元素倒置 | ||
b[j]=a[i-j-1]; | ||
} | ||
for(int k=0;k<i;k++){ | ||
if(a[k]!=b[k]) return false; // 如果有一位上的数字不同,就不是回文数 | ||
} | ||
return true; | ||
} | ||
int main(){ | ||
int n,s=0; | ||
cin>>n; | ||
for(int i=1;i<=n;i++){ | ||
if(hw(i)){ | ||
s++; | ||
cout<<i<<endl; | ||
} | ||
} | ||
cout<<"*"<<s; | ||
return 0; | ||
} | ||
|
||
``` | ||
第二种: | ||
```cpp | ||
// Author:PanDaoxi | ||
#include <iostream> | ||
using namespace std; | ||
int main(){ | ||
int n,s=0,t,k=10,m; | ||
cin>>n; | ||
for(int i=1;i<=n;i++){ | ||
t=i,m=0; | ||
while(t!=0){ | ||
m=m*k+t%10; | ||
t/=10; // 重新组合 | ||
} | ||
if(m==i){ // 判断组合前后的数是否一样 | ||
cout<<m<<endl; | ||
s++; | ||
} | ||
} | ||
cout<<"*"<<s; | ||
return 0; | ||
} | ||
``` | ||
|
Oops, something went wrong.