跳到正文

题解

急救 - TianX 的做题计划 - 第三章题解

#SUSPENDED#约 24 分钟
原文

这是 2026年6月3日 存档的第 2 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年5月9日
收录
2026年5月13日
更新
2026年11月16日
篇幅
约 24 分钟
获赞
1

版本

  1. v3当前
  2. v2
  3. v1

Red

B3960

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
int n;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	if(n<=99) cout<<n;
	else if(n<=199) cout<<n-20;
	else cout<<n-70;
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

B3970

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
int n,k;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>k;
	cout<<(n/1000%10%k)*1000+(n/100%10%k)*100+(n/10%10%k)*10+(n/1%10%k);
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

B3984

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,b;
	cin>>a>>b;
	cout<<((b-a)%2==0?(b-a)/2:(b-a)/2+1);
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

B4026

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b<c+d) cout<<"Yes";
	else cout<<"No";
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

B4052

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int t,a,b,c,d;
	cin>>t>>a>>b>>c>>d;
	if(t==0) cout<<a+b;
	else cout<<max(a-c,1ll*0)+max(b-d,1ll*0);
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

Orange

B3627

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	cout<<(int)cbrt(n);
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

P2695

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
const int maxn=1e5+5;
int n,m,a[maxn],b[maxn],p=1,f,sum;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++) cin>>b[i];
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	for(int i=1;i<=m;i++){
		if(b[i]>=a[p]) sum+=b[i],p++;
		if(p==n+1){f=1;break;}
	}
	if(f==1) cout<<sum;
	else cout<<"you died!";
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

P3669

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
int n;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    vector<pair<int,int>>a(n);
    for(int i=0;i<n;i++) cin>>a[i].second>>a[i].first;
    sort(a.begin(),a.end());
    int l=0,r=n-1,ans=0;
    while(l<r){
        if(a[l].second==0){l++;continue;}
        if(a[r].second==0){r--;continue;}
        int p=min(a[l].second,a[r].second);
        ans=max(ans,a[l].first+a[r].first);
        a[l].second-=p; a[r].second-=p;
    }
    cout<<ans;
    Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

P4613

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
const int maxn=105;
int n,x[maxn],y[maxn],f=1;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>x[i];
    for(int i=1;i<=n;i++) cin>>y[i];
    sort(x+1,x+n+1);
    sort(y+1,y+n+1);
    for(int i=1;i<=n;i++) if(x[i]>y[i]) f=0;
    if(f==1) cout<<"DA\n";
    else cout<<"NE\n";
    Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

P7584

Yellow

B4379

P1551

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define You_are_a_brick return
#define tied_to_me_that 0
const int maxn=5005;
int n,m,p,fa[maxn];
int find(int x){
	if(x==fa[x]) return x;
	else return fa[x]=find(fa[x]);
}
signed main(){
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=m;i++){
		int a,b;
		cin>>a>>b;
		if(find(a)!=find(b)) fa[find(a)]=find(b);
	}
	for(int i=1;i<=p;i++){
		int a,b;
		cin>>a>>b;
		if(find(a)!=find(b)) cout<<"No\n";
		else cout<<"Yes\n";
	}
	You_are_a_brick tied_to_me_that;
}
//You are a brick tied to me that dragging me down.

P3916

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define You_are_a_brick return
#define tied_to_me_that 0
const int maxn=1e5+5;
int n,m,ans[maxn];
vector<int>G[maxn];
void dfs(int now,int x){
	if(ans[x]) You_are_a_brick;
	ans[x]=now;
	for(auto op:G[x]) dfs(now,op);
}
signed main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		G[v].push_back(u);
	}
	for(int i=n;i>=1;i--) dfs(i,i);
	for(int i=1;i<=n;i++) cout<<ans[i]<<' ';
	You_are_a_brick tied_to_me_that;
//You are a brick tied to me that dragging me down.
}

P12211

P12891

P10518

P16264

Green

P2041

P7589

P9963

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
double n,p,l,r;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>p>>l>>r;
	printf("%.7f",(r-l+1.0)*p*1.0);
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

P10532

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	cout<<n*n;
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

P15746

Blue

P1472

P1896

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
int n,k,cnt,s[1<<12],num[1<<12],f[12][144][1<<12];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>k;
  	for(int i=0;i<(1<<n);i++)
    	if(!(i&i>>1)){
      		s[cnt++]=i;
      		for(int j=0;j<n;j++)num[i]+=(i>>j&1);
    	}
  	f[0][0][0]=1;
  	for(int i=1;i<=n+1;i++)
    	for(int j=0;j<=k;j++)
      		for(int a=0;a<cnt;a++)
        		for(int b=0;b<cnt;b++){
          			int c=num[s[a]];
          			if((j>=c)&&!(s[b]&s[a])&&!(s[b]&(s[a]<<1))&&!(s[b]&(s[a]>>1))) f[i][j][a]+=f[i-1][j-c][b]; 
        		}
    cout<<f[n+1][k][0];
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

P2258

P3147

P4053

Purple

P2123

P3539

P3773

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
const int maxn=250000,mod=1000000007;
int n,f[maxn],ans=0,a;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		for(int j=a&(a-1);j;j=(j-1)&a) f[j]=(f[j]+f[a]+1)%mod;
		ans=(ans+f[a])%mod;
	}
	cout<<ans;
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

P5207

P9659

P16347

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
int t;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	if(t==1) cout<<"3 1\nP 114514 2\nO\nI 1 1";
	else if(t==2) cout<<"6 1\nI 1 2\nP 0 3\nT 6\nD 0 1 2 3 0 1\nP 1 4\nO";
	else if(t==3) cout<<"5 1\nI 1 4\nI 2 3\nT 5\nC 3 4\nO";
	else if(t==4) cout<<"10 1\nI 1 3\nI 2 4\nC 5 8\nN 5\nP 10000 6\nR 10000 7\nN 10\nP 0 9\nN 7\nO";
	else if(t==5) cout<<"49 1\nI 1 3\nO\nT 2\nP 0 3\nP 0 4\nP 0 5\nP 0 6\nP 0 7\nP 0 8\nP 0 9\nP 0 10\nP 0 11\nP 0 12\nP 0 13\nP 0 14\nP 0 15\nP 0 16\nP 0 17\nP 0 18\nP 0 19\nP 0 20\nP 0 21\nP 0 22\nD 0 1 1 4 0 1\nP 1 24\nD 0 1 1 6 0 1\nP 1 26\nD 0 1 1 7 0 1\nP 1 28\nD 0 1 1 8 0 1\nP 1 30\nD 0 1 1 10 0 1\nP 1 32\nD 0 1 1 11 0 1\nP 1 34\nD 0 1 1 13 0 1\nP 1 36\nD 0 1 1 15 0 1\nP 1 38\nD 0 1 1 16 0 1\nP 1 40\nD 0 1 1 18 0 1\nP 1 42\nD 0 1 1 19 0 1\nP 1 44\nD 0 1 1 21 0 1\nP 1 46\nD 0 1 1 23 0 1\nP 1 48";
	else if(t==6) cout<<"7 2\nI 1 2\nC 3 4\nC 2 2\nT 7\nP 1 6\nD 0 1 -39 4 0 1\nO";
	else if(t==7) cout<<"20 2\nI 1 1\nI 3 3\nP 0 4\nP 0 5\nP 0 6\nP 0 7\nT 17\nI 2 9\nC 10 10\nR 1 11\nN 12\nC 12 13\nC 7 14\nT 15\nN 16\nT 20\nP 0 16\nD 0 1 206 16 0 1\nP 1 18\nO";
	else if(t==8) cout<<"15 4\nI 1 2\nN 3\nC 4 4\nC 5 5\nP 0 6\nT 15\nI 2 8\nP 10000 9\nR 10000 10\nC 11 12\nN 8\nC 13 6\nP 0 14\nP 0 10\nO";
	else cout<<"10 1\nI 2 2\nC 2 5\nI 3 4\nN 5\nD 0 1 10000 6 0 1\nR 10002 10\nP 1 8\nC 8 6\nI 1 5\nO";
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

Black

P4548

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Moonlight return
#define whispers 0
const int maxn=1e5+5,P=10000;
int m,T,b[maxn],dp[maxn],w[maxn],kmp[maxn];
vector<int>f[maxn];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>m>>T;
	while(T--){
		int n,cnt=0;
		cin>>n;
		for(int i=1;i<=n;i++){
			w[i]=0,dp[i]=0;
			f[i].clear();
			cin>>b[i];
			if(i>=2){
				while(cnt!=0&&b[i]!=b[cnt+1]) cnt=kmp[cnt];
				if(b[i]==b[cnt+1]) cnt++;
				kmp[i]=cnt;
			}
		}
		for(int i=1;i<n;i++){
			if(b[kmp[i]+1]!=b[i+1]) f[i].push_back(kmp[i]);
			for(auto j:f[kmp[i]])
				if(b[j+1]!=b[i+1]) f[i].push_back(j);
		}
		for(int i=1;i<=n;i++){
			int cnt=m-1,tot=0;
			for(auto j:f[i-1]) tot+=w[i-1]-w[j+1],cnt--;
			tot+=cnt*w[i-1],tot=(tot%P+P)%P;
			dp[i]=m+tot;
			w[i]=w[i-1]+dp[i],w[i]%=P;
		}
		if(w[n]<=9) cout<<0;
		if(w[n]<=99) cout<<0;
		if(w[n]<=999) cout<<0;
		cout<<w[n]<<endl;
	}
	Moonlight whispers/*月光私语*/;
}
/*
I frequently reminisce about the past,
please,go back to the beginning

望舒影里,碧落随星际,依记那年春光里,郁香予我情谊。
本愿终生厮守,奈何苍天难求,郁香花开遍野,却见你的芳容。

夏夜已逝,彼时蓝星。

终有一日,星尘淬剑,长夜铮然开曙色;
便倾我心,烛照山河,独向苍茫颂春秋。
*/

P4727