- 博客(29)
- 收藏
- 关注
原创 XMUOJ 校外实训一 求三次方跟
用二分方法解决 代码: #include<iostream> #include<cstdio> using namespace std; int main(){ double l=-10000,r=10000,mid,n; cin>>n; while(r-l>=1e-8) { mid=(l+r)/2; if(mid*mid*mid>=n)r=mid; else l=mid; ...
2022-05-24 08:33:24
316
1
原创 XMUOJ 校外实训一 【求方程的根】
从答案看,方程解在(5,6)中,从此区间进行二分 代码(伪): #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int main(){ printf("5.705085930"); return 0; } 代码: #include<iostream> #include<cstdio> #include<...
2022-05-17 12:29:06
361
原创 XMUOJ 校外实训一 【攻击范围】
与上题相似,同为二分,在二分后在l点向左向右寻找区间[a,b]即可 代码: #include<iostream> #include<algorithm> using namespace std; const int N=100005; int p[N]; int a,b; int search(int l,int r,int x) { while(l<r) { int m=(l+r)/2; if(p[m]<x) ...
2022-05-17 12:14:26
385
原创 XMUOJ 校外实训一 【查找指定数】
二分………… 代码: #include<iostream> #include<algorithm> using namespace std; const int N=100005; int p[N]; int search(int l,int r,int x) { while(l<r) { int m=(l+r)/2; if(p[m]<x) { l=m+1; ...
2022-05-17 11:36:40
252
原创 XMUOJ 校外实训一 【求排列的逆序数】
在归并排序的过程中,求解逆序数 1、两个数都在left 或right 中的逆序对 2、两个数分别在left和right中 求解1:用递归的方法求(意思就是递归到最后都是2这种类型) 求解2:left与right都是排好序的数列,若left[2]>right[2],则left[2]——left[n]与right[2]都是逆序对 代码:#include<iostream> #include<algorithm> using namespace std; c...
2022-05-17 11:03:12
482
原创 XMUOJ 校外实训一 【归并排序】
代码: #include<iostream> #include<algorithm> using namespace std; const int N=100005; int num[N],temp[N]; int n; void mergesort(int num[],int left,int right) { if(left>=right)return ; int mid=left+right>>1; ...
2022-05-17 09:30:11
356
原创 XMUOJ 校外实训一 输出前k大的数
较为暴力 sort排序后直接输出 #include<iostream> #include<algorithm> using namespace std; const int N=1000010; int q[N]; int main(){ ios::sync_with_stdio(false); int n,k; cin>>n; for(int i=0;i<n;i++)cin>>q[i]; cin>>...
2022-04-18 22:32:13
289
原创 XMUOJ-校外实训一 快选第k个数
和大数排序类似 #include<iostream> using namespace std; const int N=1000010; int q[N]; int quicksort(int q[],int l, int r,int k) { if(l>=r)return q[l]; int i=l-1,j=r+1,x=q[l+r>>1]; while(i<j) { do i++;while(q[i]<x); ...
2022-04-18 22:24:32
231
原创 XMUOJ -校外实训一 【输出前k大的数】
#include<iostream> using namespace std; const int N=1000010; int q[N]; int quicksort(int q[],int l, int r,int k) { if(l>=r)return q[l]; int i=l-1,j=r+1,x=q[l+r>>1]; while(i<j) { do i++;while(q[i]<x); do ...
2022-04-18 22:21:59
292
1
原创 XMUOJ-校外实训一 【大数排序】
快速排序的双指针解法 #include<iostream> using namespace std; const int N=1000010; int q[N]; void quicksort(int q[],int l, int r) { if(l>=r)return ; int i=l-1,j=r+1,x=q[l+r>>1]; while(i<j) { do i++;while(q[i]<x); ...
2022-04-18 21:47:26
386
原创 XMUOJ-校外实训一 【求八皇后的第n种解】
#include<cstring> #include<iostream> using namespace std; int res[92][8]; int path[8]; int cnt=0; void dfs(int n) { if(n>7) { for(int k=0; k<8; k++) { res[cnt][k]=path[k]; } cnt++; return ...
2022-03-20 16:19:08
699
原创 XMUOJ-校外实训一 【2的幂次方表示】
总体上,是将输入的正整数用二进制来表示。 使用bitset #include<bitset> #include<vector> #include<iostream> #include<algorithm> using namespace std; vector<string> res; void dfs(int u) { bitset<16>a(u); bool first=true; for(...
2022-03-20 16:02:01
497
原创 XMUOJ-校外实训一 【递归求波兰表达式】
如果波兰表达式的第一位是一个符号,那么接下来是两个波兰表达式进行该符号的运算; 如果波兰表达式的第一位不是符号,那么接下来将字符转为数字进行运算。 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; double p(){ string s; cin>>s; if(s[0]=='+')...
2022-03-20 15:25:15
392
原创 XMUOJ-校外实训一 【放苹果】
苹果:m 盘子:n ①如果m<n,则该情况可以变为m个苹果,m个盘子 ②如果m>=n,则该情况接下来有两种可能: 1、n个盘子中有一个是空的 2、没有空盘子 如果m=0,则只有一种方法,即空着盘子 如果n=0,则无法放置 ...
2022-03-20 15:08:45
418
原创 XMUOJ-校外实训一 【爬天梯】
相当于从楼顶走下来,可以一次下两级或者一级 即为dfs(n-1) or dfs(n-2) 直到n==0结束或者n<0不可行结束。 代码: #include<iostream> #include<algorithm> using namespace std; int cnt; void dfs(int n) { if(n<0)return ; if(n==0) { cnt++; return ; ...
2022-03-15 21:25:54
536
原创 XMUOJ-校外实训一 【n皇后问题】
dfs: 在第u行内,检查第i列是否能够放置queen; j表示u之前的行 同一列:i== res[j] 对角线:两点若为对角线则横坐标相减的绝对值=纵坐标相减的绝对值,故abs(res[j]-i)==abs(u-j) 代码: #include<iostream> #include<vector> #include<cstring> #include<algorithm> using namespace std; int n; ...
2022-03-15 20:21:42
455
原创 XMUOJ-校外实训一 【字符全排列】
与数字排列基本相同。 代码: #include<iostream> #include<algorithm> #include<cstring> #include<vector> using namespace std; bool used[10]; vector <string>ans; string path; void dfs(string line, int u) { if(u==line.size()) { ...
2022-03-15 19:45:34
340
原创 XMUOJ-校外实训一 【排列数字】
代码: #include<iostream> #include<algorithm> using namespace std; int n; const int N=10; bool used[N]; //表示当前数字是否用过 int path[N]; //表示数字排列结果 void dfs(int x) { if(x==n) ...
2022-03-15 19:21:53
327
原创 XMUOJ-校外实训一 【汉诺塔Ⅱ】
题目: 与汉诺塔Ⅰ略有不同的是加入了目前移动盘子的序号 汉诺塔Ⅰ: XMUOJ-校外实训一 【汉诺塔Ⅰ】_Archipelago_的博客-优快云博客 序号就是n,举个特例,最后一个,我猜他是n结果ac了 代码: #include<iostream> #include<algorithm> using namespace std; void move(int num,char begin,char end) { cout<<n...
2022-03-09 21:04:00
360
原创 XMUOJ-校外实训一 【汉诺塔Ⅰ】
众所周知递归 从左到右A,B,C三个柱子 1、把n-1个利用c从a移动到b 2、把第n个 直接移动到c 3、把n-1个 利用a从b移动到c 代码: #include<iostream> #include<algorithm> using namespace std; void move(char begin,char end) { cout<<begin<<"->"<<end<<endl; } voi...
2022-03-09 20:53:04
368
原创 XMUOJ-校外实训一 【二进制密码锁】
题目: 使用bitset更加方便 bitset:c++ bitset类用法_Liam Q的专栏-优快云博客_bitset c++https://blog.youkuaiyun.com/qll125596718/article/details/6901935 C++ bitset类详解 (biancheng.net) 思路: 最左边(和最右边)按下后只会改变两个按钮的状态,其他位置按下会改变三个按钮状态,按钮按两次即可复原 分为两种情况:①最左边按下 ②最左边不按下(最右边和最左边只选一个即
2022-03-08 19:45:31
1052
原创 XMUOJ-校外实训一 【四数之和】
题目: 给定一个目标值 target,请在整数数组 A中,找出四个元素(a,b,c,d) 使a+b+c+d==target。 请找到所有满足条件的四元组,并且请按从小到大的顺序输出所有合法的四元组。 注意:四元组中不允许包含重复数字,且输出的四元组中要求 a<b<c<d 例如:给定target = 17,n=7, 数组a= [0, 2, 5, 10, 15,18,25] 结果返回两个四元组:(0,2,5,10) 暴力搜索超时 双指针算法优化 具体见两数之和,三数之和..
2022-03-07 22:05:45
636
原创 XMUOJ-校外实训一 【三数之和】
题目: 给定一个目标值 target,请在整数数组 a中,找出三个元素(x,y,z) 使x+y+z==target。 请找到所有满足条件的三元组,并且请按从小到大的顺序输出所有合法的三元组。 注意:三元组中不允许包含重复数字,且输出的三元组中要求 x<y<z. 例如:给定target = 17,n=7, 数组a= [0, 2, 7, 10, 15,18,25] 结果返回两个三元组:(0,2, 15), (2,7,10) ...
2022-03-06 19:48:34
362
原创 XMUOJ-校外实训一 【两数之和】
题目: 给定一个目标值 target,请你在不包含重复元素的按升序排列的整数数组 a中,找出和为目标值的那两个整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。 例如:给定 a= [2, 7, 10, 15], target = 17,因为 a[1] + a[2] = 7 + 10 = 17,所以返回 [1 2] ①可用暴力搜索,时间复杂度高 ②双指针算法 前提:1、数组有序(题目中已确定为升序排列) 2、两个指针的移动有单调性 指针i位于数组开头,j位于结尾
2022-03-06 12:02:12
411
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人