#include<bits/stdc++.h>usingnamespace std;typedef __int128 Int;typedeflonglong ll;
ll n =1001733993063167141, d =212353,C =20190324,tmp;
Int e;boolisPrime(int x){if(x<2)returnfalse;for(int i=2;i<=sqrt(x);i++)if(x%i==0)returnfalse;returntrue;}voidPrint(Int x){int a[1000],top=0;while(x){int b=x%10;
a[++top]=b;
x/=10;}for(int i=top;i>=1;i--)
cout<<a[i];}voidqmod(ll a,ll n,ll mod){
Int res=1;
Int base=a;while(n){if(n&1) res=(res*base)%mod;
base=(base*base)%mod;
n>>=1;}Print(res);}intmain(){
ll p,q;//1,求p,q; // for(int i=3;i<=sqrt(n);i++)// if(n%i==0&&isPrime(i)&&isPrime(n/i)){// p=i;q=n/i;// break;// }//cout<<p<<" "<<q;
p=891234941; q=1123984201;//2,求e
tmp=(p-1)*(q-1);for(Int i=2;i<=n;i++){
Int now=i*tmp+1;if(now%d==0){
e=now/d;break;}}//Print(e);qmod(C,e,n);return0;}
完全二叉树的权值:堆
#include<iostream>#include<cstring>#include<algorithm>typedeflonglong LL;usingnamespace std;constint N =100010;int n;int a[N];intmain(){
LL sum =-0x3f3f3f3f, depth =1;scanf("%d",&n);for(int i =1; i <= n; i ++)scanf("%d",&a[i]);for(int d =1, i =1; i <= n; i ++, d ++){
LL j = i, s =0;while(j < i *2&& j <= n){
s += a[j];
j ++;}if(s > sum){
sum = s;
depth = d;}
i = j -1;}
cout << depth << endl;return0;}
B组
七段码:并查集、连通块、枚举
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;constint N =10;int n;int g[N][N];bool st[N];voiddfs(int t,int u){
st[u]=true;for(int j =0; j <7; j ++)if(g[u][j +1]&&(t >> j &1)&&!st[j +1])dfs(t, j +1);}boolcheck(int x){int t = x, cnt =0;memset(st,0,sizeof st);for(int j =0; j <7; j ++)if(t >> j &1&&!st[j +1]){dfs(t, j +1);
cnt ++;}return cnt ==1;}intmain(){for(int i =1; i <=6; i ++){
g[i][i +1]= g[i +1][i]=1;}
g[2][7]= g[7][2]=1;
g[3][7]= g[7][3]=1;
g[5][7]= g[7][5]=1;
g[1][6]= g[6][1]=1;int ans =0;for(int i =1; i <(1<<7); i +=1){if(check(i)) ans ++;}
cout << ans << endl;return0;}
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;constint N =2200;int g[N][N];int dist[N];int n =2021;bool st[N];intgcd(int a,int b){return b ?gcd(b, a % b): a;}voiddijkstra(){memset(dist,0x3f,sizeof dist);
dist[1]=0;for(int i =1; i <= n; i ++){int t =-1;for(int j =1; j <= n; j ++)if(!st[j]&&(t ==-1|| dist[j]< dist[t]))
t = j;
st[t]=true;for(int j =1; j <= n; j ++)
dist[j]=min(dist[j], dist[t]+ g[t][j]);}}intmain(){memset(g,0x3f,sizeof g);for(int i =1; i <=2021; i ++)for(int j =max(i -21,1); j <=min(i +21, n); j ++){int d =gcd(i, j);
g[i][j]= g[j][i]= i * j / d;}dijkstra();
cout << dist[n]<< endl;return0;}
堆优化版dijkstra算法
在这里插入代码片
spfa算法
在这里插入代码片
时间显示
#include<iostream>#include<cstring>#include<algorithm>typedeflonglong LL;usingnamespace std;intmain(){
LL n, h, m, s;
cin >> n;
n /=1000;
h = n /3600%24;
n %=3600;
s = n %60;
m = n /60;printf("%02lld:%02lld:%02lld", h, m, s);return0;}