跳到正文

个人记录

小学 T3、初中 T2 代码

MonKeySort_ZYczc约 2 分钟
原文

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

文章信息与版本

文章信息

发布
2025年12月5日
收录
2025年12月12日
更新
2026年11月18日
篇幅
约 2 分钟

版本

  1. v3当前
  2. v2
  3. v1

汉诺塔

C++
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int q,n,p;
string s;
char f,t,w;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>q;
	while(q--)
	{
		cin>>n>>s;
		//reverse(s.begin(),s.end());
		f='A',t='C',w='B';
		for(p=n-1;s[p]=='0';)p--;
		for(int i=0;i<n;i++)
		{
			if(p==i){cout<<n-i<<' '<<f<<' '<<t<<'\n';break;}
			if(s[i]=='0') swap(w,t);
			else swap(f,w);
		 } 
	}
}

小学 T3

C++
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int n,m,k,t,tt;
struct peo
{
	int x,p;
	bool operator<(const peo &t)const{return (x==t.x?p<t.p:x>t.x);}
}a[N];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++) cin>>a[i].x,a[i].p=i;
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) if(a[i].p==k) t=i;
	tt=t;t--;
	for(;t>=1;t--)
	{
		if(m<a[t].x-a[tt].x+1) break;
		else m-=a[t].x-a[tt].x+1;
	}
	cout<<t+1;
}