2017-2018 ACM-ICPC Asia East Continent League Final (ECL-Final 2017) 个人题解

题面:https://codeforces.com/gym/101775

  • A. Chat Group
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
const ll mod = 1000000007;

int T;
ll N,K;

ll ksm(ll a,ll b){
    ll res = 1;
    while(b){
        if(b&1) res = res*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return res;
}

ll solve(){
    ll pre = 1,ck = 1;
    for(ll k = 0;k<=K-2;k++){
        ck = ck*(N-k)%mod*ksm(k+1,mod-2)%mod;
        pre = (pre+ck)%mod;
    }
    return (ksm(2,N)-pre+mod)%mod;
}

int main(){
    cin>>T;
    int kase = 0;
    while(T--){
        cin>>N>>K;
        printf("Case #%d: %lld\n",++kase,solve());
    }
    return 0;
}
  • J. Straight Master
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;

int T,N;
int a[maxn],b[maxn];//原数组,差分数组

bool judge(){
    ll sum = 0;
    for(int i = 1;i<=N+1;i++){
        if(b[i]>0) sum+=b[i];
        if(i+3<=N+1 && b[i+3]<0) sum += b[i+3];
        if(sum<0) return false;
    }
    return sum == 0;
}
int main(){
    cin>>T;
    int kase = 0;
    while(T--){
        memset(a,0,sizeof a);memset(b,0,sizeof b);
        cin>>N;
        for(int i = 1;i<=N;i++) scanf("%d",&a[i]);
        for(int i = 1;i<=N+1;i++) b[i] = a[i]-a[i-1];
        if(judge()) printf("Case #%d: Yes\n",++kase);
        else printf("Case #%d: No\n",++kase);
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/bigbrox/p/11622966.html