跳到正文

个人记录

8.23训练总结

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

文章信息

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

版本

  1. v1当前

T1 高铁线路

AC

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,x,y,z;
int main()
{
	cin>>n>>x>>y>>z;
	if(x>y){
		for(int i=x;i>=y;i--){
			if(i==z){
				cout<<"Yes";
				return 0;
			}
		}
		cout<<"No";
		return 0;
	}
	if(x<y){
		for(int i=x;i<=y;i++){
			if(i==z){
				cout<<"Yes";
				return 0;
			}
		}
		cout<<"No";
		return 0;
	}
	if(x==y){
		if(x==z){
			cout<<"Yes";
			return 0;
		}
		else{
			cout<<"No";
		}
	}
 	return 0;
}

T2 盲打练习

AC

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s1,s2;
int main()
{
	cin>>s1>>s2;
	int c=0;
	for(int i=0;i<s2.size();i++){
		if(s2[i]==s1[c]){
			c++;
			cout<<i+1<<" ";
		}
	}
 	return 0;
}

T3 Int128游乐园

AC

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,ans;
queue<int>q;
signed main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		int w;
		cin>>w;
		q.push(w);
	}
	int x=k;
	while(1){
		if(q.size()==0){
			cout<<ans+1;
			return 0;
		}
		if(q.front()>x){
			ans++;
			x=k;
		}
		if(q.front()<=x){
			x-=q.front();
			q.pop();
		}
	}
 	return 0;
}

T4 落落的去的数学问题2

考试暴力二十分

正确思路:算总和减+(ai+aj>=去模1e8)

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[300005];
int sum;
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i]*(n-1);
	}
	sort(a+1,a+1+n);
	a[n+1]=1e9;
	int cnt=0;
	for(int i=1;i<=n;i++){
		int x=100000000-a[i];
		int pos=lower_bound(a+i+1,a+1+n,x)-a;
		cnt+=(n-pos+1);
	}
	cout<<sum-cnt*100000000;

 	return 0;
}

T5 第K小

正确思路:你想想,所有一个数的查过后还要最小的那就是两个最小的加起来了的对不对,所以只要一个一个枚举,再注意去重,最后看第k小输出就行了

C++
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
typedef long long ll;
ll n,m,ans=0;
ll a[N];
map<ll,bool> mp;
ll bfs(){
	priority_queue<ll,vector<ll>,greater<ll>> pq;
	for(int i=1;i<=n;i++){
		if(mp[a[i]]) continue;
		pq.push(a[i]);
		mp[a[i]]=true;
	}
	while(!pq.empty()){
		ans++;
		ll t=pq.top();
		pq.pop();
		if(ans==m){
			return t;
		}
		for(int i=1;i<=n;i++){
			ll sum=t+a[i];
			if(!mp[sum]){
				mp[sum]=true;
				pq.push(sum);
			}
		}
	}
	return 0;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	cout<<bfs()<<endl;
	return 0;
}

T6 磁铁迷宫

正确思路:dfs连通块,加个color

C++
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int N = 1e3 + 10;
int n, m, a[N][N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int vis[N][N];
int cnt, color;
int ans = 1;
void dfs(int x, int y) {
    for (int i = 0; i < 4; i++) {
        int xx = x + dx[i], yy = y + dy[i];
        if (xx<1||xx>n||yy<1||yy>m||vis[xx][yy]==color||a[xx][yy]==1) continue;
        vis[xx][yy] = color;
        cnt++;

        if (a[xx][yy]==2) continue;

        dfs(xx,yy);
    }
}
int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=m;j++) {
            char c;
            cin>>c;
            if (c=='#') a[i][j]=1;
            else a[i][j]=0;
        }
    }
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=m;j++){
            if (a[i][j]==1) continue;
            if (a[i-1][j]==1 || a[i+1][j]==1 || a[i][j-1]==1 || a[i][j+1]==1) {
                a[i][j]=2;
            }
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j=1;j<=m;j++){
            if (vis[i][j]==0&&a[i][j]==0){
                color++;
                cnt=1;
                vis[i][j]=color;
                dfs(i,j);
                ans=max(ans,cnt);
            }
        }
    }
    cout<<ans;
    return 0;
}





水一波~

Rob Gasser

很好的电音制作人,不想解释了,直接看维基吧 https://monstercat.fandom.com/wiki/Rob_Gasser

原文