Bestcoder Round #33

Source: Internet
Author: User

A and B practices are the same as the official solution

c I use Backpack +map, first the task according to the earliest start of the time to sort, and then go to the backpack, dp[j] mean J time can get the biggest score, and then over.

Code:

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;}


Bestcoder Round #33

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.