Brief monthly Exam

Source: Internet
Author: User
Tags mul

A brief description of the simulation game

The title can be found on the Loj.

10178."5.5 cases of 4" travel problem

Simple problem, expand N to 2 * N, monotone queue can be, pay attention to the positive and negative.

#include <iostream> #include <cstring> #include <cmath> #include <cstdio> #include <  Algorithm> using namespace std;  typedef long Long LL;    const int N=2000005;LL sum[n];int p[n],d[n],que[n],ok[n];int n;inline int read () {int x = 0,f = 1;char c = GetChar ();    while (C < ' 0 ' | | c > ' 9 ') {if (c = = '-') F = -1;c = GetChar ();}    while (c >= ' 0 ' && C <= ' 9 ') {x = x * + C-' 0 '; c = GetChar ();} return x * f;}    void DP1 () {int q1 = 1,Q2 = 0;        for (int i = 1; I <= n; + + i) {while (Q1 <= Q2 && SUM[QUE[Q2]] >= sum[i])--Q2;    que[++ q2]=i;        } for (int i = n + 1; I <= n * 2, + + i) {while (Q1 <= Q2 && SUM[QUE[Q2]] >= sum[i])--Q2;        que[++ Q2] = i;        while (Q1 <= Q2 && QUE[Q1] <= i-n) + + Q1;        if (sum[que[q1]] >= sum[i-n]) ok[i-n] = 1;    }}void DP2 () {int q1 = 1,Q2 = 0; for (int i = n * 2, i > N;---I) {while (Q1 <= Q2 && SUM[QUE[Q2]] >= sum[i])--Q2;    que[++ Q2] = i;        } for (int i = n; I,--i) {while (Q1 <= Q2 && SUM[QUE[Q2]] >= sum[i])--Q2;        que[++ Q2] = i;        while (Q1 <= Q2 && QUE[Q1] >= i + N) + + Q1;          if (sum[que[q1]] >= sum[i + n]) ok[i] = 1;    }}int Main () {n = read ();         for (int i = 1;i <= n;++ i) {p[i + n] = p[i] = Read (), D[i + n] = d[i] = read ();     Sum[i] = Sum[i-1] + p[i-1]-d[i-1];    } for (int i = n + 1;i <= 2 * n;++ i) sum[i] = Sum[i-1] + p[i-1]-d[i-1];    DP1 ();    for (int i = n * 2; i;--i) sum[i] = sum[i + 1] + p[i + 1]-d[i];    DP2 (); for (int i = 1;i <= n;++ i) ok[i]?    Puts ("TAK"): Puts ("NIE");   return 0;}
10078."3.2 Practice 4" good New Year

Simple problem, SPFA run six-side shortest way, full array enumeration can be.

#include <iostream> #include <cstring> #include <queue> #include <cstdio>const int maxn = 5e4 + 7; const int MAXM = 1e5 + 7;using namespace std;int ke_dis[maxn][7];queue <int>q;bool vis[maxn];int dis[maxn];int Q[7], N,m; struct Node {int v,nex,w;}    MAP[MAXM << 1];int head[maxn],num;void add_node (int u,int v,int w) {map[++ num] = (Node) {v,head[u],w};    HEAD[U] = num; return;}    inline int read () {int x = 0,f = 1;char c = GetChar ();    while (C < ' 0 ' | | c > ' 9 ') {if (c = = '-') F = -1;c = GetChar ();}    while (c >= ' 0 ' && C <= ' 9 ') {x = x * + C-' 0 '; c = GetChar ();} return x * f;}    void spfa (int beg,int bh) {memset (dis,0x3f,sizeof (dis));    Dis[beg] = 0;    Q.push (Beg);    Vis[beg] = true;        while (!q.empty ()) {int p = Q.front (); Q.pop (); vis[p] = false;            for (int i = Head[p];i;i = Map[i].nex) {int v = MAP[I].V; if (Dis[v] > Dis[p] + map[i].w) {Dis[v] = Dis[p] + MAP[I].W ;                    if (!vis[v]) {Q.push (v);                VIS[V] = true;    }}}} for (int i = 1;i <= n;++ i) ke_dis[i][bh] = dis[i]; return;} Long Long Ans;bool Is_ch[7];int ch[7];//Five relatives walk in order, just numbered q[number] is station number//special q[0] = 1 relative should be 1 void work () {Long Long sum    = 0;    for (int i = 1;i <= 5;++ i) {sum + = (long Long) ke_dis[q[ch[i-1]]][ch[i]]; } ans = min (ans,sum);    } void Dfs (int tot) {if (tot = = 6) work ();            for (int i = 1;i <= 5;++ i) {if (!is_ch[i]) {Ch[tot] = i;is_ch[i] = true;            DFS (tot + 1);        Is_ch[i] = false;    }}}int Main () {n = read (); m = read ();    Q[0] = 1;    for (int i = 1;i <= 5;++ i) q[i] = read ();        for (int i = 1,u,v,w;i <= m;++ i) {u = read (); v = Read (); w = read ();            Add_node (U,V,W);    Add_node (V,U,W);    } for (int i = 0;i <= 5;++ i) SPFA (q[i],i);    ans = 1e12; DFS (1);   printf ("%lld", ans); return 0;}
#10220. "One-pass 6.5 cases 2"fibonacci nth

The simplest of topics.
Set a matrix multiplication can be.

#include <iostream>#include <cstring>#include <cstdio>#define ll long longusing namespace std;struct Node {    ll w[4][4];    Node() {        memset(w,0,sizeof(w));    }};ll n,m;Node mul(Node a,Node b) {    Node c;    for(ll i = 1;i <= 2;++ i) {        for(ll j = 1;j <= 2;++ j) {            for(ll k = 1;k <= 2;++ k) {                c.w[i][j] = ( c.w[i][j] + a.w[i][k] * b.w[k][j] ) % m;            }        }    }    return c;}void fast_pow(ll b) {    Node a,ans;    a.w[1][1] = a.w[1][2] = a.w[2][1] = 1;    ans.w[1][1] = ans.w[2][2] = 1;    for(;b;b >>= 1,a = mul(a,a) ) {        if(b & 1) ans = mul(ans,a);    }    Node tmp;    tmp.w[1][1] = tmp.w[1][2] = 1;    ans = mul(tmp,ans);    printf("%lld", ans.w[1][1]);    return ;}int main() {    scanf("%lld%lld",&n,&m);    if(n == 1) {puts("1");return 0;}    if(n == 2) {puts("1");return 0;}    fast_pow(n - 2);    return 0;}
Test Harvest

The topic must be read well, read the accurate.
Otherwise, like this time, \ (220\)
Violence must be fought.
otherwise \ (250\) points of violence.
Improve your own code and error-checking levels
Now, Gzy I'm going to start serious now.

Brief monthly Exam

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.