Codeforces Round #618 (Div. 2)补题

A - Non-zero

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=2e5+10;
ll a[maxn];
int main(){
    ll t;
    scanf("%lld",&t);
    while(t--){
        ll n;
        scanf("%lld",&n);
        ll sum=0;
        ll zero=0;
        for(ll i=1;i<=n;i++){
            ll x;
            scanf("%lld",&x);
            sum+=x;
            zero+=(x==0);
        }
        ll ans=0;
        ans+=zero;
        sum+=zero;
        if(!sum)ans++;
        cout<<ans<<endl;
    }
}

B - Assigning to Classes

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=2e5+10;
ll a[maxn];
int main(){
    ll t;
    cin>>t;
    while(t--){
        ll n;
        scanf("%lld",&n);
        for(ll i=1;i<=2*n;i++){
            scanf("%lld",&a[i]);
        }
        sort(a+1,a+1+2*n);
        cout<<a[n+1]-a[n]<<endl;
    }
}

C - Anu Has a Function


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e5+10;
ll a[maxn];
ll cnt[maxn];
ll pos[maxn];
int main(){
    ll n;
    scanf("%lld",&n);
    ll MAX=0;
    for(ll i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        ll x=a[i];
        ll bit=0;
        while(x){
            MAX=max(bit,MAX);
            if(x&1){
                cnt[bit]++;
                pos[bit]=i;
            }
            bit++;
            x>>=1;
        }
    }
    ll head=n;
    for(ll i=MAX;i>=0;i--){
        if(cnt[i]==1){
            head=pos[i];
            break;
        }
    }
    cout<<a[head];
    for(ll i=n;i>0;i--){
        if(i==head)continue;
        printf(" %lld",a[i]);
    }
    cout<<endl;
}

D - Aerodynamic

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e5+10;
ll x[maxn],y[maxn];
int main(){
    ll n;
    scanf("%lld",&n);
    ll sumx=0,sumy=0;
    for(ll i=1;i<=n;i++){
        scanf("%lld%lld",&x[i],&y[i]);
        sumx+=x[i];
        sumy+=y[i];
    }
    if(n%2)puts("NO");
    else{
        bool flag=true;
        for(ll i=1;i<=n/2;i++){
            if(n*(x[i]+x[i+n/2])!=sumx*2||n*(y[i]+y[i+n/2])!=sumy*2)
                flag=false;
        }
        if(flag)puts("YES");
        else puts("NO");
    }
}

E - Water Balance


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e6+10;
int a[maxn];
double ans[maxn];
double l[maxn];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        ans[++cnt]=a[i]*1.0;
        l[cnt]=1;
        while(cnt>1&&ans[cnt]<ans[cnt-1]){
            ans[cnt-1]=(ans[cnt]*l[cnt]+ans[cnt-1]*l[cnt-1])/(l[cnt]+l[cnt-1]);
            cnt--;
            l[cnt]+=l[cnt+1];
        }
    }
    for(int i=1;i<=cnt;i++){
        for(int j=1;j<=l[i];j++){
            printf("%.12f%c",ans[i],'\n');
        }
    }
    return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值