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("\n");
    }
    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", n % p);
        else printf("%I64d\n", ((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!\n");
            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\n", ans);
                break;
            }
        }
    }
    return 0;
}
时间: 2024-10-05 14:14:51

BestCoder Round #33的相关文章

BestCoder Round #33(zhx&#39;s submissions-手速题,注意判断00和0的情况)

zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1459    Accepted Submission(s): 232 问题描述 作为史上最强的刷子之一,zhx在各大oj上交了很多份代码,而且多数都AC了. 有一天,zhx想数一数他在n  个oj上一共交了多少份代码.他现在已经统计出在第i  个oj上

BestCoder Round #4 前两题 hdu 4931 4932

第一题太水了.. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int a[6]; 7 int main(){ 8 int cas; 9 scanf( "%d", &cas ); 10 while( cas-- ){ 11 for( int i = 0; i <

BestCoder Round #88

传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <ctime> 5 #include <cmath> 6 #include <iostream> 7 #include <algorithm> 8

BestCoder Round#15 1001-Love

http://acm.hdu.edu.cn/showproblem.php?pid=5082 Love Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 64    Accepted Submission(s): 51 Problem Description There is a Love country with many couples

BestCoder Round #2 1001 (简单处理)

题目链接 题意:给N条信息,每个信息代表有x个人从开始的时间 到 结束的时间在餐厅就餐, 问最少需要多少座位才能满足需要. 分析:由于时间只有24*60 所以把每个时间点放到 数组a中,并标记开始的时间+x, 结束的时间 -x.最后累加比较. 如果时间点太多的时候可以把时间点放到结构体里,排序,然后依次枚举结构体. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <

BestCoder Round #70 Jam&#39;s math problem(hdu 5615)

Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ax^2+bx+cax?2??+bx+c into the form of pqx^2+(qk+mp)x+km=(px+k)(qx+m)pqx?2??+(qk+mp)x+km=(px+k)(qx+m). He could only solve the problem in which p,q,m,

从lca到树链剖分 bestcoder round#45 1003

bestcoder round#45 1003 题,给定两个点,要我们求这两个点的树上路径所经过的点的权值是否出现过奇数次.如果是一般人,那么就是用lca求树上路径,然后判断是否出现过奇数次(用异或),高手就不这么做了,直接树链剖分.为什么不能用lca,因为如果有树退化成链,那么每次询问的复杂度是O(n), 那么q次询问的时间复杂度是O(qn) 什么是树链剖分呢? 就是把树的边分成轻链和重链 http://blogsina.com.cn/s/blog_6974c8b20100zc61.htmlh

BestCoder Round #32

PM2.5 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 613    Accepted Submission(s): 326 Problem Description Nowadays we use content of PM2.5 to discribe the quality of air. The lower content of

HDU BestCoder Round #1 1002 项目管理

项目管理 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可能有多条边,不过一条边的两端必然是不同的节点. 每个节点都有一个能量值. 现在我们