碎碎念
普及-
, 今天也是废了九牛二虎之力才AC掉的,题解中第3点是我今后写代码要注意的。题目原文请移步下面的链接
OI
、 NOIP
、模拟
、枚举
普及-
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long LL;
void best_coder() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
LL n, m, p1, s1, s2;
cin >> n;
vector<LL> v(n + 1);
for (LL i = 1; i <= n; ++i) {
cin >> v[i];
}
cin >> m >> p1 >> s1 >> s2;
LL a = 0, b = 0;
for (LL i = 1; i < m; ++i) {
a += v[i] * (m - i);
}
for (LL i = m + 1; i <= n; i++) {
b += v[i] * (i - m);
}
if (p1 <= m - 1) {
a += s1 * (m - p1);
}
if (p1 >= m + 1) {
b += s1 * (p1 - m);
}
if (a == b) {
printf("%lld", m);
return;
}
LL t = 0;
if (abs(a - b) - abs(a - b) / s2 * s2 > abs(a - b) / s2 * s2 + s2 - abs(a - b)) {
++t;
}
if (a < b) {
long long one = 1;
cout << max(one, m - abs(a - b) / s2);
}
else if (a > b) {
cout << min(n, m + abs(a - b) / s2 + t);
}
}
void happy_coder() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int main() {
// 小码匠
best_coder();
// 最优解
//happy_coder();
return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long LL;
void best_coder() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
LL n, m, p1, s1, s2;
cin >> n;
vector<LL> v(n + 1);
for (LL i = 1; i <= n; ++i) {
cin >> v[i];
}
cin >> m >> p1 >> s1 >> s2;
LL a = 0, b = 0;
for (LL i = 1; i < m; ++i) {
a += v[i] * (m - i);
}
for (LL i = m + 1; i <= n; i++) {
b += v[i] * (i - m);
}
if (p1 <= m - 1) {
a += s1 * (m - p1);
}
if (p1 >= m + 1) {
b += s1 * (p1 - m);
}
if (a == b) {
cout << m;
return;
}
LL l = abs(a - b);
LL t = l / s2;
LL cnt = t * s2;
if (l - cnt > cnt + s2 - l) {
++t;
}
if (a < b) {
long long one = 1;
cout << max(one, m - t);
} else if (a > b) {
cout << min(n, m + t);
}
}
void happy_coder() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int main() {
// 小码匠
best_coder();
// 最优解
//happy_coder();
return 0;
}
END