跳到正文

个人记录

8.24

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

文章信息

发布
2025年8月24日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 4 分钟

版本

  1. v1当前

快递费用

C++
#include<bits/stdc++.h>
using namespace std;
long long n,m,s=20;//s是费用
int a[105]={0,4,6,9,10,17};//按区域存费用
int main(){
	cin>>n>>m;
	n-=500;
	if(n<=0) n=0;
	s+=(n/500)*a[m];
	if(n%500!=0) s+=a[m];
	cout<<s;
	return 0;
} 

石头布没有剪刀

C++
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	int t=s.size()/2,p=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='p') p++;//记录对手出p
	}
	cout<<t-p;//自己出p次数减去对手出p
	return 0;
} 

篝火问题

C++
#include<bits/stdc++.h>
using namespace std;
int n,x,y,wx,wy;
map<pair<int,int>,bool> mp;//用来记录烟雾
string a;
int main(){
    cin>>n>>x>>y;
    cin>>a;
    mp[{0,0}]=1;
    for(int i=0;i<n;i++){
        int r=0,c=0;
        if(a[i]=='N') r=1;
        if(a[i]=='W') c=1;
        if(a[i]=='S') r=-1;
        if(a[i]=='E') c=-1;
        x+=r;//移动人
        y+=c;
        wx+=r;//移动篝火
        wy+=c;
        //cout<<x<<" "<<y<<endl;
        mp[{wx,wy}]=1;//记录烟雾
        if(mp.count({x,y})) cout<<1;
        else cout<<0;
    }
    return 0;
}

落落的去的数学问题3

C++
#include<bits/stdc++.h>
using namespace std;
const long long N=998244353;
long long n,a[200005],b[200005],s;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=(b[i-1]+a[i])%998244353;
    }
    for(int i=1;i<=n;i++){
        long long len=to_string(a[i]).size();
        s=((s+b[i-1]*((long long)pow(10,len)%N)%N)%N+(i-1)*a[i]%N)%N;//要加%N,b是累加
        
    }
    cout<<s;
	return 0;
}

高低位交换

C++
#include<bits/stdc++.h>
using namespace std;
long long s;
int a[105];
int main(){
	cin>>s;
	long long w=1,x=1;
	while(w<=32){
		if(s<x) break;
		x*=2;
		w++;
	}
	x/=2;
	while(w--){//变成二进制
		if(s>=x){
			a[w]=1;
			s-=x;
		}
		x/=2;
	}
	for(int i=16;i>=1;i--){//交换高低位
		swap(a[i],a[i+16]);
	}
	x=1;
	for(int i=1;i<32;i++){//乘到2的32次方
		x*=2;
	}
	long long ss=0;//记录数字
	for(int i=32;i>=1;i--){
		if(a[i]==1){//加每一位二进制
			ss+=x;
		}
		x/=2;
	}
	cout<<ss;
	return 0;
}
原文