Codeforces Round #737 (Div. 2)

目录

A-Problem - A - Codeforces

B-Problem - B - Codeforces


A-Problem - A - Codeforces

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
        x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main() {
    int t,n;
    ll a[N];
    t=read();
    while (t--){
        n=read();
        for(int i=0;i<n;i++){
            a[i]=read();
        }
        sort(a,a+n);
        double sum=0.0;
        for(int i=0;i<n-1;i++)sum+=a[i];
        printf("%.9lf\n",sum/(n-1)+a[n-1]);
    }
}

B-Problem - B - Codeforces

思路:需要在给定的数组中找出一段子数组,这个子数组必须是升序排序的,并且是连续的(也就是说子数组之外没有数字能插进去,使得该子数组仍按升序排序)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> pr;
const int N = 1e5+10;

inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
        x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main() {
    int t,n,k,a;
    t=read();
    while (t--){
        n=read(),k=read();
        vector<pr>v;//v的键存储数组元素,值存储元素的位置
        for(int i=0;i<n;i++){
            a=read();
            v.push_back(pr(a,i));
        }
        sort(v.begin(),v.end());//对键升序排序
        int ans=1;
        for(int i=0;i<n-1;i++){
            if(v[i].second!=v[i+1].second-1)ans++;
            //当v[i].second=v[i+1].second-1时,说明排序前两个元素相邻,并且后大前小
            //即排序并没有改变二者的前后位置,并且没有元素插到他们两个之间。
            //满足条件,这两个元素可以归为一个小的subarray
        }
        if(ans<=k)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

C就整不明白了唉。。。 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值