【补题】Educational Codeforces Round 85 (Rated for Div. 2)

C题直接贪心,D题欧拉回路,理论上应该会做的……

然后应该读题比较慢的关系,A题+B题各做了20分钟……还是15分钟内连切两道比较理想,毕竟挂了梯子,开CF的速度也不慢。



C. Circle of Monsters

\(n\)只怪物站成一圈,第\(i\)只怪物有\(a[i]\)点生命值和\(b[i]\)点爆炸伤害。当第\(i\)只怪物死亡时会爆炸,且只对第\(i+1\)只怪物造成\(b[i]\)点伤害。爆炸可以传递。每次开枪会对其中一只怪物造成\(1\)点伤害,求能杀死全部怪物的最小开枪次数。

这题的数据范围有点emmm,我还以为要想办法写\(O(1)\)来着,其实是\(O(n)\)。

对每只怪物视为首个击杀目标,计算要补枪的次数(就是其它怪物扣除爆炸伤害后的剩余血量)遍历n只就好,用set维护最小值(感觉get到了什么新用法……)。

注意\(n==1\)时特判一下。

#include<iostream>
#include<map>
#include<cstring>
#include<math.h>
#include<algorithm>
#include<set>
using namespace std;

const int N = 1e5 + 5;

int main()
{
    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        long long int arr[N], pow[N], shrey[N];
        set<long long int> s;
        cin >> arr[0] >> pow[0];
        if (n == 1) {//只有一只怪物,特判
            cout << arr[0] << endl;
            continue;
        }
        long long int sum = 0;//不会被直接炸死的怪物的剩余血量
        for (int i = 1;i < n;i++) {
            cin >> arr[i] >> pow[i];
            shrey[i] = arr[i] - pow[i - 1];//shrey[i]是第i只怪物被炸后的剩余血量
            if (shrey[i] > 0) {//不会被直接炸死
                sum += shrey[i];//剩余血量
            }
        }
        shrey[0] = arr[0] - pow[n - 1];
        if (shrey[0] > 0) sum += shrey[0];
        for (int i = 0;i < n;i++) {
            if (shrey[i] > 0) {
                s.insert(sum - shrey[i] + arr[i]);
                //总残余血量-这只怪物残余血量+这只怪物生命值
                //即将它视为首个目标时需要的子弹数量
            }
            else {
                s.insert(sum + arr[i]);//总残余血量-(0)+生命值
            }
        }
        cout << *s.begin() << endl;//输出最小值
    }
    return 0;
}

原文地址:https://www.cnblogs.com/streamazure/p/12677497.html

时间: 2024-07-31 12:12:10

【补题】Educational Codeforces Round 85 (Rated for Div. 2)的相关文章

Educational Codeforces Round 85 (Rated for Div. 2)

Educational Codeforces Round 85 (Rated for Div. 2) A. Level Statistics 签到题, 要求第一位维单增, 第二维变化比第一维慢, 直接模拟即可 B. Middle Class 题目大意 每个人有一些财富, 财富值超过x的人称为富人, 由于实行共产主义, 你可以将某些人的财产重新分配使得富人最多 解题思路 直接按财富值排序, 从大到小加入富人集合, 如果当前富人集合财富平均值小于x就break掉 C. Circle of Monst

Codeforces 1082 D. Maximum Diameter Graph-树的直径-最长链-构造题 (Educational Codeforces Round 55 (Rated for Div. 2))

D. Maximum Diameter Graph time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Graph constructive problems are back! This time the graph you are asked to build should match the following proper

E. XOR Guessing 交互题 Educational Codeforces Round 71 (Rated for Div. 2)

E. XOR Guessing 交互题. 因为这个数最多只有14位 0~13,所以我们可以先处理后面7位,然后再处理后面7位. 因为异或的性质,如果一个数和0异或,那么就等于本身. 所以我们第一次异或1~100 所以 后面从7到13位就都是0,所以结果的后面的7位就可以算出来. 然后同理可以把前面七位找到. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm>

Educational Codeforces Round 74 (Rated for Div. 2)补题

慢慢来. 题目册 题目 A B C D E F G 状态 √ √ √ √ × ? ? //√,×,? 想法 A. Prime Subtraction res tp A 题意:给定\(x,y(x>y)\),问能否将\(x-y\)拆成任意多个质数之和 1.任意大于\(1\)的整数\(k\)都可以用\(2\)与\(3\)的线性表示 证: 若\(k\)是偶数,显然: 若\(k\)是奇数,则\(k\)可以表示成\(k = 3 + 2*k'\),显然: 毕. #include<bits/stdc++.h&

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

get人生第七场CF! 成绩:(exACM) rank AC3/7 Penalty104 rating() 题目:Educational Codeforces Round 58 (Rated for Div. 2) 错题题解: C. Division and Union 原文地址:https://www.cnblogs.com/xht37/p/10260260.html

Educational Codeforces Round 59 (Rated for Div. 2) DE题解

Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contest/1107/problem/D 题意: 给出一个n*(n/4)的矩阵,这个矩阵原本是一些01矩阵,但是现在四个四个储存进二进制里面,现在给出的矩阵为0~9以及A~F,表示0~15. 然后问这个矩阵能否压缩为一个(n/x)*(n/x)的矩阵,满足原矩阵中大小为x*x的子矩阵所有数都相等(所有子矩阵构