Codeforces Round #723 (Div. 2)

A. Mean Inequality

Example

input

Copy

3
3
1 2 3 4 5 6
2
123 456 789 10
1
6 9

output

Copy

3 1 4 2 5 6
123 10 456 789
9 6

题意:将序列变为(a[i-1]+a[i+1])/2!=a[i];

题解:将序列排序sort一下,然后对半分,依次输出一个。

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[100];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        for(int i=0;i<2*n;i++)
        {
            int x;
            scanf("%d",&x);
            a[i]=x;
        }
        sort(a,a+2*n);
        for(int i=0;i<n;i++)
        {
            if(i==0)
            {
                cout<<a[i+n]<<" "<<a[i];
            }
            else
            {
                cout<<" "<<a[i+n]<<" "<<a[i];
            }
        }
        cout<<endl;
    }
    return 0;
}

B. I Hate 1111

input

Copy

3
33
144
69

output

Copy

YES
YES
NO

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[100];
 
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        if(n%11<=n/11/10)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

C1. Potions (Easy Version)

Example

input

Copy

6
4 -4 1 -3 1 -3

output

Copy

5

题意:给出n瓶药水,开始你的生命值是0,你要喝这些药水保证喝的时候生命值始终为非零数。

题解:for循环暴力一下,和每瓶药水的时候判断一下生命值是否为小于零,如果小于零就将喝过的药水中负数最小的数减去。

困难版比简单版的n大,但是这个做法是O(n)的做法,时间不会超,所以简单和困难都一样。

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
 
int main()
{
 
    priority_queue<int>q;
    int n;
    scanf("%d",&n);
    int ans=0;
    LL sum;
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x<0)
        {
            q.push(-x);
        }
        if(i==0)
        {
            sum=x;
        }
        else
        {
            sum=sum+x;
        }
        ans++;
        if(sum<0)
        {
            sum=sum+q.top();
            q.pop();
            ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值