跳到正文

个人记录

暑假-S组-第二场总结

ypz_HC约 4 分钟
原文
文章信息与版本

文章信息

发布
2025年8月15日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 4 分钟

版本

  1. v1当前

T1

  1. 利用if判断进行分类讨论,注意顺序。
C++
#include<bits/stdc++.h>
using namespace std;
long long t,k,a,b,c;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--){
		cin>>k>>a>>b>>c;
		long long a1=a+b,b1=b+c,c1=c+a,d=a+b+c,ans=k;
		if(a<=k){
			ans=min(ans,k-a);
		}
		if(b<=k){
			ans=min(ans,k-b);
		}
		if(c<=k){
			ans=min(ans,k-c);
		}
		if(a1<=k){
			ans=min(ans,k-a1);
		}
		if(b1<=k){
			ans=min(ans,k-b1);
		}
		if(c1<=k){
			ans=min(ans,k-c1);
		}
		if(d<=k){
			ans=min(ans,k-d);
		}
		cout<<ans<<"\n";
	}
	return 0;
} 

T2

  1. 这题直觉告送我们跟二进制有关,果然,每一层对应二的i次方。
  2. 由于1e18最多为二的60几次方,所以我们可以提前预留60各一用来连接每层,再根据二进制数位是否为1来决定是否选这层。
C++
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 99824353;
const int maxn = 505;
const int mod1 = 1e18 + 1;
struct Point{
	int x,y; 
}; 
int dp[maxn][maxn];
vector<Point>op; 
int MUL(int a,int b){
	return((a % mod)*(b % mod))%mod;
} 
void init(){
	dp[1][1] = 1;	
	dp[2][1] = 1;	
	dp[2][2] = 1;	
	for(int i=1;i<=500;i++){
		for (int j=1;j<=i;j++){
			if(j==1||j==i){
				dp[i][j]=1;
			}else{
				dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
				dp[i][j]%=mod1;
			}
		}
	}
	return ;
} 
signed main(){
	init();
	int n;
	cin>>n;
	if(n<=60){
		cout<<n<<endl;
		for(int i=1;i<=n;i++){
			cout<<i<<' '<<1<<endl;
		}
		cout<<n<<' '<<1<<endl;
		return 0;
	}
	int tmp=n-60;
	int cnt=1;
	int ans=1ll;
	int dir=0;
	int num=60;
	int sum=0;
	while(tmp){
		if(tmp%2==1){
			if(dir==1){
				for(int i=1;i<=cnt;i++){
					op.push_back({cnt,i});
					ans=MUL(ans,dp[cnt][i]);
					sum+=dp[cnt][i]; 
				}
			}else{
				for(int i=cnt;i>=1;i--){
					op.push_back({cnt,i});
					ans=MUL(ans,dp[cnt][i]);
					sum+=dp[cnt][i]; 
				}
			}
			dir=!dir;
		}else{
			num--;
			if(dir==0){
				op.push_back({cnt,cnt});
			} else{
				op.push_back({cnt,1});
			}
			sum+=1;
		} 
		cnt++;
		tmp/=2;
	} 
	sum+=num;
	for(int i=1;i<=num;i++){
		if(dir==0){
			op.push_back({cnt,cnt});
		}else{
			op.push_back({cnt,1});
		}
		cnt++;
	}
	cout<<op.size()<<endl;
	for(int i=0;i<op.size();i++){
		cout<<op[i].x<<' '<<op[i].y<<endl;
	}
	cout<<sum<<' '<<ans<<endl;
	return 0;
}
原文