2016-2017 ACM-ICPC CHINA-Final 个人题解

  •  Problem A. Number Theory Problem
#include <iostream>
using namespace std;
const int maxn = 1e6+10;
typedef long long ll;

int T,N;
int sec[maxn];

void init(){
    ll cur = 1;
    for(int i = 1;i<=1e5+10;i++){
        cur = cur*2%7;
        if((cur-1+7)%7 == 0) sec[i] = sec[i-1]+1;
        else sec[i] = sec[i-1];
    }
}

int main(){
    init();
    cin>>T;
    int kase = 0;
    while(T--){
        printf("Case #%d: ",++kase);
        cin>>N;
        printf("%d
",sec[N]);
    }
    return 0;
}
  • Problem D. Ice Cream Tower
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1e6+10;
typedef long long ll;

int T,N,K;
ll a[maxn];

bool judge(ll n){
    if(n*K>N) return false;
    vector<ll> top(n);
    for(int i = 0;i<n;i++) top[i] = a[i];
    int idx = n;
    for(int i = n;i<n*K;i++){
        while(idx<N && a[idx]<top[i%n]*2) idx++;
        if(idx == N) return false;
        top[i%n] = a[idx++];
    }
    return true;
}

int sovle(){
    ll l = 0,r = N,mid;
    while(l<r){
        mid = (l+r+1)>>1;
        if(judge(mid)) l = mid;
        else r = mid-1;
    }
    return l;
}

int main(){
    cin>>T;
    int kase = 0;
    while(T--){
        printf("Case #%d: ",++kase);
        cin>>N>>K;
        for(int i = 0;i<N;i++) scanf("%lld",&a[i]);
        sort(a,a+N);
        int res = sovle();
        printf("%d
",res);
    }

    return 0;
}
  • Problem L. World Cup
#include <iostream>
#include <cstring>
using namespace std;


int T;
int a,b,c,d;
int sc[15][15][15][15];
int A[3] = {3,1,0},B[3] = {0,1,3};

void init(){
    memset(sc,0,sizeof sc);
    int t1,t2,t3,t4;
    for(int i = 0;i<3;i++){
        for(int j = 0;j<3;j++){
            for(int k = 0;k<3;k++){
                for(int l =0;l<3;l++){
                    for(int m = 0;m<3;m++){
                        for(int n = 0;n<3;n++){
                            t1 = A[i]+A[j]+A[k];
                            t2 = B[i]+A[l]+A[m];
                            t3 = B[j]+B[l]+A[n];
                            t4 = B[k]+B[m]+B[n];
                            sc[t1][t2][t3][t4]++;
                        }
                    }
                }
            }
        }
    }
}

int main(){
    init();
    cin>>T;
    int kase = 0;
    while (T--){
        printf("Case #%d: ",++kase);
        cin>>a>>b>>c>>d;
        if(a>9||b>9||c>9||d>9) puts("Wrong Scoreboard");
        else if(sc[a][b][c][d] == 1) puts("Yes");
        else if(sc[a][b][c][d]>1) puts("No");
        else puts("Wrong Scoreboard");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/bigbrox/p/11625713.html