跳到正文

闲话

5.27总结

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

文章信息

发布
2025年5月29日
收录
2025年12月12日
更新
2026年10月30日
篇幅
约 4 分钟

版本

  1. v1当前

5.27 总结

今天考试·_·

但我第三 (≥v≤)

T1 25 之和

水\color{skyblue}水题

本来觉得要开longlonglonglong

但不用开。。。

code(注释没加因为太水了)

C++
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=1e5+10;
ll n,ans;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=25;i++){
		ans+=n+i-1;
	}
	cout<<ans;
	return 0;
}

T2 对面的人

对面的是人吗

这题就是找规律题,找对规律就能WA

思路:

如果只要abc任何一个数超过总人数那么直接返回-1

再判断怎么输出

(不要问为什么,因为你直接加会wa。。。比如总人数6人,你要输出第5个人对面的,不能直接加,不然会输出比总人数大的数)

然后就能WA

code:

C++
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <climits>
typedef long long ll;
using namespace std;
const int N=1e5+10;
ll n,a,b,c,x;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	while(n--){
		cin>>a>>b>>c;
		x=abs(a-b);
		ll xx=x*2;
		if(c>xx||a>xx||b>xx){
			cout<<-1<<'\n';
			continue;
		}
		if(c<=xx/2)cout<<c+x;
		else cout<<c-x;
		cout<<'\n';
	}
	return 0;
}

我就爱火车头那咋了

T3 n个数中选m个

一道简单的全排列

只不过要加回溯,不然会WA

思路前几周讲过,这里就不放了 : )

code:

C++
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=114+10;
int n,m,a[N],v[N];
void dfs(int x,int num){
	if(x==m+1){
		for(int i=1;i<=m;i++)cout<<a[i]<<' ';
		cout<<'\n';
	}
	for(int i=num+1;i<=n;i++){
		if(v[i]==0){
			a[x]=i;
			v[i]=1;
			dfs(x+1,i);
			v[i]=0;
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	dfs(1,0);
	return 0;
}

知道为什么没火车头了吗

因为我善

T4 弹珠

可恶的二分啊啊啊

思路:

先找到数量最多的弹珠个数作为右边界(不然会多算很多次)

再用check函数判断当前状态是否可行

最后输出l(因为是输出最小的鸡肚子)

code:

C++
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=3e6+10;
ll n,m,a[N],ans;
bool c(ll x){
	ll sum=0;
	for(int i=1;i<=m;i++){
		sum+=a[i]/x;
		if(a[i]%x!=0)sum++;
	}
	return sum<=n;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	ll l=0,r=1e9+1;
	for(int i=1;i<=m;i++){
		cin>>a[i];
		r=max(a[i],r);
	}
	while(l+1<r){
		ll mid=(l+r)/2;
		if(c(mid))r=mid;
		else l=mid;
	}
	cout<<r;
	return 0;
}

T5 小明的计划

他计划啥我不知道,但怎么写我也不知道

The−End\color{gold}The-End

原文