Android App Basics Learning record

Source: Internet
Author: User

11th session of Fuzhou University program design Competition
Contest finished!
tag pro.id problem Title ratio (ac/submit)
1 The king asked me to patrol the mountains. 80.31% (261/325)
2 defensive positions I 23. 48% (193/822)
3 Shadow 13.23% (97/733)
4 peanut sequence 12.07% (21/174)
td> 5 defensive position II 14.98% (68/454)
  6 patrol the Nanshan I patrol North Mt. 0.00% (0/45)
7 nostop 20.79% (21/101)
  8 Fortune Puzzle 10.00% (1/10)

Originally intended as a team game to do, the result of teammates have a football game, there is a party school. I'm the only one left alone. @[email protected] Fortunately it is not difficult, otherwise it will be abused. Overall, the topic is relatively simple, it should have been prepared as a personal race.

A Shi to the question

#include <algorithm> #include <iostream> #include <cstring> #include <vector> #include < cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set > #define LL Long Long#define CLR (A, B) memset (A, B, sizeof (a)) using namespace Std;const int maxn = 5;const int INF = 0x 3f3f3f3f;int Main () {    int n;    while (scanf ("%d", &n)! = EOF)    {        int ans = N/7 * 2;        if (n% 7 = = 6) ans + +;        printf ("%d\n", ans);}    }

b to observe the transfer, you can easily find clues.

#include <algorithm> #include <iostream> #include <cstring> #include <vector> #include < cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set > #define LL Long Long#define CLR (A, B) memset (A, B, sizeof (a)) using namespace Std;const int maxn = 1001000;const int in    F = 0x3f3f3f3f;int A[maxn];int main () {int n, m;        while (scanf ("%d%d", &n, &m)! = EOF) {int ans = 0, tot = 0, sum = 0;            for (int i = 1; I <= m; i + +) {scanf ("%d", &a[i]);            Sum + = A[i];        Tot + = I*a[i];        } ans = tot;            for (int i = m + 1; I <= n; i + +) {scanf ("%d", &a[i]);            Tot-= sum;            Sum-= a[i-m];            Sum + = A[i];            Tot + = a[i] * m;        ans = max (ans, tot);    } printf ("%d\n", ans); }}
C is a relatively simple tree DP bar, only need to see the children and their own no soldiers, some words the current point will certainly be wiped out. OJ more peculiar, recursive will explode stack, with vector will time out. Unfortunately, I've met both of them.

#include <algorithm> #include <iostream> #include <cstring> #include <vector> #include < cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set > #define LL long long#define MP make_pair#define CLR (A, B) memset (A, B, sizeof (a)) using namespace Std;const int maxn = 100100;const int INF = 0x3f3f3f3f;int arm[maxn];bool hav[maxn];struct edge{int u, v;} E[maxn*2];int FIR[MAXN], nxt[maxn*2], tot = 0;    LL d[maxn];void Addedge (int u, int v) {e[tot].u = u, e[tot].v = v; Nxt[tot] = Fir[u], fir[u] = tot + +;}    LL Dfs () {stack<pair<int, int> > S;    CLR (d, 0);    S.push (MP (1, 0));    int cnt = 0; while (!        S.empty ()) {int u = s.top (). First, fa = S.top (). Second;            if (fir[u] = = 1) {if (Hav[u]) HAV[FA] = 1, d[fa] + = D[u] + arm[u];        S.pop ();            } else {int v = E[FIR[U]].V;            Fir[u] = Nxt[fir[u]];   if (v = = FA) continue;         S.push (MP (V, u)); }} return d[1];}    int main () {int n, K; while (scanf ("%d%d", &n, &k)! = EOF) {for (int i = 1; I <= n; i + +) {scanf ("%d", &A        Mp;arm[i]); } CLR (hav, 0); CLR (Fir,-1);        tot = 0;            for (int i = 0; i < K; i + +) {int u; scanf ("%d", &u);        Hav[u] = 1;            } for (int i = 1; i < n; i + +) {int u, v;            scanf ("%d%d", &u, &v);            Addedge (U, v);        Addedge (V, u);    } printf ("%lld\n", Dfs ()); }}
The d question is a DP bar, Dp[i][j], said to the second, there are J belongs to the first string, because of the specificity of the string (WBWBWB), so it is easy to determine the current position of the letter satisfies the situation. For example, the current j is an odd number, then J must be able to answer B ... That's it...

#include <algorithm> #include <iostream> #include <cstring> #include <vector> #include < cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set > #define LL Long Long#define CLR (A, B) memset (A, B, sizeof (a)) using namespace Std;const int maxn = 10100;const int INF    = 0x3f3f3f3f;const int MOD = 1000000007;char ch[maxn];int dp[2][3300];int main () {int T, n;    scanf ("%d", &t);        while (T--) {scanf ("%d%s", &n, ch);        CLR (DP, 0);        Dp[0][0] = 1;            for (int i = 0, j = 1; i < n * 2; i + +, J + +) {CLR (dp[j&1], 0); if (ch[i] = = ' B ') {for (int k = 0; k <= N; k + +) {if (k&                    1) dp[j&1][k+1] = (dp[j&1][k+1] + dp[i&1][k])% MOD;                if ((i-k) &1) dp[j&1][k] = (Dp[j&1][k] + dp[i&1][k])% MOD;       }} else {         for (int k = 0; k <= N; k + +) {if ((k&1) = = 0) dp[j&1][k+1] = (DP[J&A                    MP;1][K+1] + dp[i&1][k])% MOD;                if (((i-k) &1) = = 0) dp[j&1][k] = (Dp[j&1][k] + dp[i&1][k])% MOD;    }}} printf ("%d\n", Dp[0][n]); }}
e bare section tree interval update, interval query, as long as you do not want so much, you can direct a off.

#include <algorithm> #include <iostream> #include <cstring> #include <vector> #include < cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set > #define LL Long Long#define CLR (A, B) memset (A, B, sizeof (a)) #define Lson L, M, RT << 1#define Rson m + 1, R , RT << 1 |  1using namespace Std;const int maxn = 100100;const int INF = 0x3f3f3f3f;int Add[maxn<<2];int sum[maxn<<2];void PUSHUP (int rt) {Sum[rt] = sum[rt<<1] + sum[rt<<1|1];}        void pushdown (int rt,int m) {if (Add[rt]) {add[rt<<1] + = Add[rt];        ADD[RT&LT;&LT;1|1] + = Add[rt];        SUM[RT&LT;&LT;1] + = add[rt] * (M-(M >> 1));        SUM[RT&LT;&LT;1|1] + = add[rt] * (M >> 1);    ADD[RT] = 0;    }}void Build (int l,int R,int RT) {Add[rt] = 0;        if (L = = r) {scanf ("%d", &sum[rt]);    return;    } int m = (L + r) >> 1;    Build (Lson);    Build (Rson); PushuP (RT);}        void update (int l,int r,int c,int l,int r,int RT) {if (L <= l && R <= R) {Add[rt] + = C;        SUM[RT] + = c * (r-l + 1);    return;    } pushdown (RT, r-l + 1);    int m = (L + r) >> 1;    if (l <= m) update (L, R, C, Lson);    if (M < R) Update (L, R, C, Rson); Pushup (RT);}    int query (int l,int r,int l,int r,int RT) {if (L <= l && R <= R) {return SUM[RT];    } pushdown (RT, r-l + 1);    int m = (L + r) >> 1;    LL ret = 0;    if (l <= m) ret + = query (l, R, Lson);    if (M < r) ret + = query (L, R, Rson); return ret;}    int main () {int n, m, q;        while (scanf ("%d%d%d", &n, &m, &q)! = EOF) {build (1, N, 1);            for (int i = 0; i < q; i + +) {int x; scanf ("%d", &x);            printf ("%d\n", query (x, x + m-1, 1, N, 1));        Update (x, X + m-1,-1, 1, N, 1); }    }}

F should be a search bar ... Feel the impossible, sin ... The general idea should be to determine whether it is a substring, and then in the add character, copy operation Bar ... I guess.

G question this question first time see, feel oneself yy come out still is very happy! is to use a matrix to represent the minimum cost to arrive at each point after the K-step. In this way, we can use the initial matrix (indicated by the 1-step arrival situation) constantly updated, to get walk 2 steps, walk 3 steps to the arrival situation. So the idea is clear. Because the problem data is relatively large, we directly with the fast power update can be. (It should be easy to think that these updates meet the binding rate.) I still think it's better to look at the code. This OJ very personality, with Lld,wa without several times, changed to Cin,cout before ... =.=!!

#include <algorithm> #include <iostream> #include <cstring> #include <vector> #include < cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set > #define LL long long#define MP make_pair#define CLR (A, B) memset (A, B, sizeof (a)) using namespace Std;const int maxn = 55;const ll INF = 1ll << 60;struct matrix{LL M[MAXN][MAXN];} Sol, Pre;int N;    Matrix Add (Matrix A, matrix B) {matrix ret;            for (int i = 1; I <= n; i + +) {for (int j = 1; J <= N; j + +) {Ret.m[i][j] = INF;            ll& tmp = Ret.m[i][j];            for (int k = 1; k <= N; k + +) {tmp = MIN (tmp, A.M[I][K] + b.m[k][j]); }}} return ret;}    Matrix Mul (Matrix A, int n) {matrix ret;    BOOL flag = FALSE;            while (n) {if (n & 1) {if (flag) ret = ADD (ret, a);            else ret = A;        Flag = true; } A = Add (A, a);    n >>= 1; } return ret;} void Pt (Matrix sol) {for (int i = 1; I <= n; i + +) {for (int j = 1; J <= N; j + +) printf ("%ll            D ", Sol.m[i][j]);    Puts ("");    }}int Main () {int h, K, T;    scanf ("%d", &t);        while (T--) {scanf ("%d%d%d", &n, &h, &k);        for (int i = 1; I <= n; i + +) {for (int j = 1; J <= N; j + +) sol.m[i][j] = INF; } for (int i = 0; i < h; i + +) {int u, v;            LL C; scanf ("%d%d", &u, &v);            CIN >> C;        Sol.m[u][v] = min (sol.m[u][v], c);        Sol = Mul (sol, k);        if (sol.m[1][n] = = INF) puts ("-1");        else cout << Sol.m[1][n] << Endl;    printf ("%lld\n", Sol.m[1][n]); }}
H has no idea at all, the last man who got the shot is really good, orz~~.


Android App Basics Learning record

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.