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

AtCoder Beginner Contest 129

时间:2023-01-02 23:45:17浏览次数:59  
标签:f0 AtCoder Beginner f1 int using 129 include mod

AtCoder Beginner Contest 129

https://atcoder.jp/contests/abc129
4/6: ABCD

A - Airplane

水题:

#include <bits/stdc++.h>

using namespace std;

int main () {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a + b + c - max ({a, b, c});
}

B - Balance

前缀和水题

#include <bits/stdc++.h>

using namespace std;
const int N = 105;
int a[N], pre[N], suf[N], n, ans = 1e9;

int main () {
    cin >> n;
    for (int i = 1; i <= n; i++)    cin >> a[i], pre[i] = pre[i-1] + a[i];
    for (int i = n; i >= 1; i--)    suf[i] = suf[i+1] + a[i];
    for (int i = 1; i <= n; i++) {
        ans = min (ans, abs (pre[i] - suf[i+1]));
    }
    cout << ans;
}

C - Typical Stairs

dp水题

#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5, mod = 1000000007;
int x, n, m, f[N];

int main () {
    cin >> n >> m;
    map<int, int> mp;
    for (int i = 1; i <= m; i++)    cin >> x, mp[x] ++;
    if (n == 1) {
        if (mp[1])  cout << 0;
        else    cout << 1;
        return 0;
    }
    f[0] = 1;
    if (!mp[1])     f[1] = 1;

    for (int i = 2; i <= n; i++) {
        if (mp[i])  continue;
        if (!mp[i-1])   f[i] = (f[i] + f[i-1]) % mod;
        if (!mp[i-2])   f[i] = (f[i] + f[i-2]) % mod;;
    }
    cout << f[n];
}

D - Lamp

二分
因为把n写成m而WA了两发,太sb了

#include <bits/stdc++.h>

using namespace std;
const int N = 2005;
int n, m, hang[N][N], lie[N][N], ans;
char a[N][N];
vector <int> v1[N], v2[N];

void print () {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << hang[i][j] << ' ';
        }
        cout << endl;
    }
    cout << endl;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << lie[i][j] << ' ';
        }
        cout << endl;
    }
    cout << endl;
}

int main () {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
            if (a[i][j] == '#')     v1[i].push_back (j), v2[j].push_back (i);
        }
        v1[i].push_back (m + 1);
    }
    for (int j = 1; j <= m; j++)    v2[j].push_back (n + 1);

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i][j] == '#') continue;
            int pos = *upper_bound (v1[i].begin (), v1[i].end (), j);
            //cout << pos - j << ' ';
            for (int k = j; k < pos; k++)   hang[i][k] = pos - j;
            j = pos;
        }
        //cout << endl;
    }

    for (int j = 1; j <= m; j++) {
        for (int i = 1; i <= n; i++) {
            if (a[i][j] == '#') continue;
            int pos = *upper_bound (v2[j].begin (), v2[j].end (), i);
            //cout << pos - i << ' ';
            for (int k = i; k < pos; k++)   lie[k][j] = pos - i;
            i = pos;
        }
        //cout << endl;
    }

    //print ();

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i][j] == '#') continue;
            ans = max (ans, hang[i][j] + lie[i][j] - 1);
        }
    }
    cout << ans;
}

E - Sum Equals Xor

锻炼dp思想的好题。
前提:异或是不进位加法
转移过程详见代码注释。

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

using namespace std;
const int mod = 1e9 + 7;
ll f1 = 1, f0; //f1表示相等,f0表示小于

int main () {
    string s;
    cin >> s;
    for (int i = 0; i < s.size (); i++) {
        if (s[i] == '0') { 
            f0 = (f0 * 3) % mod; //放(0,1)或(1,0)或(0,0),只要不进位就行
            f1 = f1; // 只能放(0,0)
        }
        else { //s[i] == '1'
            f0 = (f0 * 3 + f1) % mod; //不进位的三种 + 因为当前为小于所以剩下的放什么都行
            f1 = (f1 * 2) % mod; //放(0,1)或(1,0)
            
        }
    }
    cout << (f0 + f1) % mod;
}

//异或就是不进位加法

F - Takahashi's Basics in Education and Learning

明天补

标签:f0,AtCoder,Beginner,f1,int,using,129,include,mod
From: https://www.cnblogs.com/CTing/p/17020858.html

相关文章

  • D - Scope --- ATCODER
    D-Scopehttps://atcoder.jp/contests/abc283/tasks/abc283_d 思路使用stack做字符串的内容分析,除了)所有的字符依次入栈,遇到(字符,则从栈顶开始依次出栈,直到第一个(也......
  • AtCoder Beginner Contest 283 - a new beginning
    许久没有写过博客了,让2023成为一个新的起点,重新开始写博客。尽量写的高质量一点,从E开始。E-Don'tIsolateElements考虑dp,考虑如何设计状态。不难看出,每一行变两......
  • AtCoder Beginner Contest 200 vp记
    又来vp了一场比赛\(\dots\dots\)AtCoderBeginnerContest200vp记ProblemA这道题不会有人要解析吧Code#include<bits/stdc++.h>#defineintlonglong#define......
  • UNIQUE VISION Programming Contest 2022 Winter(AtCoder Beginner Contest 283)
    A-PowerGivenintegersAandB,printthevalueA^B.基础不解答B-FirstQueryProblem基础不解答C-CashRegisterTakahashiisacashier.Thereis......
  • [AtCoder Regular Contest 077] F: SS (arc077F)
    原题链接​​​https://arc077.contest.atcoder.jp/tasks/arc077_d​​Description定义偶串为这个字符串前一半和后一半相同(abadabad)定义函数f(S)表示在S这个字符串后......
  • [AtCoder Grand Contest 018] D: Tree and Hamilton Path (agc018D)
    原题链接​​​https://agc018.contest.atcoder.jp/tasks/agc018_d​​Description给出一棵N个点带边权的树现在有一个N个点的完全图,一条边x,y的长度是这两点的在树上最短......
  • [AtCoder Grand Contest 071] E: Jigsaw (agc071E)
    原题链接​​​https://agc017.contest.atcoder.jp/tasks/agc017_e​​Description给出N块拼图每块拼图宽度为3,高度为相同的H拼图由3个宽度为1的部分拼接而成,第一部分......
  • AtCoder-abc230_g GCD Permutation 容斥
    J-GCDPermutation传送门:J-GCDPermutation知识点:素数筛、容斥定理、gcd题意:长度为n的一个排列a中,求满足\(gcd(i,j)!=1且gcd(a_i,a_j)!=1\)的i,j对数。i,j可以......
  • The CBO and Indexes: An Introduction (Absolute Beginners)
    OneofthemorecommonquestionsIgetaskedandoneofthemostcommonquestionsaskedinthevariousOraclerelatedforumsisthegeneralquestionofwhydoes......
  • AtCoder Beginner Contest 239总结
    由于比赛延期了一个星期,今天才打,恰巧我记错了时间,本来是8:00,我记成9:00,然后·········幸运的是我还是把前四题做出来了(intwentyminutes),由于时间问题,我......