02 2023 档案
线段树有感
摘要:当前数组 a1 a2 a3.....an; 对于每个下表i,求 aj<ai ( j<i ) 的个数,为当ai的文化素养, 点击查看代码 #include<bits/stdc++.h> using namespace std; const int N=1e7+9; int e[N],a[N],lazy
c++快输的偏爱cin
摘要:当你在代码中写下 ios::sync_with_stdio(0); cin.tie(0); 的时候( 关闭流同步),终于实现了cin的快速输入,但是这也意味着你与cin,cout终身绑定,白头偕老,画上完美句号(程序结束)。 如果你用的是dev编辑器,有可能你的数据依然对,请不要疑惑,这只是编辑器的
最快素数打表,比欧拉筛快一倍。
摘要:版本一:1e7内比欧拉筛子快一倍,2e7持平,之后略慢 不论N多大整体计算次数,都是欧拉筛子的1/3,求大神解答1e8之后为什么变慢 思路:相较于欧拉筛考虑1-n所有数,这里基于孪生素数,只需要考虑孪生素数,n/3; 版本二:解决了1e8的问题,多加了一个sqrt(N)的处理,缺点代码更繁琐。 版本
93. 递归实现组合型枚举
摘要:题解:递归方法,在上一题的题解上面加一个限定就行了 点击查看代码 #include<iostream> #include<algorithm> #include<cstring> using namespace std; typedef pair<int,int> pll; typedef long
92. 递归实现指数型枚举
摘要:题解:递归,加数组 点击查看代码 #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N=1e5+7; int n; int a[N]; void dfs(int x,int
91. 最短Hamilton路径
摘要:算法:动态规划位操作压缩 题解:e[i][j] i表示路线 ,j表示终点 ,初始化e[1][0]=0,表示从0点出发。 例如:i=7,n=4,二进制为 0111 表示经过 点 0 1 2 。 点击查看代码 #include<iostream> #include<algorithm> #include
#3742. 「COCI 2015.3」PROSJEK
摘要:算法:二分加前缀和 题解:二分查找最大平均值,f函数判断当前平均值mid是否合适,数组元素减去x,求前缀和sum,从sum[k]遍历,mi中存前面的最小值。 点击查看代码 #include<iostream> #include<algorithm> using namespace std; cons
牛客情人节 (悸动的距离)
摘要:点击查看代码 int a,b,c,d; cin>>a>>b>>c>>d; int ans=0; if(a>=0&&c<=0||c>=0&&a<=0) ans++; //x轴交点 if(b>=0&&d<=0||b>=0&&d<=0) ans++; //y轴交点 if(ans==2&&a*d==b*c)
90. 64位整数乘法
摘要:点击查看代码 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 10; ll a,b,p; ll solve() { ll ans=0; while(b) { if(b&1)
89. a^b
摘要:点击查看代码 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 10; ll a,b,p; ll solve() { ll ans=1; while(b) { if(b&1)