上周比赛总结2021-11-14

反思

万万没想到,上周比赛发现自己更菜了,两个半小时就写了一道题,滑了个大稽……
总不能一周比一周菜吧,唉……
还是老老实实的写本上周的总结吧

比赛题目

Distinct Strings

Distinct Strings

#include<bits/stdc++.h>
using namespace std;
int main(){
    string S; cin >> S;
    int ans = 3;
    if(S[0]==S[1] && S[1]==S[2]) ans = 1;
    else if(S[0]!=S[1] && S[1]!=S[2] && S[2]!=S[0]) ans = 6;
    cout << ans << endl;
}

Star or Not

Star or Not

//对于每个顶点,计算它的度数(连接到顶点的边数)。
//如果有度数的顶点N-1,那么答案是Yes;否则答案是No。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main(){
    ll n;cin>>n;
    vector<ll>count(n+1);//计算每个顶点的度数
    for(ll i=1;i<=n-1;i++){
        ll a,b;cin>>a>>b;
        count[a]++;
        count[b]++;
    }
    for(ll i=1;i<=n;i++){
        if(count[i] == n-1){
            cout<<"Yes"<<endl;
            return 0;//终止程序
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Calendar Validator

Calendar Validator

//对于任意一个给定的元素x,它属于(x-1)/7行、(x-1)%7+1列
//根据这个特点判断元素是否属于原来矩阵的子矩阵
#include<bits/stdc++.h>
using namespace std;

int main(){
    int N,M; cin >> N >> M;
    vector<vector<int>> B(N,vector<int>(M));
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++) cin >> B[i][j];
    }
    vector<vector<int>> x(N,vector<int>(M)),y(N,vector<int>(M));
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            x[i][j] = (B[i][j]+6)/7;
            y[i][j] = (B[i][j]-1)%7+1;
        }
    }
    string ans = "Yes";
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            if(0 < i && x[i][j] != x[i-1][j]+1) ans = "No";
            if(0 < j && y[i][j] != y[i][j-1]+1) ans = "No";
            if(0 < j && x[i][j] != x[i][j-1]) ans = "No";
            if(0 < i && y[i][j] != y[i-1][j]) ans = "No";
        }
    }
    cout << ans << endl;
}

Play Train

Play Train

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

signed main(){
    ll n,q;cin>>n>>q;
    ll nil=-1;
    vector<ll>front(n+1,nil);// 在第 i 列火车前面连接的火车,如果没有这样的火车,则为零。
    vector<ll>back(n+1,nil);// 在第 i 列火车后面连接的火车,如果没有这样的火车,则为零。
    while(q--){
        ll c;cin>>c;
        if(c==1){
            ll x,y;cin>>x>>y;
            back[x] = y;
            front[y] = x;
        }else if(c==2){
            ll x,y;cin>>x>>y;
            back[x] = nil;
            front[y] = nil;
        }else{
            ll x;cin>>x;
            while(front[x] != nil){
                x = front[x]; // 移动到 x 的第一个连通分量component of x
            }
            vector<ll>ans;
            while(x != nil){
                ans.push_back(x);
                x = back[x];
            }
            cout<<ans.size()<<" ";
            for(ll i=0;i<=(int)ans.size()-1;i++){
                cout<<ans[i];
                if(i!=(int)ans.size()-1)cout<<" ";
                else cout<<endl;
            }
        }
    }

    return 0;
}

7

7


String Cards

String Cards


X

X


Social Distance 2

Social Distance 2


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值