跳到正文

个人记录

8.24训练总结

hter约 5 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 5 分钟

版本

  1. v1当前

T1 快递费用

AC

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll w,n,sum;
int main()
{
	cin>>w>>n;
	sum+=20;
	if(w>500){
		w-=500;
		ll x;
		if(n==1){
			if(w%500!=0){
				x=w/500+1;
			}
			sum+=4*x;
			cout<<sum;
			return 0;
		}
		if(n==2){
			if(w%500!=0){
				x=w/500+1;
			}
			sum+=6*x;
			cout<<sum;
			return 0;
		}
		if(n==3){
			if(w%500!=0){
				x=w/500+1;
			}
			sum+=9*x;
			cout<<sum;
			return 0;
		}
		if(n==4){
			if(w%500!=0){
				x=w/500+1;
			}
			sum+=10*x;
			cout<<sum;
			return 0;
		}
		if(n==5){
			if(w%500!=0){
				x=w/500+1;
			}
			sum+=17*x;
			cout<<sum;
			return 0;
		}
	}
	return 0;
}

T2 石头布没有剪刀

AC

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int g,p,cnt;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='g'){
			if(g>p)p++,cnt++;
			else g++;
		}
		else{
			if(g>p)p++;
			else g++,cnt--;
		}
	}
	cout<<cnt;
	return 0;
}

T3 篝火问题

思路:bro相对运动了解过没,就是这题的关键,循环让每个烟雾移动肯定会超时,所以能想到相对运动的可以去打国赛了… 所以用map只存一个就行了

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,r,c,x=0,y=0;
map<pair<int,int>,bool>mp;
string s;
int main()
{
	cin>>n>>r>>c;
	mp[{0,0}]=1;
	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='N')x++;
		else if(s[i]=='S')x--;
		else if(s[i]=='W')y++;
		else if(s[i]=='E')y--;
		mp[{x,y}]=1;
		cout<<mp.count({r+x,c+y});
	}
	cout<<"\n";
	return 0;
}

T4 落落的去的数学问题3 老师真大气,给了十分暴力分,老师我想问你个问题,就是下次能不能多一点…

直接套公式居然要双层循环?!根据老师的性格这种关于定义之类的题你知道的出现双层循环你这代码就绝对会是错的(你以为分那么好拿)?

思路:手写公式就是a[i]*10的a[j]位数+a[j]即可,那这么一看,前缀和的性质就达成了,所以这题的关键就是用前缀和,避免用双重循环,然后再勤劳一点MOD

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=998244353;
ll n,a[200005],s[200005],ans,b[200005];
int main()
{
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		string q=to_string(a[i]);
		b[i]=q.size();
		s[i]=s[i-1]+a[i];
		s[i]%=M;
	}
	for(ll j=2;j<=n;j++){
		ll len=pow(10,b[j]);
		ans+=((s[j-1]%M)*(len%M)+(j-1)*(a[j]%M))%M;
		ans%=M;
	}
	cout<<ans;
	return 0;
}

T5 高低位交换 ヽ(≧□≦)ノ

70分,因为我没看题,只能32位,也就是用unsigned int,用long long会导致前导零输错

老师在这个代码里是运用了左移和右移,也就是位运算,表达了老师的思乡之情,这个得记,因为懒人必备、

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
unsigned int a,ans;
int main()
{
    cin>>a;
    ans=(a<<16)+(a>>16);
    cout<<ans;
	return 0;
}



紫茄子

原文