首页 > 其他分享 >Educational Codeforces Round 158 补题(A~D)

Educational Codeforces Round 158 补题(A~D)

时间:2023-11-25 20:13:32浏览次数:38  
标签:Educational int 158 long i64 solve 补题 ans using

A.

思路

找出最大耗油的路程即可

ac代码

#include <bits/stdc++.h>

using namespace std;
using i64  = long long;
const i64 inf = 8e18;
typedef pair<int, int> pii;

void solve() {
    int n, x;
    cin >> n >> x;
    std::vector<int> v(n);
    for (auto &i : v) cin >> i;

    int ans = v[0];
    for (int i = 1; i < n; i++) {
        ans = max(ans, v[i] - v[i - 1]);
    }

    if (v.back() != x) ans = max(ans, 2 * (x - v.back()));
    cout << ans << endl;

}

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

    int t = 1;
    cin >> t;
    while (t --) solve();

    return 0;
}

B.

思路

将芯片传送才能做到后一个比前一个大

ac代码

#include <bits/stdc++.h>

using namespace std;
using i64  = long long;
const i64 inf = 8e18;
typedef pair<int, int> pii;

void solve() {
    int n;
    cin >> n;
    std::vector<int> v(n);
    for (auto &i : v) cin >> i;
    i64 ans = 0;
    for (int i = 1; i < n; i++) {
        if (v[i] > v[i - 1]) ans += (v[i] - v[i - 1]);
    }
    cout << ans + (v[0] - 1) << endl;

}

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

    int t = 1;
    cin >> t;
    while (t --) solve();

    return 0;
}

C.

思路

要使得数组里的所有元素相等,就要使得最大最小值相等

ac代码

#include <bits/stdc++.h>

using namespace std;
using i64  = long long;
const i64 inf = 8e18;
typedef pair<int, int> pii;

void solve() {
    int n;
    cin >> n;
    i64 mx = -1, mn = inf;
    std::vector<i64> v(n);
    for (auto &i : v) {
        cin >> i;
        mx = max(mx, i);
        mn = min(mn, i);
    }


    vector<i64> ans;
    while (mx != mn) {
        mx = (mx + mn) / 2;
        ans.push_back(mn);
    }
    cout << ans.size() << endl;
    if (ans.size() <= n && ans.size()) {
        for(auto i : ans) cout << i << ' ';
        cout << endl;
    }

}

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

    int t = 1;
    cin >> t;
    while (t --) solve();

    return 0;
}

D.

思路

假设最小的能杀死全部怪物的攻击力是\(x\),第一个攻击的是\(i\)。则最坏情况下消灭第\(j\)个士兵的要满足:

  • \(v[j]<=x-(n-j)\) , \(j < i\)
  • \(v[j]<=x-(j-1)\) , \(j > i\)
    移项得
  • \(x>=v[j]+n-j\) , \(j < i\)
  • \(x>=v[j]+j-1\) , \(j > i\)
#include <bits/stdc++.h>

using namespace std;
using i64  = long long;
const i64 inf = 8e18;
typedef pair<int, int> pii;

void solve() {
    int n;
    cin >> n;
    vector<i64> v(n + 1), pre(n + 1), suf(n + 2);
    for (int i = 1; i <= n; i++) cin >> v[i];

    for (int i = 1; i <= n; i++) pre[i] = max(pre[i - 1], v[i] + n - i);
    for (int i = n; i >= 1; i--) suf[i] = max(suf[i + 1], v[i] + i - 1);

    i64 ans = inf;
    for (int i = 1; i <= n; i ++) //枚举第一个攻击的是谁
        ans = min(ans, max({suf[i + 1], pre[i - 1], v[i]}));
        
    cout << ans << endl;
}

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

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

    return 0;
}

标签:Educational,int,158,long,i64,solve,补题,ans,using
From: https://www.cnblogs.com/kichuan/p/17855983.html

相关文章

  • Educational Codeforces Round 158 (Rated for Div. 2)
    A.LineTrip题意是:有n个加油点,人要来回两趟,问你最少要多少油?usingnamespacestd;inta[100];voidsolve(){ intn,m; cin>>n>>m; for(inti=1;i<=n;i++)cin>>a[i]; intans=a[1]; for(inti=2;i<=n;i++){ ans=max(ans,a[i]-a[i-1]); } ans=max(ans,2*(m-......
  • Educational Codeforces Round 146 补题(A~C)
    EducationalCodeforcesRound146(RatedforDiv.2)A.Coins题目大意给你两个整数n和k,问你是否存在两个非负整数x和y,使得2⋅x+k⋅y=n成立思路裴蜀定理秒了,记得开longlongac代码#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong;consti64in......
  • Educational Codeforces Round 158 (Rated for Div. 2) A-C
    A大致题意:有一条长度为x的直线公路,最开始你位于0号点并且此时你的油箱装满了油,公路有n个加油站,当你经过加油站的时候你可以在加油站加满油,每走一个单位需要花费1升油量,起始位置和终点没有加油站,请问你的油箱容量至少为多少升才可以够你跑一个来回。解题思路:我们的路径大致是......
  • 「杂题乱刷」CF1585B
    原题链接CF1585BArrayEversion题目简述现在有一个长度为\(n\)的序列\(a\),每次操作将\(a\)中不大于序列\(a\)中最后一个数的元素按照在\(a\)序列中的顺序放入\(b\)序列中,大于序列\(a\)中最后一个数的元素同样按照在\(a\)中的顺序放入\(c\)序列中,然后再将\(c......
  • CSE 158/258 设计与实现
    任务定于11月20日星期一完成,但请确保将解决方案上传到排行榜有规律地您应该提交两个文件:writeup.txt对每个任务的解决方案进行简要的纯文本描述;请在提交截止日期提前;这只是为了帮助我们遵循您的代码,不需要待详细说明。assignment1.py包含解决方案的工作代码的python文件。自动标......
  • Educational Codeforces Round 99 (Rated for Div. 2)
    https://codeforces.com/contest/1455很久没有vp了,感觉思维又僵化了A题直接看样例,直接猜是长度。B题首先如果是\(x=\frac{n(n+1)}{2}\),那么就是n否则如果\(x=\frac{n(n+1)}{2}+y\),分成两类y=n,ans=n+2,y<n,我们总可以找到前面一个替换,然后恰好的到n,选取z=n-y即可C题感觉比B......
  • Educational Codeforces Round 156 (Rated for Div. 2) ABCD
    EducationalCodeforcesRound156(RatedforDiv.2)ABCDA.SumofThree题意:给定正整数\(n\),判断是否存在正整数\(a\),\(b\),\(c\)满足:\(a+b+c=n\)。\(a\),\(b\),\(c\)均不是\(3\)的倍数。如存在,输出YES并构造一组方案,否则输出NO。思路:法一:我们分类讨论。根据......
  • Educational Codeforces Round 13 E
    tilian最开始看错了以为是可以任意选择两人or选择一人胜出但题意是可以选择下一个擂主是谁考虑dp的话我们显然需要记录一个state以及当前擂主是谁转移就是dp[state][i]=max(dp[state][i],dp[state(1<<j)][j]*a[i][j]+dp[state(1<<i)]*a[j][i])意义是我们枚举他后一个交......
  • 2020 NOIP 补题
    P7113[NOIP2020]排水系统拓扑排序,但是\(\_\_int128\)。#include<bits/stdc++.h>usingnamespacestd;#defineendl'\n'#defineinlinline#defineebemplace_back#definepbpop_back#definemid(l+r>>1)#definelsp<<1#definersp......
  • Educational Codeforces Round 157 D
    tilian不太会这种题发现找到一个数就能确定整个序列然后转而发现前缀异或和b1^b2=a1b1^b3=a2...我们发现要是n为偶数时能直接求出b1从而确定整个序列而为奇数时我们无法确定b1我们思考拆位之后如果b1该位为0算出真实的异或后的01个数b1该位为1算出真实的......