You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
int a[101] = {0};
int main() {
//输入+输出重定向
freopen("../1134.txt", "r", stdin);
//代表兵营的数量
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int m, p1, s1, s2;
cin >> m >> p1 >> s1 >> s2;
//比m小的是龙方比m大的是虎方 1-->m-1 m+1-->n
// 龙的气势,虎的气势
int dragon = 0, tiger = 0;
for (int i = 1; i <= m - 1; ++i) {
dragon += (m - i) * a[i];
}
for (int i = m + 1; i <= n; ++i) {
tiger += (i - m) * a[i];
}
//现在s1位工兵出现在p1号兵营
if (p1 < m) { //如果出现在龙一方
dragon += (m - p1) * s1;
} else { //如果出现在虎一方
tiger += (p1 - m) * s1;
}
// 如果存在多个编号同时满足最优,取最小的编号。
// 从第1号兵营开始尝试找到最合适的解
int minCha = abs(dragon - tiger);
int result = 0;
if (m == p1) {//这个还往没用的地方放shit~
result = m;
} else if (dragon > tiger) { //放到虎方谁大,就向另一方放
for (int i = m + 1; i <= n; i++) {
int t = tiger;
t += s2 * (i - m);
if (abs(dragon - t) < minCha) {
//cout << "虎dragon:" << dragon << ",tiger:" << t << endl;
minCha = abs(dragon - t);
result = i;
}
}
} else {
//放到龙方
for (int i = 1; i <= m - 1; i++) {
int t = dragon;
t += s2 * (m - i);
if (abs(t - tiger) < minCha) {
//cout << "龙dragon:" << t << ",tiger:" << tiger << ",加了" << s2 * (m - i) << endl;
minCha = abs(t - tiger);
result = i;
}
}
}
//输出:
//输出文件有一行,包含一个正整数,即 p2表示你选择的兵营编号。如果存在多个编号同时满足最优取最小的编号。
cout << result << endl;
//关闭文件
fclose(stdin);
return 0;
}