![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
信息学奥赛
穷源溯流
路很长,尽管走便是。
展开
-
1643:Fibonacci 前 n 项和
s[n]=s[n-1]*1+f[n]+f[n-1]*0f[n+1]=s[n-1]*0+f[n]+f[n-1]f[n]=s[n-1]*0+f[n-1]*0+f[n]按照这三个方程构造矩阵即可#include <iostream>#include <cstdio>#include <cstring>#define N 3+5using namespace std;typedef long long ll; ll n,m; ...原创 2020-10-25 11:23:02 · 373 阅读 · 0 评论 -
1652:牡牛和牝牛
这 n 头牛首先要确定有多少公牛,有多少母牛,如果有 i 头公牛,那么至少有(i-1)*k 头母牛,由于 p>n 所以直接做即可const ll mod=5000011;const int N=30+5; int n,m,t; int i,j,k; //int a[N];ll pow_mod(ll a,ll x,ll p){ ll ans=1; a%=p; while(x){ if(x&1) ans...原创 2020-10-24 12:21:41 · 598 阅读 · 0 评论 -
1650:组合
因为 n 的值很大,所以需要借助 lucas 定理进行化简,另外 jc 数组没法开到 p 的大小,所以不能采用预处理的方式ll pow_mod(ll a,ll x,ll mod){ ll ans=1; a%=mod; while(x){ if(x&1) ans=ans*a%mod; a=a*a%mod; x>>=1; } return ans;}ll C(ll n,ll m,l...原创 2020-10-24 10:57:27 · 251 阅读 · 0 评论 -
1634:曹冲养猪(中国剩余定理)
利用中国剩余定理 求解 b[1]=n1%a[1],b[2]=n2%a[2], ……b[x]=nx%a[x]假设 m=a[1]*a[2]*……a[n]那么利用 ex_gcd(m/a[i],a[i],x,y)求解的是,两个互质的数 m/a[i],a[i] 的方程 ,即 x 为 m/a[i] 的逆元,这样在 *余数 b[i],就可以得到除 a[i] 之外的所有数的公倍数 ni,且 ni 还满足 ni%mb[i]const int N=1e3+5;ll mod=1e9+7; ...原创 2020-10-17 19:54:58 · 687 阅读 · 1 评论 -
1568:普通平衡树
const int N=1e5+5; int n,m,t; int i,j,k; //ll a[N]; struct Node { int l,r; int fa,prl; int val; //父节点,优先级,值 int sz,cnt; //节点的大小,节点包含重复元素的个数 }node[N]; int root=0,tot=0,ans; //根,节点个数,记录前驱后继答案...原创 2020-10-12 20:44:46 · 378 阅读 · 0 评论 -
1565:营业额统计(平衡树)
注意:以下代码最后一个点会 T,输入改成快读应该可以过const int N=5e5+5; int n,m,t; int i,j,k; int a[N]; struct Node { int l,r; int fa,prl,val; //父节点,优先级,值 }node[N]; int root=0,tree=0; //根,节点个数void zig(int &x) //右旋{ ...原创 2020-10-08 17:07:12 · 469 阅读 · 0 评论 -
1562:「NOI2015」软件包管理器
可能洛谷上的题目描述更友好一些:https://www.luogu.com.cn/problem/P2146这个题和不同的树链剖分有一点不同,首先建图时考虑单向边其次利用 lazy 操作,分别计算安装 x 时需要在安装多少,因为可能不在同一条链上,所以利用述链剖分但是删除 x 时,一定在一条链上,所以直接在线段树上操作即可const int N=1e5+5; int n,m,t; int i,j,k; int a[N]; vector&l...原创 2020-10-01 21:27:56 · 309 阅读 · 0 评论 -
1561:「HAOI2015」树上操作
【输入样例】5 51 2 3 4 51 21 42 32 53 31 2 13 52 1 23 3【输出样例】6913const int N=2e5+5; int n,m,t; int i,j,k; int a[N]; vector<int> G[N<<1];int sz[N],son[N],fa[N],dep[N];void dfs1(int u,int f){ sz[u...原创 2020-10-01 11:21:31 · 405 阅读 · 0 评论 -
1560:树的统计
#pragma GCC optimize(2)#include <bits/stdc++.h>#include <iostream>#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <vector>#include <utility>#de.原创 2020-09-29 23:24:17 · 446 阅读 · 0 评论 -
1552:点的距离(倍增求 lca)
const int lgN=20+3;const int N=2e5+5; int n,m,t; int i,j,k; //int a[N]; vector<int> G[N]; int dep[N]; int f[N][lgN]; void dfs(int u,int fa){ dep[u]=dep[fa]+1; for(int i=1;i<lgN;i++){ f[u][i]=f[f...原创 2020-09-26 09:37:58 · 442 阅读 · 0 评论 -
1545:Balanced Lineup
const int N=5e4+5;const int lgN=15+5; int n,m,t; int i,j,k; int a[N]; int lg[N]; int f[N][lgN]; int g[N][lgN]; void init(){ lg[0]=-1; for(int i=1;i<=n;i++){ lg[i]=lg[i>>1]+1; f[i][0]=a[i...原创 2020-09-21 22:20:26 · 388 阅读 · 0 评论 -
1544:天才的记忆
const int N=2e5+5;const int lgN=18+5; int n,m,t; int i,j,k; int a[N]; int lg[N]; int f[N][lgN]; void init(){ lg[0]=-1; for(int i=1;i<=n;i++){ lg[i]=lg[i>>1]+1; f[i][0]=a[i]; } for(in...原创 2020-09-20 09:39:03 · 296 阅读 · 0 评论 -
1551:维护序列(区间乘法+区间加法)
虽然感觉是模板题,但做起来很不容易啊在对区间进行乘法运算 (假设 *k )时,乘法的 lazy 标记需要变为 lazy*k区间之和 sum 也要变为 sum*k但是要注意区间的加法运算标记 lazy(add) 也要 *k因为现有的 lazy(add) 标记还未加到区间中还应该注意的是在 lazy 标记的 push_down 操作中,应该先下放 乘法运算的 lazy 标记,因为在上面已经将 lazy(add) 更改了const int ...原创 2020-09-20 09:13:30 · 574 阅读 · 0 评论 -
1550:花神游历各国 (区间开方)
区间问题向 下放操作 上去考虑,当子节点全部都是 1 / 0 时,此时不需要操作更新const int N=1e6+5; int n,m,t; int i,j,k; int a[N]; struct Node { int l, r; ll sum; bool f; //所有子节点都 <=1 则为 1 ; }node[N<<2]; void push_up(int...原创 2020-09-19 11:13:47 · 345 阅读 · 0 评论 -
1548:A Simple Problem with Integers
const int N=1e6+5; int n,m,t; int i,j,k; int a[N]; struct Node { int l, r; ll sum,lazy; void update(int x) { sum+=1ll*(r-l+1)*x; lazy+=x; } }node[N<<2]; ...原创 2020-09-19 09:07:33 · 342 阅读 · 0 评论 -
1542:最敏捷的机器人
const int N=1e5+5;const int logN=17; int n,m,t; int i,j,k; int a[N]; int log[N]; int dp[N][logN+5][2]; //[0]最大值 [1]最小值void init(){ log[0]=-1; for(int i=1;i<=n;i++){ log[i]=log[i>>1]+1; dp[i][0]...原创 2020-09-17 22:50:46 · 252 阅读 · 0 评论 -
1541:数列区间最大值
const int N=1e6+5;const int logN=20; int n,m,t; int i,j,k; int a[N]; int log[N]; int f[N][logN+5];int main(){ //IOS; while(~sdd(n,m)){ for(i=1;i<=n;i++) sd(a[i]); log[0]=-1; for(i=1;i<=n;i...原创 2020-09-17 15:20:01 · 372 阅读 · 0 评论 -
1537:校门外的树
const int N=2e5+5; int n,m,t; int i,j,k; int L[N]; int R[N];void update(int pos,int val,int *c){ for(int i=pos;i<=N;i+=lowbit(i)){ c[i]+=val; }}int sum(int pos,int *c){ int ans=0; for(int i=pos;i;i-=lo...原创 2020-09-17 14:39:49 · 359 阅读 · 0 评论 -
1539:简单题
const int N=2e5+5; int n,m,t; int i,j,k; int L[N]; int R[N];void update(int pos,int val,int *c){ for(int i=pos;i<=N;i+=lowbit(i)){ c[i]+=val; }}int sum(int pos,int *c){ int ans=0; for(int i=pos;i;i-=lo...原创 2020-09-17 14:32:12 · 338 阅读 · 0 评论 -
1538:清点人数
const int N=2e5+5; int n,m,t; int i,j,k; int c[N];void update(int pos,int val){ for(int i=pos;i<=N;i+=lowbit(i)){ c[i]+=val; }}int sum(int pos){ int ans=0; for(int i=pos;i;i-=lowbit(i)){ ans+=c[i];...原创 2020-09-17 14:08:42 · 561 阅读 · 0 评论 -
1536:数星星 Stars
const int N=2e5+5; int n,m,t; int i,j,k; int c[N]; Pair p[N]; int ans[N];void update(int pos,int val){ for(int i=pos;i<=N;i+=lowbit(i)){ c[i]+=val; }}int sum(int pos){ int ans=0; for(int i=pos;i...原创 2020-09-17 13:59:56 · 479 阅读 · 0 评论 -
1459:friends
#pragma GCC optimize(2)#include <bits/stdc++.h>#include <iostream>#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <vector>#include <utility>...原创 2020-09-16 08:46:51 · 616 阅读 · 0 评论 -
POJ 2752 && 1458:Seek the Name, Seek the Fame
const int N=1e6+5; int n,m,t; int i,j,k; //int a[N]; char s[N]; ull power[N]; ull h[N]; const int b=131;bool C(int x,ull val){ int p=n-x; if( h[n]-h[p]*power[x]==val ) return true; return false;}int main(...原创 2020-09-14 17:02:25 · 227 阅读 · 0 评论 -
POJ 2406 && 1457:Power Strings
const int N=1e6+5; int n,m,t; int i,j,k; //int a[N]; char s[N]; ull power[N]; ull h[N]; const int b=131;bool C(int len,ull val,int x){ for(int i=0;i<len;i+=x){ if(h[i+x]-h[i]*power[x]!=val) return false;...原创 2020-09-14 16:50:04 · 159 阅读 · 0 评论 -
1455:Oulipo(字符串 Hash)
const int N=1e6+5; int n,m,t; int i,j,k; //int a[N]; char s[N],s1[N]; ull power[N]; ull h[N];int main(){ IOS; power[0]=1; const int b=131; for(i=1;i<=1e6;i++){ power[i]=power[i-1]*b; } rus...原创 2020-09-14 15:52:49 · 288 阅读 · 0 评论 -
1574:矩阵取数游戏
首先先算出 n 行中每一行的最值,相加即可对于每一行来说,在区间 [i,j] 中,dp[i][j]=max(dp[i+1][j]+a[i]*2^i,dp[i][j-1]+a[j]*2^i)在开始之前,首先要处理一下,将谁放在最后一位提取,因为每一个数都可以是最后一个被提取的当然在实现过程中需要用到高精度,但我不会啊(逃)下面的代码只能过 6 个点const int N=100+5; int n,m,t; int i,j,k; ll a[N][N]...原创 2020-08-11 16:17:07 · 1207 阅读 · 0 评论 -
1573:分离与合体
const int N=300+5; int n,m,t; int i,j,k; int a[N]; int dp[N][N]; int ans[N][N];//储存区间 i~j 上的分界点void print(int l,int r,int step,int cnt){ if(l>=r) return ; int mid=ans[l][r]; if(cnt==step){ printf("%d ",mi...原创 2020-08-11 15:07:23 · 318 阅读 · 0 评论 -
1549:最大数
const int limit=2e5;const int N=2e5+5; int n,m,t; int i,j,k; int a[N<<2];void build(int l,int r,int id){ if(l==r) return ; a[id]=-inf; int mid=l+1>>1; build(l,mid,id<<1); build(mid+1,r,id<<1...原创 2020-08-02 21:44:02 · 521 阅读 · 0 评论 -
1547:区间和 (线段树模板)
【输入样例】10 200 1 101 1 40 6 61 4 101 8 91 4 90 10 21 1 80 2 101 3 90 7 80 3 100 1 11 3 81 6 90 5 51 1 80 4 21 2 80 1 1【输出样例】1060616624145041const int N=1e5+5; int n,m,t; int i,j,k; ll sum[N*4];void b...原创 2020-07-31 23:12:22 · 330 阅读 · 0 评论 -
1625: 反素数 Antiprime
假设质因数 p1<p2<p3<……<pn,那么一定有质因数的指数 t1>=t2>=t3……>=tn,这样才能保证反素数的定义这样我们只需要注意质因数的指数就好了,题目给出限制条件约束总数小于 n 的约数总数,所以当约束总数相同时,取最小的当前值,当约束总数更多时,直接替换就好质数表打到第十位,因为后面的质数想拥有指数,那么前面质数的指数必须更大 2*3*5*7*11*17*19*21*23 再向后枚举就超数据范围了const int prime[...原创 2020-07-14 17:43:29 · 571 阅读 · 0 评论 -
1626:Hankson 的趣味题
int main(){ IOS; rush(){ int a,b,fa,fb; cin>>a>>fa>>b>>fb; int ans=0; for(int i=1;i*i<b;i++){//枚举 b 的约数 if(b%i==0){ int x=fb/b*i; if(__gc...原创 2020-07-14 08:30:34 · 317 阅读 · 0 评论 -
1632:[NOIP2012]同余方程
void Exgcd(ll a,ll b,ll &d,ll &x,ll &y){ if(!b){ x=1; y=0; d=a; } else{ Exgcd(b,a%b,d,x,y); ll tmp=x; x=y; y=tmp-a/b*y; }}int main(){ IOS; ll a,b,x,y,d; cin>>a>...原创 2020-07-13 22:41:23 · 224 阅读 · 0 评论 -
1624:樱花
const int N=1e6+5; int n,m; double t; int i,j,k; int id[N],prime[N],num; int cnt[N];void init(){ for(int i=2;i<N;i++){ if(!id[i]){ prime[++num]=i; id[i]=num; } for(int j=1;j<=num && prime[j]*i&l...原创 2020-07-07 23:28:38 · 516 阅读 · 0 评论 -
1572:括号配对
const int N=400+5; int n,m,t; int i,j,k; //int a[N]; char ch[N]; int dp[N][N]; int main(){ IOS; while(cin>>ch+1){ n=strlen(ch+1); for(int len=2;len<=n;len++){ for(int i=1;i+len-1&l...原创 2020-06-30 17:13:20 · 479 阅读 · 0 评论 -
1570:能量项链
【题目描述】题做多了总会遇到重复的:原博客点击这里const int N=400+5; int n,m,t; int i,j,k; int a[N]; int head[N],tail[N]; int dp[N][N]; int main(){ IOS; while(cin>>n){ for(i=1;i<=n;i++) cin>>head[i],head[i+n]=head[i.原创 2020-06-30 16:58:10 · 414 阅读 · 0 评论 -
1569:石子合并
方程:dp[i][j]=dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]环形 dp 模板题const int N=400+5; int n,m,t; int i,j,k; int a[N]; int sum[N],dp_max[N][N],dp_min[N][N]; int main(){ IOS; while(cin>>n){ for(i=1;i<=n;i++){ ...原创 2020-06-30 16:40:12 · 576 阅读 · 0 评论 -
1001:Hello,World!
#include <iostream>using namespace std;int main(){ cout<<"Hello,World!"; return 0;}原创 2020-06-29 23:55:11 · 218 阅读 · 0 评论 -
1005:地球人口承载力估计
#include <iostream>#include <cstdio>using namespace std;int main(){ int x,a,y,b; cin>>x>>a>>y>>b; printf("%.2lf\n",1.0*( ( x*a-y*b ) / (a-b) ) ); return 0;}原创 2020-06-29 23:54:15 · 1560 阅读 · 2 评论 -
1003:对齐输出
#include <iostream>#include <cstdio>using namespace std;int main(){ int a,b,c; cin>>a>>b>>c; printf("%8d %8d %8d\n",a,b,c); //system("pause"); return 0;}原创 2020-06-29 23:49:53 · 354 阅读 · 0 评论 -
1004:字符三角形
#include <iostream>using namespace std;int main(){ char ch; cin>>ch; cout<<" "<<ch<<endl; cout<<" "<<ch<<ch<<ch<<endl; cout<<ch<<ch<<ch<<ch<&...原创 2020-06-28 22:36:42 · 284 阅读 · 0 评论