跳到正文

个人记录

8.20

huanzhenyang0420约 7 分钟
原文
文章信息与版本

文章信息

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

版本

  1. v1当前

这是今天的比赛 8.20

T1 U600567 足球游戏

Accepted1̸00tps\color{green}{Accepted\not100tps}

赛时代码

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	double a,b,s;
	cin>>a>>b;
	s=b/a*1.0;
	printf("%.3f",s);
	return 0;
}

ヾ(≧▽≦*)o

T2 U600570 按列统计

Accepted1̸00tps\color{green}{Accepted\not100tps}

赛时代码

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

ヾ(≧▽≦*)o

T3 U600572 变形虫

WrongAnswer0̸\color{red}{Wrong Answer\not0}

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+1;
int n,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[s]的两个子节点记为父节点+1
		a[2*i+1]=a[s]+1;//a[s]的两个子节点记为父节点+1
	}
	for(int i=1;i<=2*n+1;i++)cout<<a[i]<<"\n";//输出
	return 0;
}

T4 T638908 宾果

WrongAnswer3̸6\color{red}{Wrong Answer\not36}

赛时代码

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	cout<<-1;
	return 0;
}

正确代码:

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;//第x行
		int y=(num-1)%n+1;//第y列
		hang[x]++;//标记
		lie[y]++;//标记
		if(x==y)djx1++;//判断是否满足条件
		if(x+y==n+1)djx2++;//判断是否满足条件
		if(hang[x]==n||lie[y]==n||djx1==n||djx2==n){//判断这4个变量里是否有一个为n
			cout<<i;
			return 0;
		}
	}
	cout<<"-1";//如果运行到了这,说明在T个回合内没有达成宾果输出-1
	return 0;
}

T5 U600562 神奇按钮

WrongAnswer0̸\color{red}{Wrong Answer\not0}

正确代码:

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;
}
原文