跳到正文

算法·理论

不知道叫什么の做题记录

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

文章信息

发布
2026年2月27日
收录
2026年3月4日
更新
2026年11月11日
篇幅
约 8 分钟

版本

  1. v2当前
  2. v1

1.P10730 [NOISG 2023 Qualification] Burgers

考虑对答案进行二分,之前比赛见到过一题类似的。

然后就是对于答案的 check。乱设乱搞分类讨论就好了。忘了就去看题解区。

Code
C++
/*
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 100005
#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;
}
int x[N],a[N],b[N],n;
inline bool check(int y){
	int l=0,r=y;
	for(int i=1;i<=n&&l<=r;++i){
		if(a[i]==b[i]&&x[i]<1ll*y*b[i])return false;
		if(a[i]>b[i])r=min(1ll*r,(x[i]-1ll*y*b[i])/(a[i]-b[i]));
		if(a[i]<b[i])l=max(1ll*l,(x[i]-1ll*y*b[i]+a[i]-b[i]+1)/(a[i]-b[i]));
	}
	if(l>r)return false;
	return true;
}
inline void Feather(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	mt19937 Rand(time(0));
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	rep(i,1,n)cin>>x[i];
	rep(i,1,n)cin>>a[i];
	rep(i,1,n)cin>>b[i];
	int l=0,r=1e9;
	while(l<r){
		int mid=(l+r+1)/2;
		if(check(mid))l=mid;
		else r=mid-1;
	}
	cout<<l;
}
signed main(){Feather();return 0;}

2.P13541 [OOI 2022] Good arrays

戳这里,看看自己的题解。

3.CF2178D Xmas or Hysteria

首先 m×2≥nm\times2 \ge n 时是无解的。因为你技能都放不完。

然后考虑 mm 不为 00 的情况,如果 m×2=nm \times 2 = n,那么就让大的干掉小的。如果不满足这个条件,那么就让前几个小的去撞大的紫砂。

如果 m=0m=0,那么就从后往前找连着的若干个加起来可以干掉最大的那个位置,然后让前面位置的小怪去紫砂。

Code
C++
/*
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 a,h,id;
}a[N];
int T,m,n,total,ing[N];
inline bool cmp(node x,node y){
	return x.a<y.a;
}
inline void Feather(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	mt19937 Rand(time(0));
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>T;
	while(T--){
		total=0;
		cin>>n>>m;
		rep(i,1,n){
			total+=a[i].a;
			cin>>a[i].a;
			a[i].h=a[i].a;
			a[i].id=i;
		}
		if(m>n/2){cout<<-1<<endl;continue;}
		sort(a+1,a+n+1,cmp);
		if(m==n/2){
			cout<<n/2<<endl;
			int l=1,r=n;
			while(l<=r){
				cout<<a[r].id<<' '<<a[l].id<<endl;
				++l;--r;
			}
		}
		else if(m==0){
			total-=a[n].a;
			if(total<a[n].a){cout<<-1;continue;}
			cout<<n-1<<endl;
			int tmp=0,kk;
			dep(i,n-1,1){
				tmp+=a[i].a;
				if(tmp>=a[n].a){
					kk=i;
					break;
				}
			}
			rep(i,1,kk-1)cout<<a[i].id<<' '<<a[i+1].id<<endl;
			rep(i,kk,n-1)cout<<a[i].id<<' '<<a[n].id<<endl;
		}
		else{
			cout<<n-m*2+m<<endl;
			int st=1;
			while(m!=(n-st+1)/2){
				cout<<a[st].id<<' '<<a[st+1].id<<endl;
				++st;
			}
			int l=st,r=n;
			while(l<=r){
				cout<<a[r].id<<' '<<a[l].id<<endl;
				++l;--r;
			}
		}
	}
}
signed main(){Feather();return 0;}
原文