跳到正文

个人记录

暑假做题记录

Wander_Taraxacum约 17 分钟
原文
文章信息与版本

文章信息

发布
2026年7月6日
收录
2026年7月28日
更新
2026年11月11日
篇幅
约 17 分钟

版本

  1. v1当前

P11858 [CCC 2025 Senior] 破译 / Cryptogram Cracking Club

EZ题目,不讲。

code
C++
//Code By Sky_Dream

/*
It's been a long day.
Without my friend.
And I'll tell you all about it when I see you again.
We've come a long way,
From where we began.
Oh I'll tell you all about it when I see you again.
When I see you again.
Oh,who know,all the planes we flew,
good things we had been drew
That something told me right here talking with you.
*/

//#pragma GCC optimize(1)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define dep(i,x,y) for(int i=x;i>=y;--i)
#define int long long
#define N 200005
#define endl "\n"
#define MAX 1145141919810
using namespace std;
inline int read(){
	int ret=0,sgn=0,ch=getchar();
	while(!isdigit(ch))sgn|=ch=='-',ch=getchar();
	while(isdigit(ch))ret=ret*10+ch-'0',ch=getchar();
	return sgn?-ret:ret;
}
string s;
int c,len[N],tot;
char a[N];
inline void Feather(){
	freopen("decode.in","r",stdin);
	freopen("decode.out","w",stdout);
	//ios::sync_with_stdio(0);
	//cin.tie(0);cout.tie(0);
	//mt19937 Rand(time(0));
	cin>>s>>c;
	int i=0,x=1;
	while(i<=s.size()-1){
		a[x]=s[i];++i;
		while('0'<=s[i]&&s[i]<='9')len[x]=len[x]*10+(s[i]-'0'),++i;
		tot+=len[x];
		++x;
	}--x;
//	rep(i,1,x)cout<<a[i]<<' '<<len[i]<<endl;
//	cout<<c;
	c=c%tot;
	int ans=0;
	rep(j,1,x){
		ans+=len[j];
		if(ans>=c+1){cout<<a[j];break;}
	}
}
signed main(){Feather();return 0;}

P11859 [CCC 2025 Senior] 画画 / Pretty Pens

并查集就做完了。学习用 multiset 练手。

code
C++
//Code By Sky_Dream

/*
It's been a long day.
Without my friend.
And I'll tell you all about it when I see you again.
We've come a long way,
From where we began.
Oh I'll tell you all about it when I see you again.
When I see you again.
Oh,who know,all the planes we flew,
good things we had been drew
That something told me right here talking with you.
*/

//#pragma GCC optimize(1)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define dep(i,x,y) for(int i=x;i>=y;--i)
#define int long long
#define N 200005
#define endl "\n"
#define MAX 1145141919810
using namespace std;
inline int read(){
	int ret=0,sgn=0,ch=getchar();
	while(!isdigit(ch))sgn|=ch=='-',ch=getchar();
	while(isdigit(ch))ret=ret*10+ch-'0',ch=getchar();
	return sgn?-ret:ret;
}
struct node{int id,x;};
int n,m,q,c[N],p[N],sum;
multiset<node>s[N],a,b;
inline bool operator<(const node &x,const node &y){
    if(x.x!=y.x)return x.x>y.x;
    return x.id<y.id;
}
inline void del(int u){
    auto tmp=a.lower_bound(*s[u].begin());
	auto &bb=s[u];
	int val=bb.begin()->x;
	sum=sum-val;
    a.erase(tmp);
    if(s[u].size()>1){
        tmp=b.lower_bound(*next(s[u].begin()));
        b.erase(tmp);
    }
}
inline void add(int u){
    auto &bb=s[u];
	int val=bb.begin()->x;
	sum=sum+val;
    a.insert(*s[u].begin());
    if(s[u].size()>1)b.insert(*next(s[u].begin()));
}
inline void Feather(){
	freopen("paint.in","r",stdin);
	freopen("paint.out","w",stdout);
	//ios::sync_with_stdio(0);
	//cin.tie(0);cout.tie(0);
	//mt19937 Rand(time(0));
	n=read(),m=read(),q=read();
	rep(i,1,n){
	    c[i]=read();p[i]=read();
	    s[c[i]].insert({i,p[i]});
	}
	rep(i,1,m)add(i);
	int A=b.begin()->x,B=prev(a.end())->x;
	if(b.size()>0)
		if(A>B)cout<<sum-B+A<<endl;
		else cout<<sum<<endl;
	else cout<<sum<<endl;
	while(q--){
	    int op=read(),i=read(),x=read();
	    if(op==1){
	        auto pos=s[c[i]].lower_bound({i,p[i]});
	        del(c[i]);del(x);
	        s[x].insert(*pos);s[c[i]].erase(pos);
	        add(c[i]);add(x);
	        c[i]=x;
	    }
	    if(op==2){
	        auto pos=s[c[i]].lower_bound({i,p[i]});
	        del(c[i]);
	        s[c[i]].insert({i,x});s[c[i]].erase(pos);
	        add(c[i]);
	        p[i]=x;
	    }
	    int A=b.begin()->x,B=prev(a.end())->x;
	    if(b.size()>0)
	        if(A>B)cout<<sum-B+A<<endl;
	        else cout<<sum<<endl;
	    else cout<<sum<<endl;
	}
}
signed main(){Feather();return 0;}

P11860 [CCC 2025 Senior] 熔岩路 / Floor is Lava

主要思想就是点边互换,然后建图的时候记得排个序,这样就大大减小了建图的时间开销。最后跑一个 dij 就做完了。

code
C++
//Code By Sky_Dream

/*
It's been a long day.
Without my friend.
And I'll tell you all about it when I see you again.
We've come a long way,
From where we began.
Oh I'll tell you all about it when I see you again.
When I see you again.
Oh,who know,all the planes we flew,
good things we had been drew
That something told me right here talking with you.
*/

//#pragma GCC optimize(1)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define dep(i,x,y) for(int i=x;i>=y;--i)
#define int long long
#define N 200010
#define endl "\n"
using namespace std;
inline int read(){
   int ret=0,sgn=0,ch=getchar();
   while(!isdigit(ch))sgn|=ch=='-',ch=getchar();
   while(isdigit(ch))ret=ret*10+ch-'0',ch=getchar();
   return sgn?-ret:ret;
}
struct node{int id,x;}a[2*N];
struct node2{int x,d;};
struct edge{int x,w;};
int n,m,ans=LONG_LONG_MAX,l[N],r[N],cur,d[2*N];
bool flag[2*N];
vector<edge>vv[2*N],v[2*N];
bool operator<(const node &x,const node &y){if(x.id!=y.id)return x.id<y.id;return x.x<y.x;}
inline bool operator<(const node2 &x,const node2 &y){return x.d>y.d;}
inline void dij(){
   priority_queue<node2>q;
   memset(d,0x3f3f3f,sizeof(d));d[1]=0;
   q.push((node2){1,0});
   while(!q.empty()){
       int x=q.top().x;
       q.pop();
       if(flag[x])continue;
       flag[x]=1;
       for(auto e:v[x])
           if(d[x]+e.w<d[e.x]){
               d[e.x]=d[x]+e.w;
               q.push((node2){e.x,d[e.x]});
           }
   }
}
inline void Feather(){
   freopen("road.in","r",stdin);
   freopen("road.out","w",stdout);
   //ios::sync_with_stdio(0);
   //cin.tie(0);cout.tie(0);
   //mt19937 Rand(time(0));
   n=read();m=read();
   a[++cur]=(node){1,0};
   rep(i,1,m){
       int x=read(),y=read(),w=read();
       a[++cur]=(node){x,w};
       a[++cur]=(node){y,w};
       vv[x].push_back((edge){y,w});
       vv[y].push_back((edge){x,w});
   }
   sort(a+1,a+cur+1);
   rep(i,2,cur)
       if(a[i].id==a[i-1].id){
           v[i-1].push_back((edge){i,a[i].x-a[i-1].x});
           v[i].push_back((edge){i-1,a[i].x-a[i-1].x});
       }
   rep(i,1,n)
       for(auto e:vv[i]){
           int posi=lower_bound(a+1,a+cur+1,(node){i,e.w})-a,
   			posj=lower_bound(a+1,a+cur+1,(node){e.x,e.w})-a;
           v[posi].push_back((edge){posj,0});
       }
   dij();
   rep(i,1,cur)if(a[i].id==n)ans=min(ans,d[i]);
   cout<<ans;
}
signed main(){Feather();return 0;}

P9814 [CCC 2015 S5] Greedy For Pies

我们不难注意到 b 数组里面的数有两个用处,一个是拿来当隔板,这里的数比较小,另一个是拿来直接算入总值。

dp即可。

code
C++
//Code By Sky_Dream

/*
It's been a long day.
Without my friend.
And I'll tell you all about it when I see you again.
We've come a long way,
From where we began.
Oh I'll tell you all about it when I see you again.
When I see you again.
Oh,who know,all the planes we flew,
good things we had been drew
That something told me right here talking with you.
*/

//#pragma GCC optimize(1)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define dep(i,x,y) for(int i=x;i>=y;--i)
//#define int short
#define M 101
#define endl "\n"
#define MAX 1145141919810
using namespace std;
inline int read(){
	int ret=0,sgn=0,ch=getchar();
	while(!isdigit(ch))sgn|=ch=='-',ch=getchar();
	while(isdigit(ch))ret=ret*10+ch-'0',ch=getchar();
	return sgn?-ret:ret;
}
const int N=4e3+10;
int n,m,ans,a[N],b[105],f[2][105][105][2];
inline void Feather(){
	freopen("insert.in","r",stdin);
	freopen("insert.out","w",stdout);
	//ios::sync_with_stdio(0);
	//cin.tie(0);cout.tie(0);
	//mt19937 Rand(time(0)); 
	n=read();
	rep(i,1,n)a[i]=read();
	m=read();rep(i,1,m)b[i]=read();
	sort(b+1,b+m+1);
	rep(i,1,n){
		int now=i&1,pre=now^1;
		rep(j,0,m)
			rep(k,0,j){
				f[now][j][k][0]=max(f[pre][j][k][1],f[pre][j][k][0]);
				f[now][j][k][1]=f[pre][j][k][0]+a[i];
				if(j&&k)f[now][j][k][0]=max(f[now][j][k][0],f[pre][j-1][k-1][0]+b[m-k+1]);
				if(j-1>=k)f[now][j][k][1]=max(f[now][j][k][1],f[pre][j-1][k][1]+a[i]);
				ans=max({ans,f[now][j][k][0],f[now][j][k][1]});
			} 
	}
	rep(i,n+1,n+m){
		int now=i&1,pre=now^1;
		rep(j,0,m)
			rep(k,0,j){
				if(j)f[now][j][k][0]=max(f[pre][j-1][k][1],f[pre][j-1][k][0]);
				if(j&&k)f[now][j][k][1]=f[pre][j-1][k-1][0]+b[m-k+1];
				ans=max({ans,f[now][j][k][0],f[now][j][k][1]});
			} 
	}
	cout<<ans;
}
signed main(){Feather();return 0;}
原文