首页 > 其他分享 >AtCoder Beginner Contest 284

AtCoder Beginner Contest 284

时间:2023-01-09 11:14:44浏览次数:71  
标签:AtCoder Beginner vis int res namespace read using 284

A - Sequence of Strings

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

int32_t main(){
    int n;
    cin >> n;
    vector<string> s(n);
    for( auto &i : s ) cin >> i;
    for( int i = n-1 ; i >= 0 ; i -- )
        cout << s[i] << "\n";
    return 0;
}

B - Multi Test Cases

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

int read(){...}

void solve(){
    int n = read() , res = 0;
    for( int x ; n ; n -- ){
        x = read();
        if( x & 1 ) res ++;
    }
    cout << res << "\n";
    return;
}

int32_t main(){
    for( int T = read() ; T ; T -- )
        solve();
    return 0;
}

C - Count Connected Components

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

int read(){...}

vector<int> vis;
vector<vector<int>> e;

void dfs( int u ){
    vis[u] = 1;
    for( auto v : e[u] ){
        if( vis[v] ) continue;
        dfs(v);
    }
    return;
}

int32_t main(){
    int n = read() , m = read() , res = 0;
    e.resize(n+1) , vis.resize(n+1);

    for( int u , v ; m ; m -- )
        u = read() , v = read() , e[u].push_back(v) , e[v].push_back(u);
    for( int i = 1 ; i <= n ; i ++ ){
        if( vis[i] ) continue;
        dfs(i) , res ++;
    }
    cout << res << "\n";
    return 0;
}

D - Happy New Year 2023(补题)

根据唯一分解定理,\(p^2q\)是唯一的,且\(max(p,q)\le \sqrt[3]{n}\)

所以直接暴力写就好

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

int read(){...}

void solve(){
    int n = read();
    for( int i = 2 , j ; ; i ++ ){
        if( n % i != 0 ) continue;
        n /= i;
        if( n % i == 0 ) j = n / i;
        else j = i , i = sqrt( n );
        cout << i << " " << j << "\n";
        return;
    }
}

int32_t main(){
    for( int T = read() ; T ; T -- ) solve();
    return 0;
}

E - Count Simple Paths

非常简单的统计一下从1开始的简单路径,dfs不断的搜索就好了。

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

int read(){...}

const int N = 1e6 ;
int n , m , res;
vector<int> vis;
vector<vector<int>> e;

void dfs( int u ){
    vis[u] = 1;
    res ++;
    if( res == N ){
        cout << res<<"\n";
        exit(0);
    }
    for( auto v : e[u] ){
        if( vis[v] ) continue;
        dfs(v);
    }
    vis[u] = 0;
    return;
}


int32_t main(){
    n = read() , m = read() , res = 0;
    e.resize(n+1) , vis.resize(n+1);
    for( int u , v ; m ; m -- ){
        u = read() , v = read();
        e[u].push_back(v) , e[v].push_back(u);
    }
    dfs(1);
    cout << res << "\n";
    return 0;
}

F - ABCBAC(补题)

标签:AtCoder,Beginner,vis,int,res,namespace,read,using,284
From: https://www.cnblogs.com/PHarr/p/17036391.html

相关文章

  • Atcoder ABC112D Partition
    链接难度:\(\texttt{1025}\)找到最大的正整数\(x\)使得\(m\modx=0\)且\(\frac{m}{x}\gen\)。难度在于读题,简化后就简单的一批了。暴力都能过。枚举\(m\)的......
  • AtCoder Beginner Contest 284(D,E,F)
    AtCoderBeginnerContest284(D,E,F)DD这可题的大意是有一个很大的数,n,它可以变成pXpXq(p,q是质数),要我们找出这两个质数我们可以发现,这一个n的质因数一定只有两个,p,q,而我......
  • C - Count Connected Components -- ATCODER
    C-CountConnectedComponentshttps://atcoder.jp/contests/abc284/tasks/abc284_c 思路寻找独立的子连通图个数。 使用map记录边,即点之间的连通性使用vector记......
  • AtCoder Beginner Contest 284
    AtCoderBeginnerContest284https://atcoder.jp/contests/abc284被D卡了,感觉十分的弱智。GEx看不懂题解(A-SequenceofStrings#include<bits/stdc++.h>usingn......
  • AtCoder Beginner Contest 284 C - Count Connected Components DFS的应用
    TimeLimit:2sec/MemoryLimit:1024MBScore: 300300 pointsProblemStatementYouaregivenasimpleundirectedgraphwith NN verticesnumbered 11 ......
  • Atcoder ABC284 前五题题解
    ABC284A-SequenceofStrings题意:有n个字符串\(s_1,s_2,s_3,...,s_n\),要求按\(n,n-1,n-2,...,1\)的顺序输出样例:输入3TakahashiAokiSnuke输出......
  • Atcoder ABC040D 道路の老朽化対策について
    链接难度:\(\texttt{1656}\)\(n\)个点\(m\)条无向边,每条边\((u_i,v_i)\)有一个对应的时间\(t_i\)。\(q\)次询问,每次询问从\(x_i\)只经过\(t_i>y_i\)的边共能......
  • AtCoder Beginner Contest 284-F - ABCBAC(双哈希)
    F-ABCBAC题目大意:给定一个正整数n,和一个长度为2*n的字符串s问s串能不能是由一个t串经过如下操作变成s串:t串的前i个字符t串的反转串t串的后(n-i)个字符如果存在......
  • AtCoder Beginner Conest 284 解题报告
    AtCoderBeginnerConest284解题报告\(\text{ByDaiRuiChen007}\)\(\text{ContestLink}\)A.SequenceofStrings模拟,时间复杂度\(\Theta(n)\)#include<bits/stdc......
  • 2023.1.7(Atcoder Beginner Contest 284)
    A.HappyNewYear2023Linkhttps://atcoder.jp/contests/abc284/tasks/abc284_dStatement将给定的\(N\)分解成\(N=p^2\cdotq\)的形式,其中\(p,q\)为两个不......