三个签到一个提答,6
A.签到题
之前考过的,不知道咋网络流证明
点击查看代码
#include <bits/stdc++.h>
typedef long long ll;typedef unsigned long long ull; typedef double db;typedef long double ldb;
#define fre(x) freopen(#x ".in","r",stdin),freopen(#x ".out","w",stdout)
#define Rep(i,a,b) for(int i=a;i<=b;++i)
#define Dwn(i,a,b) for(int i=a;i>=b;--i)
#define pii pair<int,int>
#define mair make_pair
#define fir first
#define sec second
using namespace std;
const int maxn=1e6+10;
int n,m,K,C;
bool vis[maxn];
int ins[maxn];
void solve(){
cin>>n>>m>>K>>C;int x,y;
Rep(i,1,K){ cin>>x>>y; ++ins[x],++ins[y+n]; }
n+=m;m=0;
Rep(i,1,n)m+=(ins[i]%C!=0);
cout<<m<<"\n";
}
int main (){ fre(qiandao);ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);return solve(),0; }
B.M弟娃
区间加全局max
点击查看代码
#include <bits/stdc++.h>
typedef long long ll;typedef unsigned long long ull; typedef double db;typedef long double ldb;
#define fre(x) freopen(#x ".in","r",stdin),freopen(#x ".out","w",stdout)
#define Rep(i,a,b) for(int i=a;i<=b;++i)
#define Dwn(i,a,b) for(int i=a;i>=b;--i)
#define pii pair<int,int>
#define mair make_pair
#define fir first
#define sec second
using namespace std;
const int maxn=3e5+10;
struct Seg{
struct Tree{ int val,lazy; }tr[maxn<<2];
void Pushup(int rt){ tr[rt].val=max(tr[rt<<1].val,tr[rt<<1|1].val); }
void Update(int rt,int w){ tr[rt].val+=w,tr[rt].lazy+=w; }
void Pushdown(int rt){ if(tr[rt].lazy)Update(rt<<1,tr[rt].lazy),Update(rt<<1|1,tr[rt].lazy),tr[rt].lazy=0; }
void Modify(int rt,int l,int r,int s,int t,int w){
if(s>t)return;
if(s<=l && t>=r)return Update(rt,w);
int mid=(l+r)>>1;Pushdown(rt);
if(s<=mid)Modify(rt<<1,l,mid,s,t,w);
if(t>mid)Modify(rt<<1|1,mid+1,r,s,t,w);
Pushup(rt);
}
}T;
int n,m;
struct Graph{
struct eg{ int from,to,next; }e[maxn*2];
int len,head[maxn];
void lqx(int from,int to)
{ e[++len].from=from,e[len].to=to,e[len].next=head[from],head[from]=len; }
int siz[maxn],son[maxn],dep[maxn],top[maxn],dfn[maxn],rk[maxn],Te,fa[maxn];
void Dfs1(int u){
siz[u]=1;dep[u]=dep[fa[u]]+1;
for(int i=head[u];i;i=e[i].next){
int v=e[i].to;if(v==fa[u])continue;
fa[v]=u;Dfs1(v);siz[u]+=siz[v];
if(!son[u] || siz[v]>siz[son[u]])son[u]=v;
}
}
void Dfs2(int u,int tp){
top[u]=tp;dfn[u]=++Te;rk[Te]=u;
if(son[u])Dfs2(son[u],tp);
for(int i=head[u];i;i=e[i].next){
int v=e[i].to;if(v==fa[u] || v==son[u])continue;
Dfs2(v,v);
}
}
int Lca(int u,int v){
while(top[u]!=top[v]){
if(dep[top[u]]<dep[top[v]])swap(u,v);
u=fa[top[u]];
}
return dep[u]<dep[v] ? u : v;
}
int Fa(int u,int k){
if(k<=0)return u;
while(k){
int len=min(k,dep[u]-dep[top[u]]);
u=rk[dfn[u]-len];k-=len;
if(!k)break;
--k;u=fa[u];
}
return u;
}
}G;
void Sol(int u,int v){
int lf=G.Lca(u,v);
if(u==v)return T.Modify(1,1,n,1,n,1);
if(lf!=u && lf!=v){
T.Modify(1,1,n,G.dfn[u],G.dfn[u]+G.siz[u]-1,1);
T.Modify(1,1,n,G.dfn[v],G.dfn[v]+G.siz[v]-1,1);
}else{
if(u!=lf)swap(u,v);
int kf=G.Fa(v,G.dep[v]-G.dep[u]-1);
T.Modify(1,1,n,1,n,1);
T.Modify(1,1,n,G.dfn[kf],G.dfn[kf]+G.siz[kf]-1,-1);
T.Modify(1,1,n,G.dfn[v],G.dfn[v]+G.siz[v]-1,1);
}
}
void solve(){
cin>>n>>m;
Rep(i,2,n){ int x,y;cin>>x>>y;G.lqx(x,y),G.lqx(y,x); }
G.Dfs1(1),G.Dfs2(1,1);
while(m--){
int x,y;
cin>>x>>y;Sol(x,y);
cout<<T.tr[1].val<<"\n";
}
}
int main (){ fre(magic);ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);return solve(),0; }
C.变异大老鼠
最短路树唯一,就是一树上背包。
点击查看代码
#include <bits/stdc++.h>
typedef long long ll;typedef unsigned long long ull; typedef double db;typedef long double ldb;
#define fre(x) freopen(#x ".in","r",stdin),freopen(#x ".out","w",stdout)
#define Rep(i,a,b) for(int i=a;i<=b;++i)
#define Dwn(i,a,b) for(int i=a;i>=b;--i)
#define pii pair<int,int>
#define mair make_pair
#define fir first
#define sec second
using namespace std;
const int maxn=3e2+10;
int n,m,K;
struct Graph{
struct eg{ int from,to,next,dis; }e[maxn*maxn];
int len,head[maxn];
void lqx(int from,int to,int dis)
{ e[++len].from=from,e[len].to=to,e[len].next=head[from],head[from]=len;e[len].dis=dis; }
ll dis[maxn];int pre[maxn];bool vis[maxn];
priority_queue<pii>q;
void Dij(){
memset(dis,0x3f,sizeof(dis));
dis[1]=0;q.emplace(0,1);
while(!q.empty()){
int u=q.top().sec;q.pop();
if(vis[u])continue;
vis[u]=true;
for(int i=head[u];i;i=e[i].next){
int v=e[i].to;
if(dis[u]+e[i].dis<dis[v]){ dis[v]=dis[u]+e[i].dis;pre[v]=u;q.emplace(-dis[v],v); }
}
}
}
}G;
double P[maxn][maxn],f[maxn][maxn],g[maxn],tmp[maxn];
struct Tree{
vector<int>E[maxn];
void lqx(int u,int v){ E[u].emplace_back(v);/*cerr<<u<<" "<<v<<"\n";*/ }
void Dfs(int u){
if(E[u].empty()){ Rep(i,1,K)f[u][i]=P[u][i]; return; }
for(auto v : E[u])Dfs(v);
Rep(i,0,K)tmp[i]=g[i]=0;
for(auto v : E[u]){
Rep(i,0,K)Rep(j,0,K-i)
tmp[i+j]=max(tmp[i+j],g[i]+f[v][j]);
Rep(i,0,K){ g[i]=max(g[i],tmp[i]);tmp[i]=0; }
}
int siz=E[u].size();
Rep(i,1,K)g[i]/=siz;
Rep(i,0,K)Rep(j,0,K-i)f[u][i+j]=max(f[u][i+j],P[u][i]+(1-P[u][i])*g[j]);
}
}T;
void solve(){
cin>>n>>m>>K;
Rep(i,1,m){ int u,v,w;cin>>u>>v>>w;G.lqx(u,v,w),G.lqx(v,u,w); }
G.Dij();Rep(i,2,n)if(G.pre[i])T.lqx(G.pre[i],i);
Rep(i,1,n)Rep(j,1,K)cin>>P[i][j];
T.Dfs(1);double ans=f[1][K];
Rep(i,1,K)ans=max(ans,f[1][i]);
cout<<fixed<<setprecision(6)<<ans<<"\n";
}
int main (){ fre(arrest);ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);return solve(),0; }
D.朝鲜时蔬
题解写的很好,不复读了,直接粘了。
对于\((4,3)\)的做法,另一种式子是
\[\left [ \frac{x^n}{n!} \right ] \frac{ 1 }{ 1-x } ( F(x)^3-3F(x^2)F(x)+2F(x^3) ) \]即
\[\binom{n}{3}-3 \sum_{1}^{n-3}(i+1)[2 \mid n-3-i] + 2\left \lfloor \frac{n}{3} \right \rfloor \]题解截图
![image](/i/l/?n=23&i=blog/2110526/202302/2110526-20230211163236026-1554628637.png)
![image](/i/l/?n=23&i=blog/2110526/202302/2110526-20230211163239362-179157304.png)
![image](/i/l/?n=23&i=blog/2110526/202302/2110526-20230211163242734-523825846.png)
![image](/i/l/?n=23&i=blog/2110526/202302/2110526-20230211163245525-331334255.png)
![image](/i/l/?n=23&i=blog/2110526/202302/2110526-20230211163250302-1253030002.png)
![image](/i/l/?n=23&i=blog/2110526/202302/2110526-20230211163255498-1289974963.png)
![image](/i/l/?n=23&i=blog/2110526/202302/2110526-20230211163259515-1721718121.png)