A. Greed
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100007];
int b[100007];
const int inf = 0x3f3f3f3f;
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m;
cin >> n;
ll sum = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
sum += a[i];
}
for(int i = 1; i <= n; i++){
cin >> b[i];
}
sort(b+1, b+n+1);
if(b[n-1] + b[n] < sum){
cout << "NO" <<endl;
return 0;
}
else{
cout << "YES" << endl;
}
简单模拟 找两瓶最大即可
B. Wrath
#include <bits/stdc++.h>
using namespace std;
const int N = 1E6 + 9;
int l[N], res[N];
int main()
{
std::ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
for(int i = 1;i <= n;i ++) cin >> l[i];
for(int i = n;i >= 1;i --) {
int k = max(1, i - l[i]);
int r = i - 1;
res[k]++;
res[r+1]--;
}
for(int i = 0;i <= n;i ++) res[i] += res[i-1];
int ans = 0;
for(int i = 1;i <= n;i ++) if(res[i]==0) ans ++;
cout << ans << endl;
return 0;
}
以前的cf题的变型 我们让a[l]++, a[r+1] -- 就可以o(n)扫一遍判断当前点人是否被杀死。
C. Pride
#include <bits/stdc++.h>
using namespace std;
const int N = 1E6 + 9;
int a[N];
int main()
{
std::ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
int k = 1;
int cnt = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
if(a[i] == 1){
cnt++;
}
}
int ans = 3000;
if(cnt > 0){
cout << n - cnt << endl;
return 0;
}
else{
for(int i = 0; i < n; i++){
int k = __gcd(a[i], a[i+1]);
if(k == 1){
cout << n << endl;
return 0;
}
for(int j = i+1; j < n; j++){
if(__gcd(k, a[j]) == 1){
ans = min(ans, j - i - 1);
}
}
}
if(ans == 3000){
cout << -1 << endl;
} else{
cout << n + ans << endl;
}
}
}
首先判断原序列是否有1 有的话结果显然就是 n - (原序列1的个数), 如果没有我们就暴力扫 最短的区间gcd == 1, 如果不存在这样的区间 无解输出-1 否则输出n + 区间长 - 1;
emmmmm。。。 这题是第二天看大佬代码理解的。。。
本题题意 求一个序列的乱序,这个序列中所有的数都是不同的,使得所有相同位置组成的subset的和,都和原来不一样。空集和全集除外。
所以我们就简单的排个序。。。 使生成序列中的数 都是原序列中的数 排序后的下一个数。。。 这样就可以了。。。 因为原序列的数都是不同的。。。 所以也不会存在生成序列中
某个区间的和等于原序列区间的和。
这只是本菜鸡的理解。。。不知道是不是对的 orz
#include <iostream>
#include <algorithm>
using namespace std;
int n;
pair <int, int> a[27];
int kol[27];
int ao[27];
int main() {
ios_base::sync_with_stdio(0);
while(cin >> n){
for(int i = 1; i <= n; ++i) {
cin >> a[i].first;
a[i].second = i;
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; ++i) {
kol[a[i].second] = i;
ao[i] = a[i].first;
}
// for(int i = 1; i <= n; ++i) {
// cout << ao[i] << ' ';
// }
// cout << endl;
// for(int i = 1; i <= n; ++i) {
// cout << kol[i] << ' ';
// }
// cout <<endl;
for(int i = 1; i <= n; ++i) {
int x = kol[i];
if(x == n) cout << ao[1] << ' ';
else cout << ao[x + 1] << ' ';
}
cout << endl;
}
return 0;
}