• BestCoder Round #33


    A和B做法和官方题解一样

    C题我是用背包+map,先把任务按最早開始的时间进行排序,然后去背包,dp[j]表示j时间能得到最大的得分,然后就过了。。

    代码:

    A:

    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    
    int n, b;
    
    char str[205];
    int ans[205];
    
    int get(char c) {
        if (c >= '0' && c <= '9') return c - '0';
        return c - 'a' + 10;
    }
    
    void print(int c) {
        if (c >= 0 && c <= 9) printf("%d", c);
        else printf("%c", c + 'a' - 10);
    }
    
    int main() {
        while (~scanf("%d%d", &n, &b)) {
            memset(ans, 0, sizeof(ans));
            while (n--) {
                scanf("%s", str);
                int len = strlen(str);
                for (int i = len - 1; i >= 0; i--) {
                    ans[len - i - 1] += get(str[i]);
                }
            }
            for (int i = 0; i < 204; i++) {
                ans[i] %= b;
            }
            int i;
            for (i = 204; i >= 0; i--) {
                if (ans[i])
                    break;
            }
            if (i == -1) i++;
            for (int j = i; j >= 0; j--)
                print(ans[j]);
            printf("
    ");
        }
        return 0;
    }
    

    B:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    typedef long long ll;
    
    ll n, p;
    
    ll muti(ll a, ll n, ll p) {
        ll r = 0;
        while(n){
            if(n&1){
                r += a;
                if(r >= p) r -= p;
            }
            n >>= 1;
            a += a;
            if(a >= p) a -= p;
        }
        return r;
    }
    
    ll pow_mod(ll x, ll k) {
        ll ans = 1;
        x %= p;
        while (k) {
            if (k&1) ans = muti(ans, x, p);
            x = muti(x, x, p);
            k >>= 1;
        }
        return ans;
    }
    
    int main() {
        while (~scanf("%I64d%I64d", &n, &p)) {
            if (n == 1) printf("%I64d
    ", n % p);
            else printf("%I64d
    ", ((pow_mod(2LL, n) - 2) % p + p) % p);
        }
        return 0;
    }
    

    C:

    #include <cstdio>
    #include <cstring>
    #include <map>
    #include <algorithm>
    using namespace std;
    
    typedef long long ll;
    const int N = 35;
    
    int n;
    ll w;
    
    struct Q {
        int t, v, l, s;
        void read() {
            scanf("%d%d%d", &t, &v, &l);
            s = max(0, l - t);
        }
    } q[N];
    
    map<int, ll> dp[2];
    map<int, ll>::iterator it;
    
    bool cmp(Q a, Q b) {
        if (a.s == b.s) return a.t < b.t;
        return a.s < b.s;
    }
    
    int main() {
        while (~scanf("%d%I64d", &n, &w)) {
            ll sum = 0;
            for (int i = 0; i < n; i++) {
                q[i].read();
                sum += q[i].v;
            }
            if (sum < w) {
                printf("zhx is naive!
    ");
                continue;
            }
            sort(q, q + n, cmp);
            int now = 0, pre = 1;
            dp[now].clear();
            dp[now][0] = 0;
            for (int i = 0; i < n; i++) {
                swap(now, pre);
                dp[now].clear();
                for (it = dp[pre].begin(); it != dp[pre].end(); it++) {
                    int pt = it->first;
                    ll pw = it->second;
                    dp[now][pt] = max(dp[now][pt], pw);
                    int ut = max(pt, q[i].s) + q[i].t;
                    dp[now][ut] = max(dp[now][ut], pw + q[i].v);
                }
            }
            for (it = dp[now].begin(); it != dp[now].end(); it++) {
                if (it->second >= w) {
                    int ans = it->first;
                    printf("%d
    ", ans);
                    break;
                }
            }
        }
        return 0;
    }
    


  • 相关阅读:
    @RequestBody, @ResponseBody 注解详解(转)
    Maven之pom.xml配置文件详解
    搭建SpringCloud-Eureka 注册中心以及服务提供与调用 快速了解 SpringCloud-Eureka
    Springboot 之 多配置文件
    Spring Boot配置文件放在jar外部
    Spring Data JPA使用getOne方法报错:Method threw 'org.hibernate.LazyInitializationException' exception. Cannot evaluate
    Java内省机制
    RestTemplate发送请求并携带header信息 RestTemplate post json格式带header信息
    matlab练习程序(螺线拟合)
    mathematica练习程序(曲线的曲率与挠率)
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4466864.html
Copyright © 2020-2023  润新知