跳到正文

个人记录

8.14 东塘校区 -- 407

AK_lwh_888约 6 分钟
原文
文章信息与版本

文章信息

发布
2025年8月14日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 6 分钟

版本

  1. v1当前

8.14 东塘校区 — 407

T637642 比较数字

这道题要我们求出最小的比 NN 大的不包含 00 的一个数字。考试时我写了一个 5050 分的代码:

C++
#include<bits/stdc++.h>
using namespace std;
string s;
signed main(){
	cin>>s;
	for(int i=0;i<s.size();++i){
		if(s[i]=='0'){
			cout<<"1";
		}
		else{
			cout<<s[i];
		}
	}
	return 0;
} 

这个代码我想的是最小的不含 00 的数不就是将 NN 所有的 00 改成 11 就行了。

但是如果是 1230200112302001 那么输出是 1231211112312111 这个不是正确答案,正确答案是 1231111112311111。所以在我们看到第一个 00 的时候就后面的所有数都得是 00。

C++
#include<bits/stdc++.h>
using namespace std;
string s;
bool vis; 
signed main(){
	cin>>s;
	for(int i=0;i<s.size();++i){
		if(s[i]=='0'||vis){
			vis=true;
			cout<<"1";
		}
		else{
			cout<<s[i];
		}
	}
	return 0;
} 

T637627 张的弓

这道题模拟可以拿 7575 分,我只拿了 2525 分。

每次只要判断 xx 是否到边界了,如果到了就将 yy 加一就行了。如果行是偶数,边界就是 11,如果行是奇数,边界就是 nn。

70 分代码

C++
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int n,m,k;
int t;
signed main(){
	cin>>t;
	while(t--){
		cin>>n>>m>>k;
		int x=1,y=1;
		for(int i=1;i<=k;++i){
			if(y%2==1){
				if(x==n){
					y++;
				}
				else{
					x++;
				}
			}
			else{
				if(x==1){
					y++;
				}
				else{
					x--;
				}
			}
		}
		cout<<abs(x-1)+abs(y-1)<<"\n";
	}
	
	return 0;
}

100100 分就是直接求曼哈顿距离。

C++
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int n,m,k;
int t;
signed main(){
	cin>>t;
	while(t--){
		cin>>n>>m>>k;
		int ans=0;
		if((k/n)%2==0){
			ans+=(k/n)+(k%n);
		}
		else{
			ans+=(k/n)+(n-k%n-1);
		}
		cout<<ans<<"\n";
	}
	
	return 0;
}

T637602 可可口乐

这道题用广搜写,枚举字符串和步数。为了避免重复,还得用 visvis 标记一下。如果发现字符串正确就直接输出,否则就枚举不同的数 pushpush。

C++
#include<bits/stdc++.h>
using namespace std;
string t="cocacola";
string s;
struct node{
	string s1;
	int dis;
};
map<string,bool>vis;
int bfs(){
	queue<node>q;
	q.push({s,0});
	vis[s]=true;
	while(q.size()){
		node u=q.front();
		q.pop();
		if(u.s1==t){
			return u.dis;
		}
		int id=0;
		for(int i=0;i<8;++i){
			if(u.s1[i]!=t[i]){
				id=i;
				break;
			}
		}
		for(int i=id+1;i<8;++i){
			string pos=u.s1;
			swap(pos[id],pos[i]);
			if(vis.count(pos)==false){
				vis[pos]=true;
				q.push({pos,u.dis+1});
			}
		}
	}
}
signed main(){
	cin>>s;
	cout<<bfs()<<"\n";
	return 0;
}

T637561 小梦的守卫

这道题开始时我用的是模拟,只拿了 2020 分。我们可以先求出这个军队最多可以扛多少下。因为僵尸是左右攻击,所以两边的前缀和都要求。因为僵尸攻击力只是 11,所以我们可以二分这个时间,然后输出人数减去两个区间死掉的人数,就是 l+r。如果死的人数比总人数还多或者刚好死光,就输出 Zombies ate your brain!。

C++
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int N=1e6;
int a[N],n,q,t,pre[N],suf[N];
signed main(){
	cin>>n>>q;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=n;++i){
		pre[i]=pre[i-1]+a[i];
	}
	for(int i=n;i>=1;--i){
		suf[n-i+1]=suf[n-i]+a[i];
	}
	while(q--){
		cin>>t;
		int l=upper_bound(pre+1,pre+1+n,t)-pre-1;
		int r=upper_bound(suf+1,suf+1+n,t)-suf-1;
		if(l+r>n)cout<<"Zombies ate your brain!\n";
		else cout<<n-l-r<<"\n";
	}
	return 0;
}
原文