codeforces C. Circle of Monsters
程序员文章站
2022-06-27 11:52:16
...
题目
题意:
给你一个环,环中有个小怪兽,然后你有若干子弹,当你杀死一只怪兽的时候,它会对下一个造成的伤害,每一只怪兽有的血,
思路:
我们可以把设置一个就是前一个怪兽死后,这只怪兽剩下的血量,如果不等于的话,那么这一部分使肯定要用子弹取打的,所以要加上,最后得到一个,但是这样算还缺了一部分,那就是刚开始的第一只怪兽必须用子弹去打,所以我们只要加上出。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
inline void out(int x) {
if (x > 9) out(x / 10);
putchar(x % 10 + '0');
}
const int maxn = 3e+5 + 10;
ll a[maxn] = {0}, b[maxn] = {0}, c[maxn] = {0};
int main() {
int t, n;
read(t);
while (t--) {
ll sum = 0;
read(n);
for (int i = 1; i <= n; i++) {
read(a[i]), read(b[i]);
if (i > 1) {
c[i] = max(0ll, a[i] - b[i - 1]);
sum += c[i];
}
}
c[1] = max(a[1] - b[n], 0ll);
sum += c[1];
ll Min = 1e13;
for (int i = 1; i <= n; i++) {
Min = min(Min, a[i] - c[i]);
}
sum += Min;
printf("%lld\n", sum);
}
return 0;
}
推荐阅读
-
codeforces C. Count Triangles
-
Codeforces 1355 C. Count Triangles
-
codeforces C. K-th Not Divisible by n
-
Codeforces Round #320 (Div. 2) C. A Problem about Polyline ( 数学 )
-
Codeforces Round #654 (Div. 2)-C. A Cookie for You
-
A. Circle of Students(遍历匹配)Codeforces Round #579 (Div. 3)
-
CodeForces - 1169A A - Circle Metro
-
Educational Codeforces Round 85 (Rated for Div. 2) C. Circle of Monsters(前缀和 预处理 贪心)
-
codeforces C. Circle of Monsters
-
Codeforces Round #651 (Div. 2) C. Number Game