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

AtCoder Beginner Contest 325

时间:2023-11-14 22:23:55浏览次数:40  
标签:AtCoder Beginner int vi cin long vector 325 using

A - Takahashi san

#include <bits/stdc++.h>

using namespace std;

#define ll long long

using vi = vector<int>;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s , t;
    cin >> s >> t;
    cout << s << " san\n";
    return 0;
}

B - World Meeting

//#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

#define ll long long

#define int long long

using vi = vector<int>;


int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vi w( 24 );

    for( int i = 1 , a , b ; i <= n ; i ++ )
        cin >> a >> b , w[b] += a;
    int res = 0;

    for( int l = 0 , r = 8  ; l <= 23 ; l ++ , r ++ ){
        int cnt = 0;
        for ( int i = l ; i <= r ; i ++ )
            cnt += w[ i % 24 ];
        res = max( res , cnt );        
    }

    cout << res << "\n";

    return 0;
}

C - Sensors

#include <bits/stdc++.h>

using namespace std;

#define ll long long

using vi = vector<int>;

int dx[] = {0,0,1,-1,1,1,-1,-1};
int dy[] = {1,-1,0,0,1,-1,1,-1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int H,W;cin >> H >> W;
    vector<string> s(H);
    for (int i = 0;i < H;i++){
        cin >> s[i];
    }
    vector<vector<int>> vis(H,vector<int>(W));

    int res = 0;
    auto dd = [&](int x,int y)->void{
        queue<pair<int,int>> q;
        q.emplace(x,y);
        while (!q.empty()){
            auto [u,v] = q.front();
            q.pop();
            if (vis[u][v]) continue;
            
            vis[u][v] = 1;
            

            for (int i = 0;i < 8;i++){
                int tx = u + dx[i],ty = v + dy[i];
                if (tx < 0 || tx >= H || ty < 0 || ty >= W || vis[tx][ty]) continue;
                if (s[tx][ty] == '.') continue;
                q.emplace(tx,ty);
            }
        }


    };  

    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            if (vis[i][j] || s[i][j] == '.') continue;
            res++;
            dd(i,j);
        }
    }
    cout << res << endl;

    return 0;
}

D - Printing Machine

枚举开始时间,然后把所有已经到达的加入到队列中,然后每次贪心的选择结束时间最少的即可。

#include <bits/stdc++.h>

using namespace std;

#define int long long
using i32 = int32_t;
using vi = vector<int>;
using pii = pair<int, int>;

const int inf = 1e9, INF = 1e18;
const int mod = 998244353;


i32 main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    vector<pii> p(n);

    for (auto &[x, y]: p) cin >> x >> y;
    p.emplace_back(LLONG_MAX, LLONG_MAX);
    sort(p.begin(), p.end());
    multiset<int> cnt;
    int now = 0, res = 0;
    for (int i = 0; i < n;) {
        now = max(now, p[i].first);
        for (; i < n and p[i].first <= now; i++)
            cnt.insert(p[i].first + p[i].second);
        while (!p.empty() and now < p[i].first) {
            auto it = cnt.lower_bound(now);
            if (it == cnt.end()) break;
            cnt.erase(it);
            now++, res++;
        }
    }
    cout << res << "\n";
    return 0;
}

E - Our clients, please wait a moment

根据汽车火车分别建图,然后求两遍最短路,然后枚举换乘点即可

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define int long long

using vi = vector<int>;


const int inf = 1e18;


int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n ;
    cin >> n;
    int a , b , c;
    cin >> a >> b >> c;
    vector<vi> g( n+1 , vi( n + 1 ) );
    auto f = g;
    for( int i = 1 ; i <= n ; i ++ ){
        for( int j = 1 , x ; j <= n ; j ++ ){
            cin >> x;
            g[i][j] = x * a;
            f[i][j] = x * b + c ;
        }
    } 

    vi dis( n+1 , inf );
    vi dis1(n + 1,inf);
    dis[1] = 0;
    priority_queue<pair<int,int> , vector<pair<int,int>> , greater<pair<int,int>>> q;
    q.emplace( 0 , 1 );
    vi vis( n + 1 );

    while( !q.empty() ){
        auto [ d , x ] = q.top();
        q.pop();
        if( vis[x] ) continue;
        vis[x] = 1;
        for( int y = 1 ; y <= n ; y ++ ){
            if( dis[y] <= d + g[x][y] ) continue;
            dis[y] = d + g[x][y];
            q.emplace( dis[y] , y );
        }
    }
    
    dis1[n] = 0;
    priority_queue<pair<int,int> , vector<pair<int,int>> , greater<pair<int,int>>> q1;
    q1.emplace( 0 , n );
    vi vis1( n + 1 );

    while( !q1.empty() ){
        auto [ d , x ] = q1.top();
        q1.pop();
        if( vis1[x] ) continue;
        vis1[x] = 1;
        for( int y = 1 ; y <= n ; y ++ ){
            if( dis1[y] <= d + f[x][y] ) continue;
            dis1[y] = d + f[x][y];
            q1.emplace( dis1[y] , y );
        }
    }
    int res = 1e18;
    for (int i = 1;i <= n;i++){
        res = min(res,dis[i] + dis1[i]);
    }
    cout << res << endl;

    return 0;
}

F - Sensor Optimization Dilemma

\(f[i][j]\)表示前\(i\)个部分用了\(j\)个 1 型监控器最少用多少个 2 型监控器。然后枚举一下\(i\)位用了多少个 1 型监控器即可。

#include <bits/stdc++.h>

using namespace std;

#define int long long
using i32 = int32_t;
using vi = vector<int>;
using pii = pair<int, int>;

const int inf = 1e10, INF = 1e18;
const int mod = 998244353;


i32 main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    vi d(n + 1);
    for (int i = 1; i <= n; i++) cin >> d[i];
    int l1, c1, k1, l2, c2, k2;
    cin >> l1 >> c1 >> k1 >> l2 >> c2 >> k2;
    vector f(n + 1, vi(k1 + 1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= k1; j++) {
            f[i][j] = inf;
            for (int k = 0, t; k <= j; k++) {
                t = d[i] - k * l1, t = (t + l2 - 1) / l2;
                f[i][j] = min(f[i][j], f[i - 1][j - k] + t);
                if (t == 0) break;
            }
        }
    }
    int res = INF;
    for (int i = 0; i <= k1; i++)
        if (f[n][i] <= k2) res = min(res, c1 * i + c2 * f[n][i]);
    if( res == INF ) cout << "-1\n";
    else cout << res << "\n";
    return 0;
}

G - offence

一个不太好想的区间 dp

\(f[l][r]\)表示\([l,r]\)经过若干次操作后所能剩下的最短长度,则答案即为\(f[0][n-1]\)

转移首先考虑用两个子区间拼起来的最优解,其次再考虑端点为of的情况。

#include <bits/stdc++.h>

using namespace std;

#define int long long
using i32 = int32_t;
using vi = vector<int>;
using pii = pair<int, int>;

const int inf = 1e10, INF = 1e18;
const int mod = 998244353;


i32 main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int K;
    string s;
    cin >> s >> K;
    int n = s.size();
    vector f(n + 1, vi(n + 1));
    for (int l = 0; l < n; l++)
        for (int r = 0; r < n; r++)
            f[l][r] = r - l + 1;

    for (int len = 2; len <= n; len++) {
        for (int l = 0, r = len - 1; r < n; l++, r++) {
            if (len == 2) {
                if (s[l] == 'o' and s[r] == 'f') f[l][r] = 0;
            } else {
                for (int k = l; k < r; k++)
                    f[l][r] = min(f[l][r], f[l][k] + f[k + 1][r]);
                if (s[r] == 'f') {
                    for (int k = l; k < r; k++)
                        if (s[k] == 'o' and f[k + 1][r - 1] == 0)
                            f[l][r] = min(f[l][r], (k == 0) ? 0 : f[l][k - 1]);
                }
                if (s[l] == 'o') {
                    for (int k = l + 1; k <= r; k++) {
                        if (s[k] == 'f' and f[l + 1][k - 1] == 0)
                            f[l][r] = min(f[l][r], max(f[k + 1][r] - K, 0ll));
                    }
                }
            }
        }
    }
    cout << f[0][n - 1] << "\n";
    return 0;
}

标签:AtCoder,Beginner,int,vi,cin,long,vector,325,using
From: https://www.cnblogs.com/PHarr/p/17832730.html

相关文章

  • Toyota Programming Contest 2023#7(AtCoder Beginner Contest 328)
    ToyotaProgrammingContest2023#7(AtCoderBeginnerContest328)A.NotTooHard题意:将给定的数列\(a\)中数值小于\(x\)的数累加。解题思路:模拟。代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;voidsolve(){ intn,x; cin>>n>>x;......
  • 2023-2024-1 20231325 《计算机基础与程序设计》第7周学习总结
    ###目录*作业信息*教材学习内容总结1.《计算机科学概论》第8章2.《c语言程序设计》第6章*基于AI的学习*学习心得*学习进度条作业信息这个作业属于哪个课程2023-2024-1《计算机基础与程序设计》这个作业的要求在哪里1.学习《计算机科学概论》第8章并完成......
  • AtCoder Beginner Contest 328
    A-NotTooHard(abc328A)题目大意给定\(n\)个数字和一个数\(x\)。问不大于\(x\)的数的和。解题思路按找要求累计符合条件的数的和即可。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=longlong;intmain(void){ios::sync_with_stdi......
  • AtCoder Beginner Contest 328
    A傻逼题。B傻逼题C傻逼题D不难发现,每次添加一个字符,如果可以当前的答案组成ABC就删。然后模拟即可。E两种方法。二进制枚举使用了哪些边。可以发现有用的状态只有\(\binom{m}{n-1}\),上限大概\(10^5\),剩余无用状态过了就行。复杂度\(O(m2^m)\),但是跑的特别不满。......
  • cf1325D. Ehab the Xorcist(位运算trick)
    https://codeforces.com/contest/1325/problem/D有一个非常经典的结论a+b=(a^b)+2(a&b)这个题就可以往上面靠,首先我们观察一下,对于两个数的情况,如果(v-u)mod2=1,必然无解,试着将它扩展一下,也是对的,因为最低一位没有进位。可以确定的是ans<=3仿照上面的式子,令a=u,b=c=((a+b......
  • AtCoder Beginner Contest(abc) 322
    B-PrefixandSuffix难度:⭐题目大意给定两个字符串t和s,如果t是s的前缀则输出1,如果是后缀则输出2,如果都是则输出0,都不是则输出3;解题思路暴力即可;神秘代码#include<bits/stdc++.h>#defineintl1ngl1ng#defineIOSios::sync_with_stdio(false),cin.......
  • 20211325 2023-2024-1 《信息安全系统设计与实现(上)》第九周学习笔记
     202113252023-2024-1《信息安全系统设计与实现(上)》第九周学习笔记一、任务要求自学教材第6章,提交学习笔记(10分),评分标准如下1.知识点归纳以及自己最有收获的内容,选择至少2个知识点利用chatgpt等工具进行苏格拉底挑战,并提交过程截图,提示过程参考下面内容(4分)“我在学***X知......
  • D - Good Tuple Problem atcoder abc 327
    D-GoodTupleProblemhttps://atcoder.jp/contests/abc327/tasks/abc327_d 思路https://www.zhihu.com/question/292465499判断二分图的常见方法是染色法:用两种颜色,对所有顶点逐个染色,且相邻顶点染不同的颜色如果发现相邻顶点染了同一种颜色,就认为此图不为二分图当所......
  • 【杂题乱写】AtCoder-ARC116
    AtCoder-ARC116_CMultipleSequences朴素DP是设\(f_{i,j}\)表示第\(i\)个位置填\(j\)的方案数,时间复杂度\(O(n^2\logV)\)。考虑求出元素都不同序列个数,再根据长度乘组合数,这样长度是\(O(\logV)\)的,复杂度\(O(n\log^2V)\)。提交记录:Submission-AtCoder......
  • 【misc】[HNCTF 2022 Week1]calc_jail_beginner_level2.5(JAIL) --沙盒逃逸,breakpoint
    查看附件内容这道题过滤挺多重要的函数,比如exec,input,eval,还对长度做了限制,这里了尝试了help函数,但是最后一步!ls没通,接着考虑breakpoin函数:Python中内置了一个名为breakpoint()的函数,在Python3.7中引入,用于在调试模式下设置断点。使用breakpoint()函数会停止程序的执行,并在......