Loading

随笔分类 -  算法

摘要:AOJ-ALDS1_1_D Maximum Profit 本题主要考虑要将复杂度降到O(n),否则过不了最后五组数据 #include<iostream> #include<bits/stdc++.h> using namespace std; int main(){ int n,maxv=-1e1 阅读全文
posted @ 2020-12-01 22:13 Do1phln 阅读(124) 评论(0) 推荐(0)
摘要:好久没见过CF有这么水的contest了,蒟蒻赶紧找找自信 A. Subtract or Divide #include<iostream> using namespace std; int main(){ int T,n; cin>>T; while(T--) { cin>>n; if(n<=3) 阅读全文
posted @ 2020-12-01 22:11 Do1phln 阅读(92) 评论(0) 推荐(0)
摘要:GCD,LCM 定理 a、b两个数的最大公约数乘以它们最小公倍数等于a和b的乘积 axb=GCD(a,b)xLCM(a,b) 据此定理,求3与8的最小公倍数可以为:LCM(3,8)=3x8divGCD(3,8)=24 欧几里得算法 构造关系:GCD(a,b)=GCD(b, a mod b) int 阅读全文
posted @ 2020-12-01 22:10 Do1phln 阅读(204) 评论(0) 推荐(0)
摘要:前言 近期发现我NEFU低年级组校赛题目只有模拟+数论,恰恰都是我最不会做的,数论方面反反复复用到的就是素数筛,特在此记录一下,闲来无事自己翻阅当作复习复习,以免被到时候一道题都做不出来菜到巨佬们。 代码 查找2-N的所有素数,如下 //线性筛 void init() { phi[1] = 1; f 阅读全文
posted @ 2020-12-01 22:09 Do1phln 阅读(101) 评论(0) 推荐(0)
摘要:本人随便乱写,目前正确性未知 C.本质上升序列 #include<bits/stdc++.h> using namespace std; bool access[4][4]; int dfs(int idx, int x, int y) { if(x<0 || y<0 || x>=4 || y>=4 阅读全文
posted @ 2020-12-01 22:07 Do1phln 阅读(241) 评论(0) 推荐(0)
摘要:#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> using namespace std; const int maxn = 100 + 5; char piece[maxn][maxn]; int n,m 阅读全文
posted @ 2020-11-10 20:02 Do1phln 阅读(73) 评论(0) 推荐(0)
摘要:逆向考虑即可解决 #include<iostream> using namespace std; const int maxn= 100000 +5; int a[maxn][4];//0-x,1-y,2-x-length,3-y-length int main(){ int n,flag=0; c 阅读全文
posted @ 2020-11-10 19:04 Do1phln 阅读(75) 评论(0) 推荐(0)
摘要:在输入过程中同时进行数据处理,代码简洁,效率较高 #include<iostream> #include<cstdio> using namespace std; bool solve(int& W) { int W1,D1,W2,D2; bool b1=true,b2=true; cin>>W1> 阅读全文
posted @ 2020-11-10 18:00 Do1phln 阅读(91) 评论(0) 推荐(0)
摘要:Description 给出长度为n的数组,找出这个数组的最长上升子序列 Input 第一行:输入N,为数组的长度(2=<N<=50000) 第二行:N个值,表示数组中元素的值(109<=a[i]<=109) Output 输出最长上升子序列的长度 Sample Input 5 -6 4 -2 10 阅读全文
posted @ 2020-11-06 22:20 Do1phln 阅读(136) 评论(0) 推荐(0)
摘要:#include<iostream> #include<cstdio> using namespace std; int main(){ int inf = 99999999; int n,m,t1,t2,t3,min; int e[7][7],dis[7],book[7]={0}; int cou 阅读全文
posted @ 2020-11-05 20:24 Do1phln 阅读(79) 评论(0) 推荐(0)
摘要:#include<iostream> #include<cstdio> using namespace std; struct edge { int u; int v; int w; }; struct edge e[10]; int n,m; int f[7]={0},sum=0,count=0; 阅读全文
posted @ 2020-11-05 20:22 Do1phln 阅读(91) 评论(0) 推荐(0)
摘要:思路 队列的原理基本与站队一样,队首出,队尾入,变化以后也是大同小异,写起来主要就是注意struct的相关知识,以及伪指针(分别指向队首和队尾+1),队尾序号要+1以防首位变量数字重合造成不必要的麻烦(目前也不是很清楚会遇到什么) 代码 #include<iostream> using namesp 阅读全文
posted @ 2020-11-04 22:52 Do1phln 阅读(145) 评论(0) 推荐(0)
摘要:思路 快排基本思路应该就是二分+递归,从两侧同时(实则先从右往左)往中间找,同时和参变量对比,发现位置颠倒后交换位置,然后通过二分将其一块一块的分割开,直到分割到一个元素位置,即完成了快排。 代码 #include<bits/stdc++.h> using namespace std; int a[ 阅读全文
posted @ 2020-11-04 22:51 Do1phln 阅读(258) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; int book[101],sum,n,e[101][101]; void dfs(int cur) { cout<<cur<<" "; sum++; if(sum==n) return; for(int i=1;i<= 阅读全文
posted @ 2020-11-04 22:49 Do1phln 阅读(63) 评论(0) 推荐(0)
摘要:输入100个学生的学号、姓名、性别(0男1女),数学、语文、英语成绩,然后计算语数外平均分按从高到低的顺序排列后输出。 #include<cstdio> #define MAXN 100 //学生类型 typedef struct student{ int id, sex, ch, ma, en; 阅读全文
posted @ 2018-01-22 00:02 Do1phln 阅读(448) 评论(0) 推荐(0)