首页 > 其他分享 >Toyota Programming Contest 2024#1(AtCoder Beginner Contest 337)

Toyota Programming Contest 2024#1(AtCoder Beginner Contest 337)

时间:2024-01-21 23:12:49浏览次数:36  
标签:AtCoder Beginner Contest int long -- solve using define

Toyota Programming Contest 2024#1(AtCoder Beginner Contest 337)

A - Scoreboard

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using i128 = __int128_t;

void solve()
{
    int n;
    cin >> n;
    int x = 0;
    int y = 0;
    for (int i = 1; i <= n; i++)
    {
        int a, b;
        cin >> a >> b;
        x += a;
        y += b;
    }
    int ans = x - y;
    if (ans > 0)
    {
        puts("Takahashi");
    }
    else if (ans < 0)
    {
        puts("Aoki");
    }
    else
    {
        puts("Draw");
    }
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

B - Extended ABC

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using i128 = __int128_t;

void solve()
{
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 1; i < n; i++)
    {
        if (s[i] < s[i - 1])
        {
            puts("No");
            return;
        }
    }
    puts("Yes");
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

C - Lining Up 2

解题思路:

\(dfs\)一次即可。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using i128 = __int128_t;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> adj(n + 1);
    int r = 0;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        if (x == -1)
        {
            r = i;
        }
        else
        {
            adj[x].push_back(i);
        }
    }
    auto dfs = [&](auto self, int u) -> void
    {
        cout << u << ' ';
        for (auto v : adj[u])
        {
            self(self, v);
        }
    };
    dfs(dfs, r);
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

D - Cheating Gomoku Narabe

解题思路:

记录时,\(o\)为1,其余为0.

\(a[i][j]:记录以第i行第j列为末尾,总长度为k的序列的区间和。\)

遍历时,\(x为-1\),其余为\(1\)。遍历过程中,长度为\(k\)的区间和刚好为\(k\)时,\(k - a[i][j]\)就是一种填补数量。

横着跑一次,竖着跑一次。

时间复杂度\(O(n)\).

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using i128 = __int128_t;

void solve()
{
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> g(h + 1);
    for (int i = 1; i <= h; i++)
    {
        cin >> g[i];
        g[i] = ' ' + g[i];
    }
    vector<vector<int>> a(h + 1, vector<int>(w + 1));
    int cur = 0;
    for (int i = 1; i <= h; i++)
    {
        cur = 0;
        queue<int> q;
        for (int j = 1; j <= w; j++)
        {
            if (q.size() == k)
            {
                cur -= q.front();
                q.pop();
            }
            int x = 0;
            if (g[i][j] == 'o')
            {
                x = 1;
            }
            q.push(x);
            cur += x;
            if (q.size() == k)
            {
                // cout << i << ' ' << j << ' ' << cur << endl;
                a[i][j] = cur;
            }
        }
    }
    int ans = 1e9;
    for (int i = 1; i <= h; i++)
    {
        cur = 0;
        queue<int> q;
        for (int j = 1; j <= w; j++)
        {
            if (q.size() == k)
            {
                cur -= q.front();
                q.pop();
            }
            int x = 1;
            if (g[i][j] == 'x')
            {
                x = -1;
            }
            q.push(x);
            cur += x;
            if (q.size() == k)
            {
                if (cur == k)
                {
                    ans = min(k - a[i][j], ans);
                }
            }
        }
    }
    for (int i = 1; i <= w; i++)
    {
        cur = 0;
        queue<int> q;
        for (int j = 1; j <= h; j++)
        {
            if (q.size() == k)
            {
                cur -= q.front();
                q.pop();
            }
            int x = 0;
            if (g[j][i] == 'o')
            {
                x = 1;
            }
            q.push(x);
            cur += x;
            if (q.size() == k)
            {
                // cout << i << ' ' << j << ' ' << cur << endl;
                a[j][i] = cur;
            }
        }
    }
    for (int i = 1; i <= w; i++)
    {
        cur = 0;
        queue<int> q;
        for (int j = 1; j <= h; j++)
        {
            if (q.size() == k)
            {
                cur -= q.front();
                q.pop();
            }
            int x = 1;
            if (g[j][i] == 'x')
            {
                x = -1;
            }
            q.push(x);
            cur += x;
            if (q.size() == k)
            {
                if (cur == k)
                {
                    ans = min(k - a[j][i], ans);
                }
            }
        }
    }
    if (ans > k)
    {
        ans = -1;
    }
    cout << ans << endl;
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

E - Bad Juice

解题思路:

每个人第二天出问题或者没出问题对应二进制变化\(1或者0\)。

所以有\(n\)杯果汁,我们就需要\(n\)中不同的二进制编码。每种唯一即可对应情况选择出坏的果汁。

代码:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define fi first
#define se second
using i128 = __int128_t;

void solve()
{
    int n;
    cin >> n;
    n--;
    int m = 0;
    for (int i = 30; i >= 0; i--)
    {
        if (n >> i & 1)
        {
            cout << i + 1 << endl;
            m = i + 1;
            break;
        }
    }
    vector<vector<int>> a(m + 10, vector<int>(0));
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < 30; j++)
        {
            if (i >> j & 1)
            {
                a[j + 1].push_back(i + 1);
            }
        }
    }
    for (int i = 1; i <= m; i++)
    {
        cout << a[i].size() << ' ';
        for (auto x : a[i])
        {
            cout << x << ' ';
        }
        if (a[i].size() == 0)
        {
            continue;
        }
        cout << endl;
    }
    cout.flush();
    string s;
    cin >> s;
    int ans = 1;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '1')
        {
            ans += 1 << i;
        }
    }
    cout << ans << endl;
    cout.flush();
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

标签:AtCoder,Beginner,Contest,int,long,--,solve,using,define
From: https://www.cnblogs.com/value0/p/17978659

相关文章

  • AtCoder Beginner Contest 337
    基本情况ABC秒了,D数组在空间复杂度上面第一次疯狂吃亏,吃了两次罚时过。赛后看官方题解,发现C做法薄纱我。C-LiningUp2https://atcoder.jp/contests/abc337/tasks/abc337_c这题一眼链表,我用双向链表实现,代码石山。官方题解就题论题,更本质。其实这题并没必要开双向链......
  • Toyota Programming Contest 2024#1(AtCoder Beginner Contest 337)
    ToyotaProgrammingContest2024#1(AtCoderBeginnerContest337)比赛链接A-Scoreboard思路简单的模拟,统计一下总分数就可以了Code#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){ intn; intans1=0; intans2=0; cin>>n; for......
  • AtCoder Beginner Contest 337
    AtCoderBeginnerContest337赛后总结A题不多说,纯水。B题对题目要求没有理解太透(不知道是英语问题,还是它样例给的不够全,没太能理解最后的那个判断结果)卡c题上了c题感觉其实是个比较有意思的题,但是只要理解了题目就知道本质是一个求数组对应的下标,再以数组的下标所对应的数组......
  • AtCoder Beginner Contest 336
    AtCoderBeginnerContest336A-LongLoong代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;usingpii=pair<ll,ll>;#definefifirst#definesesecondusingi128=__int128_t;voidsolve(){intn;cin>&g......
  • 比赛必备——codeforces better 和 atcoder better 的安装教程
    大家有没有像我一样英语不太好然后又想要打cf和atc的呢?(可能全世界就我英语不好)这里有两个强力的工具可以帮助我们解决这一问题——codeforcesbetter和atcoderbetter。由于我只用的是edge,所以下面默认为edge浏览器篡改猴首先我们需要安装篡改猴,link。codeforcesbe......
  • AtCoder Beginner Contest 337
    AtCoderBeginnerContest337做题顺序有点奇怪。先做的C。套路题。令\(to_i\)表示\(i\)的下一个点是什么。2min过了。再做的B。智障题。令\(now\)表示现在在哪个字符(A或B或C),然后挨个字符跳。结果真成智障了,第一发没判断A跳到C的情况,罚时+1。又做的A。入......
  • AtCoder Grand Contest 010 E Rearranging
    洛谷传送门AtCoder传送门赛时在想一些奇怪的东西,没想到建图。考虑使用元素两两之间的相对顺序来描述序列。发现若\(x,y\)互质那么它们的相对顺序被确定了。先把输入的序列从小到大排序。然后考虑互质的数之间先连一条无向边。那么先手要把无向边定向使得它是个DAG,后手会......
  • AtCoder Beginner Contest 337
    A-Scoreboard思路&&Code/*高桥和青木N场比赛xy得分情况分别为x1y1.....xnyn计算高桥的总得分与青木的总得分进行比较高桥得分>青木得分输出Takahashi==输出Draw<输出Aoki*......
  • AtCoder Beginner Contest 336
    AtCoderBeginnerContest33657秒切A,75秒切B。然后C就卡了,没想到五进制,二分答案加数位DP判断过了。用了半个小时。DE读完题,发现D可做。小推了一下发现可以维护线段树。很快写完过了样例。第一发罚时,\(+1\)和\(-1\)写反了。第二发罚时,把那个“金字塔”写成了......
  • 昆虫科学院 AtCoder Race Ranking 2023 Autumn
    概况为提高选手们的训练/比赛热情,我们(昆虫科学院)通过商讨,在\(2023-5-25\)仿照AtCoderRaceRanking(WTF)机制,设立了“昆虫科学院AtCoderRaceRanking2023”。该排行榜为\(2023\sim2024\)赛季的第二轮排行。校内参赛选手(按照学号排序)AtCoder用户名学号......