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

AtCoder Beginner Contest 133

时间:2023-01-10 23:00:11浏览次数:76  
标签:AtCoder val Beginner int namespace cin long 133 ++

AtCoder Beginner Contest 133

https://atcoder.jp/contests/abc133

A - T or T

#include <bits/stdc++.h>

using namespace std;

int main (){
    int a, b, n;
    cin >> n >> a >> b;
    cout << min (a * n, b);
}#include <bits/stdc++.h>

using namespace std;

int main (){
    int a, b, n;
    cin >> n >> a >> b;
    cout << min (a * n, b);
}

B - Good Distance

#include <bits/stdc++.h>

using namespace std;
const int N = 15;
int a[N][N], n, m, ans;

int main (){
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }

    for (int i = 1; i < n; i++) {
        for (int ii = i + 1; ii <= n; ii++) {
            int sum = 0;
            for (int j = 1; j <= m; j++) {
                sum += (a[ii][j] - a[i][j]) * (a[ii][j] - a[i][j]);
            }
            if ((int)sqrt (sum) == sqrt(sum))   ans ++;
        }
    }
    cout << ans;
}

C - Remainder Minimization 2019

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 15;
vector<int> v;
int ans = 2018 * 2018;

signed main (){
    int l, r;
    cin >> l >> r;
    for (int i = l; i < r; i++) {
        for (int j = i + 1; j <= r; j++) {
            ans = min (ans, (i * j) % 2019);
            if (!ans)   break;
        }
        if (!ans)   break;
    }
    cout << ans;
}

//找到离2019的倍数最近的几个

D - Rain Flows into Dams

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 1e5 + 5;
int a[N], b[N], n;

signed main (){
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = n - 1; i >= 0; i -= 2)     b[0] +=a[i];
    for (int i = n - 2; i >= 0; i -= 2)     b[0] -=a[i];
    for (int i = 1; i < n; i++)     b[i] = 2 * a[i-1] - b[i-1];
    for (int i = 0; i < n; i++)     cout << b[i] << ' ';
}

//解方程

E - Virus Tree 2

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 1e5 + 5, M = N * 2, mod = 1000000007;
int n, k, dep[N], cnt[N]; //深度, 深度为i的时候有多少个
int h[N], e[M], ne[M], idx;
int ans = 1, val[N];

void add (int a, int b) {
    e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

void dfs (int u, int fa) {
    dep[u] = dep[fa] + 1;
    for (int i = h[u]; ~i; i = ne[i]) {
        int j = e[i];
        if (j == fa)    continue;
        dfs (j, u);
    }
}

void count (int u, int fa) {
    if (dep[u] == 2)    val[u] --;
    if (dep[u] >= 3)    val[u] -= 2;

    int flag = false, sum = 0;
    for (int i = h[u]; ~i; i = ne[i]) {
        int j = e[i];
        if (j == fa)    continue;
        if (!flag) {
            flag = true;
            sum = val[j];
        }
        else {
            val[j] = sum - 1;
            sum = val[j];
        }
    }
    for (int i = h[u]; ~i; i = ne[i]) {
        int j = e[i];
        if (j == fa)    continue;
        count (j, u);
    }
}

signed main () {
    memset (h, -1, sizeof h);
    cin >> n >> k;
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        add (a, b), add (b, a);
    }
    dfs (1, 0);
    for (int i = 1; i <= n; i++)    val[i] = k;
    count (1, 0);
    for (int i = 1; i <= n; i++) {
        ans = (ans * max (0ll, val[i])) % mod;
        if (!ans)   break;
    }
    
    cout << ans << endl;
}

//注意对0取max

F - Colorful Tree

标签:AtCoder,val,Beginner,int,namespace,cin,long,133,++
From: https://www.cnblogs.com/CTing/p/17041624.html

相关文章

  • AtCoder Beginner Contest 171
    A-αlphabet(abc171a)题目大意给定一个字母,其大写字母则输出A,否则输出a。解题思路isupper函数或者在'A'与Z之间即为大写字母。神奇的代码#include<bits/stdc+......
  • AtCoder284 D - Happy New Year 2023
    AtCoder284D-HappyNewYear2023[Editorial](Editorial-AtCoderBeginnerContest284)Youaregivenapositiveinteger\(N\).Itisknownthat\(N\)canbe......
  • AtCoder Beginner Contest 284
    A-SequenceofStrings#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){intn;cin>>n;vector<string>s(n);for(auto&i:s)......
  • 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\)的边共能......