1. 程式人生 > >2016-2017 ACM-ICPC CHINA-Final

2016-2017 ACM-ICPC CHINA-Final

題目連結:A題

題目大意:問有多少個小於2n的形式是2k1的能整除7的數字的個數

題目思路:7的二進位制是111,而2k1的二進位制是k個1,所以只需要k能被3整除就好了

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int maxn = 1e6+10; int T,n,m; int main(){ scanf("%d",&T); for(int Case = 1;Case <= T;Case++){ scanf("%d",&n); printf("Case #%d: %d\n",Case,n/3); } return
0; }

題目連結:D題

題目大意:有n個蛋糕,每個蛋糕都有尺寸,現在問你能形成多少個蛋糕塔,要求:蛋糕塔的層數一定得是k,每一層只有能一個蛋糕,下一層的蛋糕得尺寸至少得是上一層得兩倍

題目思路:二分蛋糕塔的個數,然後我們優先取最小的mid個,然後線性掃看能合成多少層,然後層數和k比較得二分check性

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; const ll maxn = 1e6+10; ll T,a[maxn],b[maxn],n,k; bool check(ll mid){ if(mid == 0) return true; memset(b,0,sizeof(b)); ll cnt = 0,now = 0; for(ll i = 0;i < n;i++){ if(a[i] >= b[now]*2){ b[now] = a[i]; now++; if(now == mid){ cnt++; now = 0; } } } if(cnt >= k) return true; return false; } int main(){ scanf("%lld",&T); for(ll Case = 1;Case <= T;Case++){ scanf("%lld%lld",&n,&k); for(ll i = 0;i < n;i++) scanf("%lld",&a[i]); sort(a,a+n); ll l = 0,r = 1e6+10; ll mid = (l+r)/2,maxx = -1; while(l <= r){ mid = (l+r)/2; if(check(mid)){ maxx = max(maxx,mid); l = mid+1; } else r = mid-1; } printf("Case #%lld: %lld\n",Case,maxx); } return 0; }

題目連結:L題

題目大意:有四個隊伍進行足球比賽,贏方得3分,敗方不得分,平局雙方各得一分,給出最後得分,問是否合法,或者是否有多種情況

題目思路:因為比賽就6場,直接dfs一下就好了

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

struct node{
    int a,b,c,d;
}res[1005];

int cnt = 0;

void dfs(int now,int a,int b,int c,int d){
    if(now == 1){
        dfs(now+1,a+3,b,c,d);
        dfs(now+1,a,b+3,c,d);
        dfs(now+1,a+1,b+1,c,d);
    }
    else if(now == 2){
        dfs(now+1,a+3,b,c,d);
        dfs(now+1,a,b,c+3,d);
        dfs(now+1,a+1,b,c+1,d);
    }
    else if(now == 3){
        dfs(now+1,a+3,b,c,d);
        dfs(now+1,a,b,c,d+3);
        dfs(now+1,a+1,b,c,d+1);
    }
    else if(now == 4){
        dfs(now+1,a,b+3,c,d);
        dfs(now+1,a,b,c+3,d);
        dfs(now+1,a,b+1,c+1,d);
    }
    else if(now == 5){
        dfs(now+1,a,b,c,d+3);
        dfs(now+1,a,b+3,c,d);
        dfs(now+1,a,b+1,c,d+1);
    }
    else if(now == 6){
        dfs(now+1,a,b,c,d+3);
        dfs(now+1,a,b,c+3,d);
        dfs(now+1,a,b,c+1,d+1);
    }
    else if(now == 7){
        res[cnt].a = a;
        res[cnt].b = b;
        res[cnt].c = c;
        res[cnt].d = d;
        cnt++;
        return ;
    }
}


int main(){
    int T,a,b,c,d;
    scanf("%d",&T);
    dfs(1,0,0,0,0);
    for(int Case = 1;Case <= T;Case++){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int cot = 0;
        for(int i = 0;i < cnt;i++){
            if(res[i].a == a&&res[i].b == b&&res[i].c == c&&res[i].d == d) cot++;
        }
        if(cot == 0) printf("Case #%d: Wrong Scoreboard\n",Case);
        else if(cot == 1) printf("Case #%d: Yes\n",Case);
        else printf("Case #%d: No\n",Case);
    }
    return 0;
}