Codeforces Round 909 (Div. 3)
2023-12-13 22:56:06
Codeforces Round 909 (Div. 3)
A
莫3为0必败,其他必胜
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin >> n;
if(n%3==0){
cout << "Second\n";
}else{
cout << "First\n";
}
}
int main()
{
int T;
cin >> T;
while(T --){
solve();
}
}
B
求约数,然后模拟
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long a[N], s[N];
vector<int> get_divisors(int x)
{
vector<int> res;
for (int i = 1; i <= x / i; i++)
if (x % i == 0)
{
res.push_back(i);
if (i != x / i)
res.push_back(x / i);
}
sort(res.begin(), res.end());
return res;
}
void solve()
{
long long n, maxn = -0x3f3f3f3f, minn = 0x3f3f3f3f , ans = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
vector<int> res = get_divisors(n);
for (auto x : res)
{
if(x == n)continue;
maxn = -0x3f3f3f3f3f3f3f3f, minn = 0x3f3f3f3f3f3f3f3f;
for(int i = x; i <= n ; i += x){
minn = min(minn , s[i] - s[i - x]);
maxn = max(maxn , s[i] - s[i - x]);
}
ans = max(ans , maxn - minn);
}
cout << ans << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}
}
C
dp,dp[i]
表示到第i个的最大值,可由第i个选或不选得到
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int INF = 0x3f3f3f3f;
long long a[N], dp[N];
bool check(long long x , long long y){
if(x&1){
if(y&1)return false;
else return true;
}else{
if(y&1)return true;
else return false;
}
return 0;
}
void solve()
{
long long n , ans = -INF;
cin >> n;
for(int i = 1 ; i <= n ; i ++){
cin >> a[i];
}
dp[1] = a[1];
for(int i = 2 ; i <= n ; i ++){
dp[i] = a[i];
if(check(a[i] , a[i - 1])){
dp[i] = max(dp[i] , dp[i-1] + a[i]);
}
}
for(int i = 1 ; i <= n ; i ++){
ans = max(ans , dp[i]);
}
cout << ans << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}
}
D
只有当i,j为1,2或者i=j时成立,统计
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int INF = 0x3f3f3f3f;
long long a[N], dp[N];
void solve()
{
long long n , ans = 0;
cin >> n;
map<int,int> m;
for(int i = 1 ; i <= n ; i ++){
cin >> a[i];
ans += m[a[i]] ++;
}
ans += 1LL * m[1] * m[2];
cout << ans << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}
}
E
数列第一次出现最小值后一直都是最小值,因此最小值最后的数必须有序否者返回-1,有序则返回第一次出现最小值的位置
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int INF = 0x3f3f3f3f;
long long a[N], dp[N];
void solve()
{
long long n , ans = 0 , minn = INF , idx = -1;
cin >> n;
for(int i = 0 ; i < n ; i ++){
cin >> a[i];
if(a[i] < minn){
minn = a[i];
idx = i;
}
}
bool f = true;
for(int i = idx ; i + 1 < n ; i ++){
if(a[i] > a[i + 1])f = false;
}
if(f){
cout << idx << endl;
}else{
cout << "-1\n";
}
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}
}
F
一开始构造一条链,,每次通过移动点 n 的位置来保证条件
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int INF = 0x3f3f3f3f;
long long a[N], dp[N];
void solve()
{
long long n , q;
cin >> n >> q;
int p = n-1;
for (int i = 1; i < n; ++i) cout << i << ' ' << i + 1 << "\n";
for (int i = 1, d; i <= q; ++i) {
cin >> d;
if(p == d) cout << "-1 -1 -1\n";
else {cout << n << ' ' << p << ' ' << d << "\n"; p = d;}
}
return ;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}
}
文章来源:https://blog.csdn.net/qq_60755751/article/details/134900367
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!