2016-2017 ACM-ICPC CHINA-Final

A Gym 101194A Number Theory Problem

找规律,发现每隔三个数能被 7 整除。

#include <bits/stdc++.h>
using namespace std;

int main() {
    int T;
    scanf("%d", &T);
    for(int ca = 1; ca <= T; ++ca) {
        int n;
        scanf("%d", &n);
        printf("Case #%d: %d\n", ca, n/3);
    }
    return 0;
}

  

B Gym 101194B Hemi Palindrome

C Gym 101194C Mr. Panda and Strips

D Gym 101194D Ice Cream Tower

 二分

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 3e5 + 100;
int T;
int n, k;

LL a[maxn];
int vis[maxn];


bool check(int mid)
{
    for (int i = 1; i <= n; i++) vis[i] = 0;
    for (int i = 1; i <= mid; i++) vis[i] = 1;

    int st = 1, ed = mid, flag = 0, maxx = ed;
    for (int i = 1; i <= k-1; i++)
    {
        for (int j = st; j <= ed; j++)
            if (vis[j])
            {
                int pos = lower_bound(a+maxx+1,a+1+n,2*a[j])-a;
                if (pos > n) { flag = 1; break; }
                vis[pos] = 1;
                maxx = max(maxx, pos);
            }
        if (flag) return false;
        st = ed+1, ed = maxx;
    }

    return true;
}

int main()
{ scanf("%d",&T); for(int t=1;t<=T;t++) { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a+1, a+1+n); int l = 0, r = n/k, ans = 0; while(l <= r) { int mid = (l+r)/2; if (check(mid)) ans = mid, l = mid+1; else r = mid-1; } printf("Case #%d: %d\n", t, ans); } return 0; }

  


E Gym 101194E Bet

设总共的钱数为 1,通过赔率可以求出买每个球队的花费。然后直接贪心就好了。double 精度,用long double

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
const int maxn=100 + 10;
const int Max = 100000;
long double spend[maxn];

int main()
{ int t; scanf("%d", &t); for (int ca = 1; ca <= t; ca++) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { long double x, y; char s; cin >> x >> s >> y; spend[i] = x/(y+x); } int ans = 0; long double tot = 1; sort(spend+1, spend+1+n); for (int i = 1; i <= n; i++) if (tot > spend[i]) tot -= spend[i], ans++; printf("Case #%d: %d\n", ca, ans); } return 0; }

  


F Gym 101194F Mr. Panda and Fantastic Beasts

G Gym 101194G Pandaria


H Gym 101194H Great Cells


I Gym 101194I Cherry Pick


J Gym 101194J Mr.Panda and TubeMaster


K Gym 101194K Justice Rains From Above


L Gym 101194L World Cup

直接搜索一下每两个队的三种情况即可。如果答案没出现过,就是 Wrong Scoreboad,如果答案出现过多次,就是 No 。否则就是 Yes

#include <cstdio>
using namespace std;
int T;
int a[10];
int sc[10];

int fr[] = {0, 1, 1, 1, 2, 2, 3};
int to[] = {0, 2, 3, 4, 3, 4, 4};

int ans = 0;

void DFS(int k)
{
    if (k > 6)
    {
        int flag = 1;
        for (int i = 1; i <= 4; i++)
            if (sc[i] != a[i]) { flag = 0; break; }
        if (flag) ans++;
        return;
    }
    int x = fr[k], y = to[k];
    sc[x]+=3, DFS(k+1), sc[x] -= 3;
    sc[y]+=3, DFS(k+1), sc[y] -= 3;
    ++sc[x], ++sc[y], DFS(k+1), --sc[x], --sc[y];
}

int main(){
    scanf("%d",&T);
    for(int t=1;t<=T;t++){
        ans = 0;
        scanf("%d%d%d%d",&a[1],&a[2],&a[3],&a[4]);

        DFS(1);
        printf("Case #%d: ", t);

        if (ans == 0)
            printf("Wrong Scoreboard\n");
        else if (ans == 1) printf("Yes\n");
        else printf("No\n");
    }
return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/ruthank/p/9747358.html