contest 1.21

A.Exchange

模拟

#include <iostream>
#include<cstdio>
typedef long long ll;
using namespace std;

int main()
{
    ll a,b,k;scanf("%lld%lld%lld",&a,&b,&k);
    ll cnt=0;
    while(k--){
        cnt++;
        if(cnt%2){
          if(a%2) a--;
          b+=a/2;
          a=a/2;
        }
        else{
          if(b%2) b--;
          a+=b/2;
          b=b/2;
        }
    }
    printf("%lld %lld\n",a,b);
    return 0;
}
View Code

B.Align

公式

#include <iostream>
#include<cstdio>
#include<algorithm>
typedef long long ll;
using namespace std;

ll a[100005];

int main()
{
    ll n;scanf("%lld",&n);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    if(n==1){
        printf("0\n");
        return 0;
    }
    sort(a+1,a+1+n);
    ll ans=0;
    if(n%2==0){
        ll num=(n-2)/2;
        ll tmp1=0;
        for(ll i=n;i>=n-num+1;i--) tmp1+=a[i];
        ll tmp2=0;
        for(ll i=1;i<=num;i++) tmp2+=a[i];
        ll tmp3=a[n-num]-a[num+1];
        ans=2*(tmp1-tmp2)+tmp3;
    }
    else{
        ll num=(n-1)/2;
        ll tmp1=0;
        for(ll i=n;i>=n-num+1;i--) tmp1+=a[i];
        ll tmp2=0;
        for(ll i=1;i<=num-1;i++) tmp2+=a[i];
        ll tmp3=a[num]+a[num+1];
        ll ans1=2*(tmp1-tmp2)-tmp3;
        tmp1=0,tmp2=0,tmp3=0;
        for(ll i=n;i>=n-num+2;i--) tmp1+=a[i];
        for(ll i=1;i<=num;i++) tmp2+=a[i];
        tmp3=a[num+1]+a[num+2];
        ll ans2=2*(tmp1-tmp2)+tmp3;
        ans=max(ans1,ans2);
    }
    printf("%lld\n",ans);
    return 0;
}
View Code

C.Crossing

构造

#include <iostream>
#include<cstdio>
using namespace std;

bool ok[100005];

void init(){
  ok[1]=1,ok[2]=0,ok[3]=1;
  int now=3;
  for(int t=3;now+t<=100000;t++){
    ok[now+t]=1;
    now=now+t;
  }
}

int main()
{
    init();
    int n;scanf("%d",&n);
    if(ok[n]) puts("Yes");
    else puts("No");
    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/lllxq/p/10297607.html