Medium CF 585D Lizard Era:beginning, Midway meet.

Source: Internet
Author: User

In the game Lizard era:beginning the protagonist would travel with three Companions:lynn, Meliana and Worrigan. Overall the game has nmandatory quests. To perform each of the them, you need to take exactly of the companions.

The attitude of the companions to the hero are an integer. Initially, the attitude of each of the them to the hero of neutral and equal to 0. As the hero completes quests, he makes actions the attitude of the companions, whom he took to perform this TA SK, in positive or negative direction.

Tell us about companions the hero needs to choose to make their attitude equal after completing all the quests. If This can be do in several ways, choose the one in which the value of resulting attitude is greatest.

The question is whether you can find a set of sequences and then meet the criteria ...

At a glance is halfway meet, N only 25, two DFS on the line ...

The first time with SBT maintenance, and then 1996ms Insurance, the second change into sort,498ms, have to say really fast ah ...

The code is as follows:

//The ━━━━━━ of gods and Beasts ━━━━━━//┏┓┏┓//┏┛┻━━━━━━━┛┻┓//┃┃//┃━┃//████━████┃//┃┃//┃┻┃//┃┃//┗━┓┏━┛//┃┃//┃┃//┃┗━━━┓//┃┣┓//┃┏┛//┗┓┓┏━━━━━┳┓┏┛//┃┫┫┃┫┫//┗┻┛┗┻┛////━━━━━━ Feel the ━━━━━━ of Meng Meng//author:whywhy//Created time:2015 October 13 Tuesday 17:27 11 seconds//File name:f.cpp#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<time.h>using namespacestd;Const intmaxn=2000005;Const intinf=0x3f3f3f3f;structnum{intb; Num () {} num (intXinty): A (x), B (y) {}BOOL operator< (ConstNum & y)Const    {        returnA==y.a? b<y.b:a<y.a; }    BOOL operator> (ConstNum & y)Const    {        returnA==y.a? B>y.b:a>y.a; }    BOOL operator== (ConstNum & y)Const    {        returnA==Y.A && b==y.b; } Numoperator+ (ConstNum & y)Const    {        returnNum (a+y.a,b+y.b); }};structstate{Num N; int Base; Long LongRoute; BOOL operator< (ConstState &b)Const    {        returnn<B.N; }    BOOL operator== (ConstState &b)Const    {        returnn==B.N; }};BOOLcmpConstState &a,ConstState &b) {    returnA.N==B.N? A.Base>b.Base: a.n<B.N;} State STA[MAXN];intcou;intN; Num rem[ -][3];intrnum[ -];intBBB;Long Longlll;voidDFS1 (intD,num TN,intBLong Longl) {    if(D> (n+1) >>1) ) {STA[COU].N=TN; Sta[cou].Base=C; Sta[cou++].route=l; return; }     for(intI=0;i<3;++i) DFS1 (d+1, tn+rem[d][i],b+ (I? Rnum[d]:0), (l<<2)|i);}voidDFS2 (intD,num TN,intBLong Longl) {    if(d>N) {state TS; Ts.n.a=-Tn.a; TS.N.B=-tn.b; intP=lower_bound (Sta,sta+cou,ts)-STA; if(P<cou && sta[p]==ts && sta[p].Base+b>BBB) {BBB=STA[P].Base+b; LLL= (sta[p].route<< (2* (n/2)))|M; }        return; }     for(intI=0;i<3;++i) dfs2 (d+1, tn+rem[d][i],b+ (I? Rnum[d]:0), (l<<2)|i);}voidShow () {intrrr[ -];  for(intI=0; i<n;++i) {Rrr[i]=lll &3; LLL>>=2; }     for(intj=m-1; i>=0;--i)if(rrr[i]==0) puts ("MW"); Else if(rrr[i]==1) puts ("LW"); ElsePuts"LM");}intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);    intA,b,c; scanf ("%d",&N);  for(intI=1; i<=n;++i) {scanf (" %d%d%d",&a,&b,&B); Rnum[i]=A; rem[i][0]=Num (B,C); rem[i][1]=num (-a,c-a); rem[i][2]=num (b-a,-a); } cou=0; BBB=-INF; DFS1 (1, Num (0,0),0,0); Sort (Sta,sta+cou,cmp); Cou=unique (Sta,sta+cou)-STA; DFS2 ((N+1)/2+1, Num (0,0),0,0); if(Bbb==-inf) puts ("Impossible"); ElseShow (); return 0;}
View Code

Medium CF 585D Lizard Era:beginning, Midway meet.

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.