Codeforces Round #794 (Div. 2)

目录

A. Everything Everywhere All But One

B. Odd Subarrays

C. Circular Local MiniMax


A. Everything Everywhere All But One

A. Everything Everywhere All But One

思路:找数组的平均值是否在数组的元素中

代码如下

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> PII;
typedef pair<char, int> PCI;
typedef long long LL;

const int N = 1010;

int T;

void solve()
{
    int n, m;
    scanf("%d", &n);

    int a[N];
    int sum = 0;
    for(int i = 0; i < n; i ++ )
        scanf("%d", &a[i]), sum += a[i];

    for(int i = 0; i < n; i ++ )
    {
        if( fabs ( sum*1.0/n - 1.0*a[i]) < 1e-6)
        {
            puts("YES");
            return;
        }
    }

    puts("NO");

    return;
}

int main()
{
    scanf("%d", &T);

    while(T -- )
        solve();

    return 0;
}

B. Odd Subarrays

B. Odd Subarrays 

思路

找到一个逆序对,res ++,输出即可

代码如下

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> PII;
typedef pair<char, int> PCI;
typedef long long LL;

const int N = 2e5+10;

int T;

void solve()
{
    int n, m;
    scanf("%d", &n);

    int a[N];
    int sum = 0;
    for(int i = 0; i < n; i ++ )
        scanf("%d", &a[i]);

    int res = 0;
    for(int i = 1; i < n; i ++ )
    {
        if(a[i-1] > a[i]) res ++, i ++;
    }

    cout << res << endl;

    return;
}

int main()
{
    scanf("%d", &T);

    while(T -- )
        solve();

    return 0;
}

C. Circular Local MiniMax

C. Circular Local MiniMax 

思路:将后半段插入到前半段中,n 必须是偶数,若是奇数,插入的后半段或前半段必定会有两个同一区域的数挨着,我们必须满足两端区域的数是交替出现如此可满足

代码如下

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> PII;
typedef pair<char, int> PCI;
typedef long long LL;

const int N = 2e5+10;

int T;

void solve()
{
    int n, m;
    scanf("%d", &n);

    int a[N];
    for(int i = 1; i <= n; i ++ )
        scanf("%d", &a[i]);

    sort(a + 1, a + n + 1);

    int res[N], cnt = 1;

    for(int i = 1, j = n/2 + 1; i <= n/2 || j <= n; i ++ , j ++ )
    {
        if(i <= n/2) res[cnt ++] = a[i];
        if(j <= n) res[cnt++] = a[j];
    }

    res[0] = res[n];
    res[n+1] = res[1];

    for(int i = 1; i <= n; i ++ )
    {
        if((res[i-1] >= res[i] && res[i+1] <= res[i]) || (res[i-1] <= res[i] && res[i+1] >= res[i]))
        {
            //printf("%d %d %d\n", res[i-1], res[i], res[i+1]);
            puts("NO");
            return;
        }
    }

    puts("YES");
    for(int i = 1; i <= n; i ++ )
    {
        printf("%d ", res[i]);
    }

    puts("");

    return;
}

int main()
{
    scanf("%d", &T);

    while(T -- )
        solve();

    return 0;
}
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AC自动寄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值