当前位置:网站首页>Sum of three terms (construction)
Sum of three terms (construction)
2022-07-05 06:16:00 【whitewall_ nine】
https://atcoder.jp/contests/arc135/tasks
#include<iostream>
#include<map>
#include<cstring>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define pii pair<int, int>
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fir first
#define pb push_back
#define sec second
#define sortall(x) sort((x).begin(),(x).end())
inline int read () {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f?-x:x;
}
template<typename T> void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) print(x/10);
putchar(x % 10 + '0');
}
const int mod = 998244353;
const int N = 3e5 + 10;
int a[N];
int s[N];
int n;
void solve() {
cin >> n;
for (int i = 0; i< n; i ++) cin >> a[i];
int minvy = 0, minvx = 0;
// Negative numbers need not be considered , Because he was a positive number , It must be greater than or equal to 0 Conditions , Then we just need to find the smallest negative number
int maxx = 0x3f3f3f3f;
for (int i = 2; i< n + 2; i ++) {
s[i] = a[i - 2] - s[i - 1] - s[i - 2];
if (i % 3 == 0) {
minvy = max (minvy, -s[i]);
}
else if (i % 3 == 1) {
minvx = max(minvx, -s[i]);
}
else {
maxx = min(maxx, s[i]);
}
}
if (minvy + minvx > maxx) {
puts("No");
return ;
}
puts("Yes");
s[0] = minvy, s[1] = minvx;
for (int i = 2; i < n + 2; i ++)
s[i] = a[i - 2] - s[i - 1] - s[i - 2];
for (int i = 0; i < n + 2; i ++)
cout << s[i] << " \n"[i == n + 1];
}
int main () {
int t;
t = 1;
while (t --) solve();
return 0;
}
This problem is solved by finding the boundary range and then constructing a feasible solution . By simplifying the formula You can find i % 3 == 0 s[i] = x +a i % 3 == 1 s[i] = x + b i % 3== 2 s[i] = x - a - b We need to find out whether the limit conditions are feasible To this end, we construct c1, c2, c3 c1 <= a c2 <= b a + b <=c3 c1 + c2<= a + b <= c3 Maximum left , Take the minimum on the right and judge whether it meets the size relationship to judge whether it is feasible . If it is satisfied, just substitute the value directly
边栏推荐
- 【Rust 笔记】16-输入与输出(上)
- 可变电阻器概述——结构、工作和不同应用
- leetcode-1200:最小绝对差
- Leetcode-6111: spiral matrix IV
- Leetcode divide and conquer / dichotomy
- Daily question 1342 Number of operations to change the number to 0
- 数据可视化图表总结(二)
- SQLMAP使用教程(一)
- In depth analysis of for (VaR I = 0; I < 5; i++) {settimeout (() => console.log (I), 1000)}
- leetcode-22:括号生成
猜你喜欢

MySQL advanced part 2: storage engine

Doing SQL performance optimization is really eye-catching

开源存储这么香,为何我们还要坚持自研?

Matrixdb V4.5.0 was launched with a new mars2 storage engine!

LaMDA 不可能觉醒吗?

MIT-6874-Deep Learning in the Life Sciences Week 7

MySQL advanced part 2: MySQL architecture

阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长

Data visualization chart summary (I)

wordpress切换页面,域名变回了IP地址
随机推荐
Leetcode-9: palindromes
Binary search template
[rust notes] 17 concurrent (Part 2)
Leetcode-6111: spiral matrix IV
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
MySQL advanced part 1: index
LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively
【Rust 笔记】17-并发(下)
[rust notes] 15 string and text (Part 1)
MIT-6874-Deep Learning in the Life Sciences Week 7
开源存储这么香,为何我们还要坚持自研?
实时时钟 (RTC)
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
对for(var i = 0;i < 5;i++) {setTimeout(() => console.log(i),1000)}的深入分析
MySQL advanced part 1: triggers
Sqlmap tutorial (1)
【Rust 笔记】13-迭代器(中)
Leetcode-556: the next larger element III
Daily question 1688 Number of matches in the competition
LVS简介【暂未完成(半成品)】