Xuzhou Online Race 2018

Source: Internet
Author: User

Xuzhou Online Race 2018

The online game is not going to be out of the question.

"Memory Search for PN State" be, GE or NE
    • Test instructions: Three operations, increase, decrease, plus minus sign. A person wants to make the number >=r, a person wants to make the number less than or equal to L.
    • Obviously for the initiator is definitely to make the best score, for the bottom is definitely the best score. We consider all the scheme, certainly is 3^n, so we can remember the search, altogether only 1000*200 kind of state, so must be calculated out of
      A point is a winning state, when and only if his successor has a must-fail state
      A point is a must-fail state, and only if all his successors are a winning state.
      Consider this problem, if the first person can win, he will not choose flat, and will not choose to lose
      For a second person
#include <bits/stdc++.h>using namespace std; #define LL Long longconst int maxn=1005;int down,up,s,n;int a[maxn],b[ Maxn],c[maxn];int dp[maxn][305];int high,low;map<int,int>mp;int dfs (int pos,int now) {if (pos==n+1) {if (now        >=high) {return 2;        } else if (Now>low) return 1;    else return 0;    } if (Dp[pos][mp[now]]!=-1) return Dp[pos][mp[now]];        if (pos%2==1) {int op=0;        if (A[pos]) {Op=max (Op,dfs (Pos+1,min (Now+a[pos],up)));        } if (B[pos]) {Op=max (Op,dfs (Pos+1,max (Now+b[pos],down)));        } if (C[pos]) {Op=max (Op,dfs (Pos+1,-now));    } return Dp[pos][mp[now]]=op;        } else{int op=1e9;        if (A[pos]) {op=min (Op,dfs (Pos+1,min (Now+a[pos],up)));        } if (B[pos]) {op=min (Op,dfs (Pos+1,max (Now+b[pos],down)));        } if (C[pos]) {op=min (Op,dfs (Pos+1,-now)); } return Dp[pos][mp[now]]=op;   }}int Main () {int tol=0;mp.clear ();    for (int i = -100; I <=100; ++i) {mp[i]=++tol;    } down=-100,up=100;    Memset (Dp,-1,sizeof (DP));    scanf ("%d%d%d%d", &n,&s,&high,&low);        for (int j = 1; J <=n; ++j) {scanf ("%d%d%d", &a[j],&b[j],&c[j]);    B[J]=-B[J];    } int Op=dfs (1,s);    if (op==2) {puts ("good ending");    } else if (op==1) {puts ("Normal ending");    } else puts ("bad ending"); return 0;}

Memory Search: The algorithm is still the search process, but some of the search solution with the dynamic planning of the kind of ideas and patterns to make some preservation.
In general, dynamic planning always iterates through all states, while search can exclude some invalid states.
More importantly, the search can also be pruned, potentially cutting off a lot of unnecessary state, so the space overhead is often much lower than the dynamic planning.
The memory algorithm at the time of the solution is still in the top-down order, but each solution to a state, it will save its solution,
You will not have to re-solve this state again later.
This method combines the advantages of both search and dynamic programming, so it is very useful.

"Desire for violence + test Instructions" Cacti lottery

This problem really test instructions kill ...
It's hard to read, 123 represents the number that is already known, * The Representative knows the number but does not know the specific, #代表未知的数. And then ask for expectations.

#include <bits/stdc++.h>using namespace Std;typedef long Long ll;int num[25] = { 0,0,0,0,0,0,10000,36,720,360,80,252,108,72,54,180,72,180,119,36,360,1080,144,1800,3600};char Mp[5][5];int vis[10     ];int cnt = 0, cnt1 = 0, Cnt2 = 0;char mp2[10];int fial[10];int idx = 0;double Allans = 0;int ans[10];int A (int n, int m) {    int res = 1;    for (int i = 1; I <= m; i++) {res *= (n-i + 1); } return res;    void Check1 () {ans[0] + = num[fial[0] + fial[1] + fial[2]];    ANS[1] + = num[fial[3] + fial[4] + fial[5];    ANS[2] + = Num[fial[6] + fial[7] + fial[8];    ANS[3] + = num[fial[0] + fial[3] + fial[6];    ANS[4] + = num[fial[1] + fial[4] + fial[7];    ANS[5] + = num[fial[2] + fial[5] + fial[8];    ANS[6] + = num[fial[0] + fial[4] + fial[8]; ANS[7] + = num[fial[2] + fial[4] + fial[6]];}        void dfs2 (int num) {if (num = = 9) {check1 ();    Return    } if (Fial[num]! = 0) DFS2 (num + 1); else {for (int i = 1; I <= 9; i++) {iF (Vis[i]) continue;            Vis[i] = 1;            Fial[num] = i;            DFS2 (num + 1);            Fial[num] = 0;        Vis[i] = 0;        }}}void dfs (int num) {if (num = = 9) {memset (ans, 0, sizeof (ans));        DFS2 (0);        int maxx = 0;        for (int i = 0; i < 8; i++) {Maxx = Max (Maxx, Ans[i]);        } Allans + = Maxx/(A (Cnt2,cnt2) *1.0);    Return    } if (mp2[num] = = ' # ') {DFS (num + 1);}    else if (mp2[num]! = ' * ') {Fial[num] = mp2[num]-' 0 '; DFS (num + 1);}            else {for (int i = 1; I <= 9; i++) {if (vis[i]) continue;            Vis[i] = 1;            Fial[num] = i;            DFS (num + 1);        Vis[i] = 0;    }}}int Main () {int T;    scanf ("%d", &t);        while (t--) {memset (Vis, 0, sizeof (VIS));        memset (fial, 0, sizeof (fial));        memset (MP2, 0, sizeof (MP2));        int p = 0;        cnt1 = 0;        Cnt2 = CNT = 0;   IDX = 0;     Allans = 0;            for (int i = 1; I <= 3; i++) {scanf ("%s", Mp[i]);            int len = strlen (Mp[i]);                for (int j = 0; j<len; j + +) {if (Mp[i][j] <= ' 9 ' &&mp[i][j] >= ' 0 ')                    {int k = mp[i][j]-' 0 ';                    Vis[k] = 1;                cnt1++;                } if (mp[i][j] = = ' * ') cnt++;            mp2[idx++] = Mp[i][j];        }} cnt2 = 9-cnt1-cnt;        DFS (0);        int k = A (9-cnt1, CNT);        Double TT = allans/k * 1.0;    printf ("%.6lf\n", TT); } return 0;}
"Set+ Analog" Trace

Did not do, with set maintenance can solve the problem.
I think it's a question of mind.

#include <bits/stdc++.h>using namespace std;#define ll long longvector<int>vector1;vector<int>vector2;ll solve(vector<int>v1){    ll res=0;    set<int>set1;    int len=v1.size();    for (int i = len-1; i >=0 ; --i) {        set<int>::iterator it=set1.lower_bound(v1[i]);        if(it==set1.begin()){            res+=v1[i];        }        else{            it--;            res+=v1[i]-*it;        }        set1.insert(v1[i]);    }    return res;}int main(){    int n,x,y;    scanf("%d",&n);    for (int i = 1; i <=n; ++i) {        scanf("%d%d",&x,&y);        vector1.push_back(x);        vector2.push_back(y);    }    printf("%lld\n",solve(vector1)+solve(vector2));}

Xuzhou Online Race 2018

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.