2018 东北地区大学生程序设计竞赛(ABF)

HDU6500:Problem A. Game with string

题意:

  给你一个字符串s以及它的m个子串的首尾位置,现在Alice和 Bob两个人轮流在任一子串的前面或者后面加1个字符,要求加了这个串加了一个字符之后仍然是s的子串,谁不能加了谁就输了,要你输出谁赢。

题解:

  每个子串可以加的字符次数是恒定的:s串的长度-子串的长度。那么我们将所有子串可以加的次数加起来再判断奇偶就能得出答案。

  傻逼多组WA了几发

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000+10;
const int INF = 1e9+10;
const ll mod = 998244353;
int main() {
    string s;
    while (cin>>s){
        int len = s.length();
        int n,l,r,sum = 0;
        scanf("%d",&n);
        for (int i = 0; i < n; i++){
            scanf("%d%d",&l,&r);
            sum += len - (r-l+1);
        }
        if (sum&1) printf("Alice\n");
        else printf("Bob\n");
    }
    return 0;
}
View Code

HDU6501:Problem B. Memory Banks

题意:

  有60种不同种类的内存存储区,编号为0~59,第i种内存存储区的内存大小为2i,告诉你每种内存存储区的数量。

扫描二维码关注公众号,回复: 6238192 查看本文章

  有n个空间站,每个空间站需要wi的内存空间,每个空间站你都要用你已有的内存存储区来为它提供正好wi的内存空间。

  如果有空间站不能正好有wi的内存空间输出-1,否则输出你剩下的内存存储区的总存储量。

题解:

  要使组成的空间站尽可能多,我们需要先取容量大的。我们可以把每个站需要的内存空间转化为2进制,从高位到低位,如果这i位为1就代表需要1个容量为2i的内存存储区,如果少了可以用2倍的容量为2i-1的内存存储区代替。

  例如如果需要10的内存空间,化成2进制就是1010,需要1个23和1个21,若没有容量为23的可以用两个容量为22的代替。

  如果当前空间站内存不够,则输出-1,否则求各个类型剩余容量与个数的乘积之和。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000+10;
const int INF = 1e9+10;
const ll mod = 1e9+7;
ll qp(ll a, ll b){
    ll ans = 1;
    while (b) {
        if (b&1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
ll a[70];
int main() {
    while (~scanf("%lld",&a[0])) {
        for (int i = 1; i < 60; i++) scanf("%lld",&a[i]);
        int n;
        scanf("%d",&n);
        bool fg = 1;
        while (n--) {
            ll w,sum = 0;
            scanf("%lld",&w);
            int cnt = 0,b[70];
            while (w) {
                b[cnt++] = w%2;
                w>>=1;
            }
            for (int i = cnt - 1; i >= 0; i--) {
                sum = sum * 2 + b[i];
                if (!a[i]) continue;
                if ( sum > a[i]) {
                    sum -= a[i];
                    a[i] = 0;
                } else {
                    a[i] -= sum;
                    sum = 0;
                }
            }
            if (sum) fg = 0;
        }
        if (!fg) printf("-1\n");
        else {
            ll ans = 0;
            for (int i = 0; i < 60; i++) {
                if (a[i]) ans = (ans + (a[i]%mod) * qp(2,i) % mod )%mod;
            }
            printf("%lld\n",ans);
        }
    }
    return 0;
}
View Code

HDU6510:Problem K. Harbin Sausage

题意:

  对于下面这个三视图,给你H和R,每单位体积需要花费 3/Pi(圆周率) 问这个几何体花费的总金额。

  

题解:

  公式为:(4*Pi*R*R*R/3 + Pi*R*R*H) * 3/Pi = 4*R*R*R+3*R*R*H

代码: 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000+10;
const int INF = 1e9+10;
const ll mod = 998244353;
int main() {
    int h,r;
    scanf("%d%d",&h,&r);
    printf("%d",4*r*r*r+3*r*r*h);
    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/l999q/p/10860602.html