2021.11.30 eleveni的水省选题的记录
2021.11.30 eleveni的水省选题的记录
因为eleveni比较菜,eleveni决定先刷图论,再刷数据结构,同时每天都要刷dp。当然,对于擅长的图论,eleveni决定从蓝题开始刷。当然,eleveni的神秘好友崇青云会监督eleveni刷题。
图论:
[P1772 ZJOI2006]物流运输 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
//#define int long long
const int N=410;
int n,m,k,e,dis[N],vis[N],dp[N][N],mapi[N][N],no[N];
typedef long long ll;
ll f[N];
int cnt,head[N];
struct node{
int to,next,val;
}a[N*2];
struct nodei{
int pos,dis;
bool operator <(const nodei &b)const{
return dis>b.dis;
}
};
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
inline void add(int u,int v,int w){
++cnt;
a[cnt].to=v;
a[cnt].val=w;
a[cnt].next=head[u];
head[u]=cnt;
}
inline void dijkstra(){
memset(dis,0x3f3f3f3f,sizeof(dis));
memset(vis,0,sizeof(vis));
dis[1]=0;
priority_queue<nodei>q;
q.push({1,0});
while(!q.empty()){
nodei tmp=q.top();q.pop();
int x=tmp.pos;
if(vis[x])continue;
vis[x]=1;
for(int i=head[x];i;i=a[i].next){
int v=a[i].to;
if(no[v])continue;
if(dis[v]>dis[x]+a[i].val){
dis[v]=dis[x]+a[i].val;
if(!vis[v])q.push({v,dis[v]});
}
}
}
}
signed main(){
n=read();m=read();k=read();e=read();
//cout<<n<<" "<<m<<" "<<k<<" "<<e<<endl;
for(int i=1;i<=e;i++){
int u,v,w;
u=read();v=read();w=read();
add(u,v,w);add(v,u,w);
//cout<<u<<" "<<v<<" "<<w<<endl;//
}
int d;d=read();
for(int i=1;i<=d;i++){
int t,x,y;
t=read();x=read();y=read();
for(int j=x;j<=y;j++)mapi[j][t]=1;
}
/*for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)cout<<mapi[i][j]<<" ";
cout<<endl;//
}
cout<<endl;//*/
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
memset(no,0,sizeof(no));
for(int ii=i;ii<=j;ii++)
for(int ji=1;ji<=m;ji++)
if(mapi[ii][ji])no[ji]=1;
dijkstra();
dp[i][j]=dis[m];
}
/*for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)cout<<dp[i][j]<<" ";
cout<<endl;//
}
cout<<endl;//*/
memset(f,0x7f,sizeof(f));
//cout<<f[1]<<endl;//
for(int i=1;i<=n;i++){
f[i]=1ll*dp[1][i]*i;
for(int j=i-1;j>=0;j--)
f[i]=min(f[i],f[j]+1ll*dp[j+1][i]*(i-j)+k);
}
cout<<f[n];
return 0;
}
[P1841 JSOI2007]重要的城市 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=210;
int n,m,f[N][N],dis[N][N],mapi[N][N];
int ans;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
int main(){
n=read();m=read();
memset(dis,0x3f3f3f3f,sizeof(dis));
memset(mapi,0x3f3f3f3f,sizeof(mapi));
for(int i=1;i<=m;i++){
int u,v,w;
u=read();v=read();w=read();
mapi[u][v]=dis[u][v]=f[u][v]=w;
mapi[v][u]=dis[v][u]=f[v][u]=w;
}
for(int i=1;i<=n;i++)mapi[i][i]=dis[i][i]=0;
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dis[i][j]=min(dis[i][k]+dis[k][j],dis[i][j]);
}
/*cout<<"mapi"<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)cout<<mapi[i][j]<<" ";
cout<<endl;
}
cout<<"dis"<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)cout<<dis[i][j]<<" ";
cout<<endl;
}
cout<<endl;*/
for(int h=1;h<=n;h++){
//memset(f,0x3f3f3f3f,sizeof(f));
memcpy(f,mapi,sizeof(mapi));
for(int i=1;i<=n;i++)f[i][h]=f[h][i]=0x3f3f3f3f;
for(int k=1;k<=n;k++)if(k!=h)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
int flag=0;
for(int i=1;i<=n;i++)if(i!=h)
for(int j=1;j<=n;j++)if(j!=h)
if(f[i][j]>dis[i][j]||f[i][j]==f[0][0])flag=1;
if(flag==1)cout<<h<<" ";
ans+=flag;
/*cout<<"h "<<h<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)cout<<f[i][j]<<" ";
cout<<endl;
}
cout<<endl;*/
}
if(!ans)cout<<"No important cities.";
//else cout<<ans;
return 0;
}
https://www.luogu.com.cn/problem/P4578
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define int long long
const int N=1010;
int t,n,m,k;
int cnt,head[N*2],vis[N*2],dis[N*2],cnti[N*2];
struct node{
int to,next,val;
}a[N*N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
inline void add(int u,int v,int w){
++cnt;
a[cnt].to=v;
a[cnt].val=w;
a[cnt].next=head[u];
head[u]=cnt;
}
inline bool spfa(int s){
queue<int>q;
memset(dis,0x3f3f3f3f,sizeof(dis));
dis[s]=0;
q.push(s);
while(!q.empty()){
int x=q.front();q.pop();
if(cnti[x]>n+m)return false;
++cnti[x];
vis[x]=0;
for(int i=head[x];i;i=a[i].next){
int v=a[i].to;
if(dis[v]>dis[x]+a[i].val){
dis[v]=dis[x]+a[i].val;
if(!vis[v])q.push(v),vis[v]=1;
}
}
}
return true;
}
signed main(){
t=read();
while(t--){
cnt=0;
memset(head,0,sizeof(head));
memset(vis,0,sizeof(vis));
memset(cnti,0,sizeof(cnti));
n=read();m=read();k=read();
for(int i=1;i<=k;i++){
int u,v,w;
u=read();v=read()+n;w=read();
add(u,v,w);
add(v,u,-w);
}
int start=n+m+1;
for(int i=1;i<=n+m;i++)add(start,i,0);
if(spfa(start))puts("Yes");
else puts("No");
}
return 0;
}
https://www.luogu.com.cn/problem/P2792
//只要买了就能享受优惠价
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=55;
const int inf=2e9;
int n,m,k,root,num[N],id[N],vis[N],pre[N],true_id[N];
double minn[N],price[N],ans,val[N];
struct node{
int from,to;
double val;
}a[N*N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
inline double zhuLiu(){
while(true){
for(int i=1;i<=n;i++)val[i]=inf;
for(int i=1;i<=m;i++){
int u=a[i].from,v=a[i].to;
if(u!=v&&val[v]>a[i].val)val[v]=a[i].val,pre[v]=u;
}
for(int i=1;i<=n;i++)if(i!=root&&val[i]==inf)return -1;
int cnt=0;
for(int i=1;i<=n;i++)id[i]=vis[i]=0;
for(int i=1;i<=n;i++){
if(i==root)continue;
ans+=val[i];
int v=i;
while(vis[v]!=i&&!id[v]&&v!=root)vis[v]=i,v=pre[v];
if(!id[v]&&v!=root){
id[v]=++cnt;
for(int u=pre[v];u!=v;u=pre[u])id[u]=cnt;
}
}
if(cnt==0)break;
for(int i=1;i<=n;i++)if(!id[i])id[i]=++cnt;
for(int i=1;i<=m;i++){
int u=a[i].from,v=a[i].to;
a[i].from=id[u];a[i].to=id[v];
if(a[i].from!=a[i].to)a[i].val-=val[v];
}
n=cnt;
root=id[root];
}
return ans;
}
int main(){
n=read();
int top=1;
root=1;
for(int i=1;i<=n;i++){
minn[i]=inf;
cin>>price[i];
num[i]=read();
if(!num[i])continue;
true_id[i]=++top;
minn[i]=min(minn[i],price[i]);
a[++m]={1,top,price[i]};
}
k=read();
for(int i=1;i<=k;i++){
int u,v;
double w;
u=read();v=read();cin>>w;
if(!true_id[u]||!true_id[v])continue;
minn[v]=min(minn[v],w);
a[++m]={true_id[u],true_id[v],w};
}
for(int i=1;i<=n;i++)if(num[i]>1)ans+=(num[i]-1)*minn[i];
n=top;
printf("%.2lf",zhuLiu());
return 0;
}
https://www.luogu.com.cn/problem/P3171
悲催的eleveni写挂了的网络流!为毛只有90分???
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define int long long
const int N=2010;
const int M=2e5+10;
const int inf=2e18;
int n,m,start,endi;
int cnt=1,head[N],dep[N],cur[N];
int cnti,headi[N],vis[N],dis[N];
struct node{
int to,next,val;
}e[M],a[M];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
inline void addi(int u,int v,int w){
++cnti;
e[cnti].to=v;
e[cnti].val=w;
e[cnti].next=headi[u];
headi[u]=cnti;
}
inline void spfa(int s){
queue<int>q;
for(int i=1;i<=n;i++)dis[i]=inf;
dis[s]=0;vis[s]=1;
q.push(s);
while(!q.empty()){
int x=q.front();q.pop();
vis[x]=0;
for(int i=headi[x];i;i=e[i].next){
int v=e[i].to;
if(dis[v]>dis[x]+e[i].val){
dis[v]=dis[x]+e[i].val;
if(!vis[v])vis[v]=1,q.push(v);
}
}
}
}
inline void addii(int u,int v,int w){
++cnt;
a[cnt].to=v;
a[cnt].val=w;
a[cnt].next=head[u];
head[u]=cnt;
}
inline void add(int u,int v,int w){
addii(u,v,w);addii(v,u,w);
}
inline int bfs(int s,int t){
queue<int>q;
memset(dep,0,sizeof(dep));
memcpy(cur,head,sizeof(head));
dep[s]=1;
q.push(s);
while(!q.empty()){
int x=q.front();q.pop();
for(int i=head[x];i;i=a[i].next){
int v=a[i].to;
if(!dep[v]&&a[i].val)dep[v]=dep[x]+1,q.push(v);
}
}
return dep[t];
}
inline int dfs(int x,int t,int f){
if(x==t)return f;
int ans=0;
for(int i=cur[x];i&&f>ans;i=a[i].next){
cur[x]=i;
int v=a[i].to;
int fi=0;
if(dep[v]==dep[x]+1&&a[i].val&&(fi=dfs(v,t,min(f-ans,a[i].val)))>0)
a[i].val-=fi,a[i^1].val+=fi,ans+=fi;
}
return ans;
}
inline int Dinic(int s,int t){
int flow=0;
while(bfs(s,t)){
int x=0;
if((x=dfs(s,t,inf))>0)flow+=x;
}
return flow;
}
signed main(){
n=read();m=read();
for(int i=1;i<=m;i++){
int u,v,w;
u=read();v=read();w=read();
addi(u,v,w);addi(v,u,w);
}
spfa(1);
for(int i=1;i<=n;i++)
for(int j=headi[i];j;j=e[j].next){
int v=e[j].to;
if(dis[v]==dis[i]+e[j].val)add(i+n,v,inf);
}
start=n*2+1,endi=n*2+2;
add(start,1,inf);add(n*2,endi,inf);
for(int i=1;i<=n;i++){
int x=read();
if(i==1||i==n)add(i,i+n,inf);
else add(i,i+n,x);
}
cout<<Dinic(start,endi);
return 0;
}
别人的满分代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int NR=1005+10;
const int MR=3e5+10;
const int INF=1e18;
void Min(int& x,int y){x=min(x,y);}
void Max(int& x,int y){x=max(x,y);}
int n,m;
int a[NR];
int to[MR*5],nxt[MR*5],val[MR*5];
int head[NR<<1];
int tot=1;
void add(int x,int y,int z)
{
to[tot]=y;
val[tot]=z;
nxt[tot]=head[x];
head[x]=tot++;
}
int s[MR],t[MR],v[MR];
bool vis[NR];
int dis[NR];
void spfa()
{
memset(vis,0,sizeof(vis));
memset(dis,0x3f,sizeof(dis));
dis[1]=0;vis[1]=1;queue<int>q;q.push(1);
while(!q.empty())
{
int x=q.front();q.pop();vis[x]=0;
for(int i=head[x];i;i=nxt[i])
{
int y=to[i];
if(dis[y]>dis[x]+val[i])
{
dis[y]=dis[x]+val[i];
if(!vis[y])vis[y]=1,q.push(y);
}
}
}
}
int S,T;
int dep[NR<<1];
int now[NR<<1];
bool bfs()
{
memcpy(now,head,sizeof(now));
memset(dep,0,sizeof(dep));
queue<int>q;q.push(S);dep[S]=1;
while(!q.empty())
{
int x=q.front();q.pop();
for(int i=head[x];i;i=nxt[i])
{
int y=to[i];if(!val[i]||dep[y])continue;
dep[y]=dep[x]+1;q.push(y);if(y==T)return 1;
}
}return 0;
}
int dinic(int x,int flow)
{
if(x==T)return flow;int mxflow=0;
for(int i=head[x];i;i=nxt[i])
{
if(flow==mxflow)return flow;
int y=to[i];now[x]=i;
if(!val[i]||dep[y]!=dep[x]+1)continue;
int num=dinic(y,min(val[i],flow-mxflow));
mxflow+=num;val[i]-=num,val[i*2-(i^1)]+=num;
}
return mxflow;
}
int read()
{
int x=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*f;
}
signed main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
n=read(),m=read();
for(int i=1;i<=m;i++)
{
int x=read(),y=read(),z=read();
s[i]=x,t[i]=y;v[i]=z;add(x,y,z),add(y,x,z);
}spfa();
memset(head,0,sizeof(head));tot=1;
for(int i=1;i<=m;i++)
{
if(dis[t[i]]==dis[s[i]]+v[i])add(s[i]+n,t[i],INF),add(t[i],s[i]+n,0);
if(dis[s[i]]==dis[t[i]]+v[i])add(t[i]+n,s[i],INF),add(s[i],t[i]+n,0);
}
for(int i=1;i<=n;i++)a[i]=read();S=1,T=n*2;
add(1,n+1,INF),add(n+1,1,0);add(n,n*2,INF),add(n*2,n,0);
for(int i=2;i<n;i++)add(i,i+n,a[i]),add(i+n,i,0);
int ans=0;while(bfs())ans+=dinic(S,INF);printf("%lld\n",ans);
return 0;
}
https://www.luogu.com.cn/problem/P2472
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int N=10000;
const int inf=(1<<30);
int n,m,maxn,top,h[25][25],true_id[25][25];
int start,endi,cnt=1,head[N],dep[N],cur[N];
struct node{
int to,next,val;
}a[N*2];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
inline void addi(int u,int v,int w){
++cnt;
a[cnt].to=v;
a[cnt].val=w;
a[cnt].next=head[u];
head[u]=cnt;
}
inline void add(int u,int v,int w){
addi(u,v,w);addi(v,u,0);
}
inline int bfs(int s,int t){
memset(dep,0,sizeof(dep));
memcpy(cur,head,sizeof(head));
queue<int>q;
dep[s]=1;
q.push(s);
while(!q.empty()){
int x=q.front();q.pop();
for(int i=head[x];i;i=a[i].next){
int v=a[i].to;
if(!dep[v]&&a[i].val)dep[v]=dep[x]+1,q.push(v);
}
}
return dep[t];
}
inline int dfs(int x,int t,int f){
if(x==t)return f;
int ans=0;
for(int i=cur[x];i&&f>ans;i=a[i].next){
cur[x]=i;
int v=a[i].to,fi=0;
if(a[i].val&&dep[v]==dep[x]+1&&(fi=dfs(v,t,min(f-ans,a[i].val)))>0)
a[i].val-=fi,a[i^1].val+=fi,ans+=fi;
}
return ans;
}
inline int Dinic(int s,int t){
int flow=0;
while(bfs(s,t)){
int x=0;
if((x=dfs(s,t,inf))>0)flow+=x;
}
return flow;
}
int main(){
n=read();m=read();maxn=read();
for(int i=1;i<=n;i++){
string s;cin>>s;
for(int j=1;j<=m;j++){
h[i][j]=s[j-1]-'0';
if(h[i][j])true_id[i][j]=++top;
}
}
/*cout<<"h"<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)cout<<h[i][j]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"true_id"<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)cout<<true_id[i][j]<<" ";
cout<<endl;
}*/
start=top*2+1,endi=top*2+2;
int tot=0;
//cout<<"top "<<top<<" start "<<start<<" endi "<<endi<<endl;//
for(int i=1;i<=n;i++){
string s;cin>>s;
for(int j=1;j<=m;j++){
if(s[j-1]=='L'&&h[i][j])
add(start,true_id[i][j],1),++tot;
if(h[i][j])
add(true_id[i][j],true_id[i][j]+top,h[i][j]);
if(h[i][j]&&(i-maxn<=0||(n-i+1)<=maxn||j-maxn<=0||(m-j+1)<=maxn))
add(true_id[i][j]+top,endi,inf);//,cout<<"Case 1 "<<true_id[i][j]<<endl;
}
}
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(h[i][j]){
for(int k=1;k<=n;k++)for(int l=1;l<=m;l++)if(!(k==i&&l==j))
if(h[k][l]&&(i-k)*(i-k)+(j-l)*(j-l)<=maxn*maxn)
add(true_id[i][j]+top,true_id[k][l],inf);//,cout<<true_id[i][j]<<" "<<true_id[k][l]<<endl;
}
cout<<tot-Dinic(start,endi);
return 0;
}
https://www.luogu.com.cn/problem/P3324
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define int long long
const int N=210;
const int inf=(1<<30);
int n,m,A[N],B[N],attack[N][N];
int start,endi,sum;
int cnt=1,head[N],cur[N],dep[N];
struct node{
int to,next,val;
}a[N*N*10];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
inline void addi(int u,int v,int w){
++cnt;
a[cnt].to=v;
a[cnt].val=w;
a[cnt].next=head[u];
head[u]=cnt;
}
inline void add(int u,int v,int w){
//cout<<" Case 3 "<<u<<" "<<v<<" "<<w<<endl;
addi(u,v,w);addi(v,u,0);
}
inline int bfs(int s,int t){
memset(dep,0,sizeof(dep));
memcpy(cur,head,sizeof(head));
queue<int>q;
dep[s]=1;
q.push(s);
while(!q.empty()){
int x=q.front();q.pop();
for(int i=head[x];i;i=a[i].next){
int v=a[i].to;
if(!dep[v]&&a[i].val)dep[v]=dep[x]+1,q.push(v);
}
}
return dep[t];
}
inline int dfs(int x,int t,int f){
if(x==t)return f;
int ans=0;
for(int i=cur[x];i&&f>ans;i=a[i].next){
cur[x]=i;
int v=a[i].to,fi=0;
if(a[i].val&&dep[v]==dep[x]+1&&(fi=dfs(v,t,min(f-ans,a[i].val)))>0)
a[i].val-=fi,a[i^1].val+=fi,ans+=fi;
}
return ans;
}
inline int Dinic(int s,int t){
int flow=0;
while(bfs(s,t)){
//cout<<" Case 2"<<endl;//
int x=0;
if((x=dfs(s,t,inf<<1))>0)flow+=x;//,cout<<x<<endl;
}
return flow;
}
inline int check(int timei){
for(int i=1;i<=m;i++)B[i]*=timei;
memset(head,0,sizeof(head));
cnt=1;
for(int i=1;i<=n;i++)add(i+m,endi,A[i]);
for(int i=1;i<=m;i++)add(start,i,B[i]);
for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)if(attack[i][j])add(i,j+m,inf);//,cout<<i<<" "<<j<<endl;
//cout<<"Case 1"<<endl;//
int now=Dinic(start,endi);
//cout<<now<<endl;//
int ans=(now>=sum);
for(int i=1;i<=m;i++)B[i]/=timei;
return ans;
}
signed main(){
n=read();m=read();
for(int i=1;i<=n;i++)A[i]=read()*10000,sum+=A[i];//,cout<<A[i]<<" ";cout<<endl;
for(int i=1;i<=m;i++)B[i]=read();//,cout<<B[i]<<" ";cout<<endl;//
for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)attack[i][j]=read();
start=n+m+1;endi=n+m+2;
int L=0,R=1e9+10,mid,ans=0;
while(L<R){
mid=(L+R)>>1;
//cout<<mid<<endl;
if(check(mid))R=mid,ans=mid;
else L=mid+1;
}
printf("%.6lf",(double)ans/10000);
return 0;
}
https://www.luogu.com.cn/problem/P4001
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int N=1e6+10;
const int inf=(1<<30);
int n,m;
int cnt=1,head[N],dep[N],cur[N];
struct node{
int to,next,val;
}a[N*6];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
inline void addi(int u,int v,int w){
++cnt;
a[cnt].to=v;
a[cnt].val=w;
a[cnt].next=head[u];
head[u]=cnt;
}
inline void add(int u,int v,int w){
addi(u,v,w);addi(v,u,w);
}
inline int bfs(int s,int t){
memset(dep,0,sizeof(dep));
memcpy(cur,head,sizeof(head));
queue<int>q;
dep[s]=1;
q.push(s);
while(!q.empty()){
int x=q.front();q.pop();
for(int i=head[x];i;i=a[i].next){
int v=a[i].to;
if(!dep[v]&&a[i].val)dep[v]=dep[x]+1,q.push(v);
}
}
return dep[t];
}
inline int dfs(int x,int t,int f){
if(x==t)return f;
int ans=0;
for(int i=cur[x];i&&f>ans;i=a[i].next){
cur[x]=i;
int v=a[i].to,fi=0;
if(a[i].val&&dep[v]==dep[x]+1&&(fi=dfs(v,t,min(f-ans,a[i].val)))>0)
a[i].val-=fi,a[i^1].val+=fi,ans+=fi;
}
return ans;
}
inline int Dinic(int s,int t){
int flow=0;
while(bfs(s,t)){
int x=0;
if((x=dfs(s,t,inf))>0)flow+=x;
}
return flow;
}
inline int id(int x,int y){
return (x-1)*m+y;
}
int main(){
n=read();m=read();
for(int i=1;i<=n;i++)for(int j=1;j<m;j++){
int x=read();
add(id(i,j),id(i,j+1),x);
}
for(int i=1;i<n;i++)for(int j=1;j<=m;j++){
int x=read();
add(id(i,j),id(i+1,j),x);
}
for(int i=1;i<n;i++)for(int j=1;j<m;j++){
int x=read();
add(id(i,j),id(i+1,j+1),x);
}
cout<<Dinic(1,n*m);
return 0;
}
https://www.luogu.com.cn/problem/P5043
树哈希
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define int long long
const int N=1001;
int n,m,ans[N][N];
int cnt,head[N];
struct node{
int to,next;
}a[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
inline void add(int u,int v){
++cnt;
a[cnt].to=v;
a[cnt].next=head[u];
head[u]=cnt;
}
inline int Hash(int x,int f){
int q[N],top=0,now=N;
memset(q,0,sizeof(q));
for(int i=head[x];i;i=a[i].next){
int v=a[i].to;
if(v==f)continue;
q[++top]=Hash(v,x);
}
sort(q+1,q+top+1);
for(int i=1;i<=top;i++)now=now*2333+q[i];
return now*2333+N+1;
}
signed main(){
m=read();
for(int i=1;i<=m;i++){
n=read();
memset(head,0,sizeof(head));
cnt=0;
for(int j=1;j<=n;j++){
int x=read();
if(x)add(x,j),add(j,x);
}
for(int j=1;j<=n;j++)ans[i][j]=Hash(j,0);
sort(ans[i]+1,ans[i]+n+1);
for(int j=1,k=0;j<=i;j++){
while(k<=n)if(ans[i][++k]!=ans[j][k])break;
if(k>n){
cout<<j<<endl;
break;
}
}
}
/*for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++)cout<<ans[i][j]<<" ";
cout<<endl;
}
cout<<endl;*/
return 0;
}
动态规划:
https://www.luogu.com.cn/problem/P2327
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e4+10;
int n,num[N],f[N][2][2];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
int main(){
n=read();
for(int i=1;i<=n;i++)num[i]=read();
f[0][0][0]=f[0][0][1]=1;
for(int i=1;i<=n;i++){
if(num[i]==0)f[i][0][0]+=f[i-1][0][0];
else if(num[i]==1){
f[i][0][0]+=f[i-1][1][0];
f[i][1][0]+=f[i-1][0][1];
f[i][0][1]+=f[i-1][0][0];
}else if(num[i]==2){
f[i][1][0]+=f[i-1][1][1];
f[i][0][1]+=f[i-1][1][0];
f[i][1][1]+=f[i-1][0][1];
}else if(num[i]==3)f[i][1][1]+=f[i-1][1][1];
}
cout<<f[n][0][0]+f[n][1][0];
return 0;
}
https://www.luogu.com.cn/problem/P5414
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=110;
int t,n,a[N],f[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
int main(){
t=read();
while(t--){
memset(f,0,sizeof(f));
n=read();
for(int i=1;i<=n;i++)a[i]=read();
for(int i=1;i<=n;i++){
for(int j=1;j<i;j++)if(a[j]<=a[i])f[i]=max(f[i],f[j]);
f[i]+=a[i];
}
int maxn=0,tot=0;
for(int i=1;i<=n;i++)tot+=a[i],maxn=max(maxn,f[i]);
cout<<tot-maxn<<endl;
}
return 0;
}
https://www.luogu.com.cn/problem/P2513
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1010;
const int mod=1e4;
int n,k,f[N][N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
int main(){
n=read();k=read();
f[1][0]=1;
for(int i=2;i<=n;i++){
int sum=0;
for(int j=0;j<=k;j++){
sum+=f[i-1][j];sum%=mod;
f[i][j]=sum;
if(j-i+1>=0)sum-=f[i-1][j-i+1],sum=(sum%mod+mod)%mod;
}
}
cout<<f[n][k];
return 0;
}
数论:
除法分块
https://www.luogu.com.cn/problem/P2261
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define int long long
int n,k,ans;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
signed main(){
n=read();k=read();
ans=1ll*n*k;
n=min(n,k);
for(int L=1,R=0;L<=n;L=R+1){
R=min(n,k/(k/L));
ans-=1ll*(k/L)*(L+R)*(R-L+1)/2;
}
cout<<ans;
return 0;
}
基础算法:
https://www.luogu.com.cn/problem/P2434
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=5e4+10;
int n;
struct node{
int from,to;
bool operator <(const node &b)const{
return from<b.from;
}
}a[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
int main(){
n=read();
for(int i=1;i<=n;i++)cin>>a[i].from>>a[i].to;
sort(a+1,a+n+1);
a[n+1].from=1000010;
int L=a[1].from,R=a[1].to;
for(int i=2;i<=n+1;i++){
if(a[i].from<=R)R=max(R,a[i].to);
else{
cout<<L<<" "<<R<<endl;
L=a[i].from;R=a[i].to;
}
}
return 0;
}
https://www.luogu.com.cn/problem/P3252
这是道搜索题,鬼知道为啥标签是动态规划
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e6+10;
int n,s,sum[N],num[N],val[N];
int cnt,head[N],ans;
struct node{
int to,next;
}a[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
inline void add(int u,int v){
++cnt;
a[cnt].to=v;
a[cnt].next=head[u];
head[u]=cnt;
}
inline void dfs(int x,int fa){
sum[x]=sum[fa]+val[x];
if(sum[x]>=s&&num[sum[x]-s]>0)++ans;
++num[sum[x]];
for(int i=head[x];i;i=a[i].next){
int v=a[i].to;
dfs(v,x);
}
--num[sum[x]];
}
int main(){
n=read();s=read();
num[0]=1;
for(int i=1;i<=n;i++)val[i]=read();
for(int i=1;i<n;i++){
int u,v;
u=read();v=read();
add(u,v);
}
dfs(1,0);
cout<<ans;
return 0;
}
2021.11.30 eleveni的水省选题的记录的更多相关文章
- 2021.11.05 eleveni的水省选题的记录
2021.11.05 eleveni的水省选题的记录 因为eleveni比较菜,但是eleveni不想写绿题(总不能说是被绿题虐得不想写),eleveni决定继续水noip原题. --实际上菜菜的el ...
- 2021.11.02 eleveni的水省选题的记录
2021.11.02 eleveni的水省选题的记录 因为eleveni比较菜,所以eleveni决定从绿题开始水 --实际上菜菜的eleveni连绿题都不一定能水过/忍不住哭了 [P2217 HAO ...
- 2021.12.16 eleveni的刷题记录
2021.12.16 eleveni的刷题记录 1. 数论 https://www.luogu.com.cn/problem/P2532 1.1卡特兰数 https://www.luogu.com.c ...
- 日常Javaweb 2021/11/19
Javaweb Dao层: //连接数据库,实现增查功能 package dao; import java.sql.Connection; import java.sql.DriverManager; ...
- 2021.12.21 eleveni的刷题记录
2021.12.21 eleveni的刷题记录 0. 有意思的题 P6701 [POI1997] Genotype https://www.luogu.com.cn/problem/P6701 状压优 ...
- 2021.11.09 P4824 [USACO15FEB]Censoring S与P3121 [USACO15FEB]Censoring G(KMP&&AC自动机)
2021.11.09 P4824 [USACO15FEB]Censoring S与P3121 [USACO15FEB]Censoring G(KMP&&AC自动机) https://w ...
- 2021.11.09 P2292 [HNOI2004]L语言(trie树+AC自动机)
2021.11.09 P2292 [HNOI2004]L语言(trie树+AC自动机) https://www.luogu.com.cn/problem/P2292 题意: 标点符号的出现晚于文字的出 ...
- 黑盒测试实践--Day6 11.30
黑盒测试实践--Day6 11.30 今天完成任务情况: 应用设计的场景用例,完成测试用例的编写 完成测试用例在自动化测试工具QTP上的测试 分析测试结果得到缺陷报告 小靳 软件测试 今天主要钻研了q ...
- 日常Java 2021/11/18
用idea实现Javaweb登录页面 <%-- Created by IntelliJ IDEA. User: Tefuir Date: 2021/11/18 Time: 18:14 To ch ...
随机推荐
- Linux移植实际操作一
@ 目录 *前言 目前看了很多关于"Linux移植"的的各种教程.书籍,看完发现不过是对已有板子.已有驱动进行启用.禁用.参数修改.只能叫做"Linux配置". ...
- 域渗透 | kerberos认证及过程中产生的攻击
文章首发于公众号<Z2O安全攻防> 直接公众号文章复制过来的,排版可能有点乱, 可以去公众号看. https://mp.weixin.qq.com/s/WMGkQoMnQdyG8UmS ...
- winform 代码生成textbox ,checkbox
参考地址:https://jingyan.baidu.com/article/380abd0a6b80701d90192cde.html 首先搭建好Winform项目框架后,创建窗体页面后自行布局 这 ...
- loj#6072 苹果树(折半搜索,矩阵树定理,容斥)
loj#6072 苹果树(折半搜索,矩阵树定理,容斥) loj 题解时间 $ n \le 40 $ . 无比精确的数字. 很明显只要一个方案不超过 $ limits $ ,之后的计算就跟选哪个没关系了 ...
- POI完成Excel文件的读和写
简介 Apache POI 是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office(Excel.WORD.PowerPo ...
- Ubuntu16.04 oh_my_zsh 安装与配置
参考文章 Ubuntu上使终端显示Git分支(oh-my-zsh) oh-my-zsh的安装与基本配置 Ubuntu 下安装oh-my-zsh 前言 之前学习Laravel的时候,经常要切换git分支 ...
- 半吊子菜鸟学Web开发5 -- PHP开发环境配置
本文参考自:http://blog.csdn.net/angon823/article/details/54415855 Ubuntu16.04 默认 apt-get install apache2 ...
- Vue指令02——v-on指令和v-show的使用
Vue指令02--v-on指令和v-show的使用 v-on指令 格式1:v-on:事件="方法" 格式2:@事件="方法" 格式3:@事件="方法( ...
- Aspect 切面?
AOP核心就是切面,它将多个类的通用行为封装成可重用的模块,该模块含有一组API提供横切功能.比如,一个日志模块可以被称作日志的AOP切面.根据需求的不同,一个应用程序可以有若干切面.在Spring ...
- Java 中能创建 volatile 数组吗?
能,Java 中可以创建 volatile 类型数组,不过只是一个指向数组的引用,而不 是整个数组.我的意思是,如果改变引用指向的数组,将会受到 volatile 的保护, 但是如果多个线程同时改变数 ...