跳到正文

个人记录

8.20训练总结

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;
double a,b,s;
int main()
{
	cin>>a>>b;
	s=b/a*1.000;
	printf("%.3f",s);

	return 0;
}

T2 按列统计

AC

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int m,n;
int a[2020];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char t;
			cin>>t;
			if(t=='#')a[j]++;
		}
	}
	for(int i=1;i<=m;i++)cout<<a[i]<<" ";

	return 0;
}

T3 变形虫

思路:将自己分裂后的虫标上自己的号,存在数组里,然后再去数组里找

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+1;
int n;
int a[N];
int main()
{
	cin>>n;
	a[1]=0;
	for(int i=1;i<=n;i++){
		int s;
		cin>>s;
		a[2*i]=a[s]+1;
		a[2*i+1]=a[s]+1;
	}
	for(int i=1;i<=2*n+1;i++)cout<<a[i]<<"\n";


	return 0;
}

T4 宾果

思路:输入后行列斜都加上1最后谁等于n,就输出;

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e3+5;
int n,t;
int hang[N],lie[N],djx1,djx2;
int main()
{
	cin>>n>>t;
	for(int i=1;i<=t;i++){
		int num;
		cin>>num;
		int x=(num-1)/n+1;
		int y=(num-1)%n+1;
		hang[x]++;
		lie[y]++;
		if(x==y)djx1++;
		if(x+y==n+1)djx2++;
		if(hang[x]==n or lie[y]==n or djx1==n or djx2==n){
			cout<<i;
			return 0;
		}
	}
	cout<<"-1";


	return 0;
}

T5 神奇按钮

思路:额…

C++
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int N=2e5+5;

struct node{
    int x,step;
};

int n,m,k;
vector<int> g[2*N];
bool vis[2*N];

void bfs(){
    vis[1]=1;
    deque<node> q;
    q.push_back({1,0});
    while(q.size()){
        node f=q.front();
        q.pop_front();
        if(f.x==n||f.x==n*2){
            cout<<f.step;
            return;
        }
        if(g[f.x].size()==0) continue;
        int v=g[f.x][g[f.x].size()-1];
        if(abs(v-f.x)==n){
            if(!vis[v]){
                vis[v]=1;
                q.push_front({v,f.step});
            }
        }
        for(auto v:g[f.x]){
            if(vis[v]) continue;
            vis[v]=1;
            q.push_back({v,f.step+1});
        }
    }
    cout<<-1;
    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>k;
    for(int i=1;i<=m;i++){
        int u,v,w;
        cin>>u>>v>>w;
        if(w){
            g[u].push_back(v);
            g[v].push_back(u);
        }else{
            g[n+u].push_back(n+v);
            g[n+v].push_back(n+u);
        }
    }
    while(k--){
        int x;
        cin>>x;
        g[x].push_back(x+n);
        g[x+n].push_back(x);
    }
    bfs();
    return 0;
}




今天没有,因为累了:(

原文