Description
"Story Background" Jyy is very fond of bowling, although the technology is not high, but still always think of high points. Here Jyy will introduce you to the rules of his special bowling game and ask you to help him get as many points as possible. "Problem description" a bowling game with a total of n rounds, each round will have 10 wooden bottles placed at the other end of the boardwalk. In each round, the contestants have two pitches to try to knock down all 10 wooden bottles. For each pitching opportunity, the player throws a score equal to the number of wooden bottles knocked down by the ball. The player's score for each round was his two chance to knock down all the wooden bottles. For each round, there are three kinds of cases: 1, "All in": If the player first tries to knock down all 10 wooden bottles, then this turn is called "whole". In a "All in" round, because all the wood bottles have been knocked down in the first attempt, the player does not need to make a second pitch attempt. At the same time, in the calculation of the total score, the next round of the player's score will be multiplied by 2 into the total score. 2, "Fill in": If the contestant uses two attempts to knock down 10 wooden bottles, then this round is called "Fill in". At the same time, in calculating the total score, the player's first attempt in the next round will be multiplied by a score of 2. 3, "error": If the player failed to pass two attempts to knock down all the wooden bottles, then this round is called "error." At the same time, in the calculation of the total score, the contestants in the next round will be counted into the total score, no score doubled. In addition, if the first n round is "all in", then the player can carry out an additional round: that is, if the nth round is "all in", then the player will conduct a n+1 round. Obviously, in this case, the score of the n+1 wheel is bound to be doubled. The rules for additional rounds are executed only once. That is to say, even if the n+1 has played "All in", it will not be the first n+2 round. As a result, the results of the additional rounds do not double the scores of other rounds. Finally, the total score of the contestant is the sum of each round of the points after the additional round rule has been executed and the score is doubled according to the above rules. Jyy just had a n round bowling game, but Jyy was very dissatisfied with his score. Jyy came up with a way: he could rearrange the order of all the rounds he'd played on the scoreboard, so that after the rearrangement, Jyy would get a higher score because of the doubling rule. Of course, jyy do not want to do too fake, he wants to ensure that after the rearrangement, the number of rounds needed to be carried out before the number of rotations is the same: for example, if the jyy in the first n round of the "full", then after the row, the nth round is still "full" to ensure that the game is carried out n+1 round; If the Jyy n round does not play "all in", then the second row of the nth round can not be full. Please help jyy calculate the highest score he can get.Input
The first line contains an integer n that represents the number of rounds required for a bowling match. Next contains n or n+1 rows, the line I contains two nonnegative integers xi and Yi, representing the scores that Jyy scored in this round of two throws, Xi represents the first attempt, Yi says the second attempt. We use the expression "all in one" round. Enter data assurance. Read-in data exists n+1 rows, if and only if xn=10 and yn=10. Output
The output line is an integer that represents the maximum possible score for jyy. Sample Input 2
5 2
10 0
3 7 Sample Output 44
HINT
"Sample description"
According to the input order, Jyy will get 37 points.
The best scenario is to arrange the 3 rounds in the following order:
3 7
10 0
5 2
N<=50
JSOI2014 second round of d2t2 insane greedy question "Do not know if there is no greedy way" wrote more than 400 lines = = I am divided into two different rounds of discussion. And then more or more in the whole of the more and each of the two kinds we know to be the biggest affirmation is the whole of the complement in the whole of such a similar arrangement. Then you can get greedy. Then we can then enumerate every two locations for the exchange to adjust the answer. The last point at the beginning of all the small 1 = = and then adjust the part of the change to any of the two positions are enumerated anyway N on 50 is not = = do not drop the code. I think it's better to look at the code than to consider it myself. "After that, this must be one of the most memorable questions of a."
#include <cstdio> #include <algorithm> using namespace std;
struct score {int x,y;
int s;
}A[10001],B[10001],C[10001],D[10001],AX[10001],TT[10001];
inline bool Cmp1 (score X,score y) {if (X.S>Y.S) return true;
if (x.s==y.s&&x.x>y.x) return true;
return false;
} inline bool Cmp2 (score X,score y) {if (x.x>y.x) return true;
return false;
int main () {//Freopen ("Bowling.in", "R", stdin);//Freopen ("Bowling.out", "w", stdout);
int n;
scanf ("%d", &n);
int i;
for (i=1;i<=n;i++) {scanf ("%d%d", &a[i].x,&a[i].y);
A[I].S=A[I].X+A[I].Y;
} if (a[n].x!=10) {sort (A+1,A+1+N,CMP1);
int x1=0,x2=0,xt=n+1,xx1=0,xx2=0;
for (i=1;i<=n;i++) {if (a[i].x==10) {x1++;
B[x1]=a[i];
else if (a[i].s==10) {x2++;
C[x2]=a[i];
else {xt=i;
Break
} int x3=0;
for (i=xt;i<=n;i++) {x3++;
D[x3]=a[i];
} xx1=x1;
xx2=x2;
int ans=0;
int as=0;
if (x2>0) {as++;
AX[AS]=C[X2];
x2--;
ans+=10;
Ax[as]=a[xt-(XX2-X2)];
while (x2>0&&x1>0) {as++;
ax[as].x=10;
ax[as].y=0;
ax[as].s=10;
as++;
Ax[as]=a[xt-(XX2-X2)];
AX[AS]=C[X2];
x1--;
x2--;
ans+=40;
} if (x2>0) {sort (D+1,D+1+X3,CMP2);
Sort (C+1,C+1+X2,CMP2); INT D2=1,D2R=X2,D3=1,D3R=X3;
BOOL Flag=true; while (d2r-d2+1>0&&d3r-d3+1>0) {if (flag) {if (C[D2). x>d[d3].x| |
d3r-d3+1==1) {as++;
AX[AS]=C[D2];
ans+= (C[D2].X*2+C[D2].Y);
d2++;
else {as++;
AX[AS]=D[D3];
ans+= (D[D3].X*2+D[D3].Y);
d3++;
Flag=false;
} else {as++;
AX[AS]=C[D2R];
ans+= (C[D2R].X+C[D2R].Y);
d2r--;
Flag=true;
} if (d2r-d2+1>0) {if (flag) {as++; AX[AS]=C[D2];
ans+= (C[D2].X*2+C[D2].Y);
d2++;
while (d2r-d2+1>0) {as++;
AX[AS]=C[D2];
ans+= (C[D2].X+C[D2].Y);
d2++;
} else if (d3r-d3+1>0) {if (flag) {as++;
AX[AS]=D[D3];
ans+= (D[D3].X*2+D[D3].Y);
d3++;
Flag=false;
while (d3r-d3+1>0) {as++;
AX[AS]=D[D3];
ans+= (D[D3].X+D[D3].Y);
d3++;
} int Ansx=ans;
Int J;
for (i=as;i>=1;i--) if (ax[i].s==10) break;
int tx=i;
for (i=1;i<=as;i++) {if (ax[i].x==10) {score t=ax[i]; AX[I]=AX[TX];
ax[tx]=t;
ans=0;
BOOL Flag1=false,flag2=false; for (j=1;j<=as;j++) {if (Flag1) ans+= (ax[j].s*2)
;
else if (Flag2) ans+= (AX[J].X*2+AX[J].Y);
else ans+= (AX[J].X+AX[J].Y);
Flag1=false;
Flag2=false;
if (ax[j].x==10) flag1=true;
else if (ax[j].s==10) flag2=true;
} ansx=max (Ansx,ans);
T=ax[i];
AX[I]=AX[TX];
ax[tx]=t;
} printf ("%d\n", ANSX);
else if (x1>0) {if (xx2==0) ans-=10;
while (x1>0) {ans+=20;
x1--;
} ans+= (a[xt].s*2);
for (i=xt+1;i<=n;i++) Ans+=a[xt].s;
printf ("%d\n", ans);
} else {for (i=1;i<=n;i++) tt[i]=a[i];
scanf ("%d%d", &tt[n+1].x,&tt[n+1].y);
TT[N+1].S=TT[N+1].X+TT[N+1].Y;
int j,k;
int xx;
int ansx=0;
for (k=1;k<=n+1;k++) {xx=0;
for (j=1;j<=n+1;j++) {if (j!=k) {xx++;
A[XX]=TT[J];
}/* printf ("\ n");
for (j=1;j<=n;j++) printf ("%d%d%d\n", A[J].X,A[J].Y,A[J].S);
printf ("\ n"); */ax[n+1]=tt[k];
Sort (A+1,A+1+N,CMP1);
int x1=0,x2=0,xt=n+1,xx1=0,xx2=0;
for (i=1;i<=n;i++) { if (a[i].x==10) {x1++;
B[x1]=a[i];
else if (a[i].s==10) {x2++;
C[x2]=a[i];
else {xt=i;
Break
} int x3=0;
for (i=xt;i<=n;i++) {x3++;
D[x3]=a[i];
} xx1=x1;
xx2=x2;
int ans=0;
int as=n+1;
if (x1>0) {as--;
AX[AS]=B[X1];
x1--;
Ax[as]=a[xt-(XX2-X2)];
else continue;
while (x2>0&&x1>0){as--;
Ax[as]=a[xt-(XX2-X2)];
AX[AS]=C[X2];
as--;
ax[as].x=10;
ax[as].y=0;
ax[as].s=10;
x1--;
x2--; } if (x2>0) {//------------------------------------------------------------------------ ----------------------------------
//----------------------------------------------------------------------- -----------------------------------
//---------------------------------------------------------------------- ------------------------------------
//---------------------------------------------------------------------
-------------------------------------sort (D+1,D+1+X3,CMP2);
int d2=1,d2r=x2,d3=1,d3r=x3;
BOOL Flag=true; while (d2r-d2+1>0&&d3r-d3+1>0) {
if (flag) {as--;
AX[AS]=C[D2R];
d2r--;
Flag=false;
else {/*//if (d[d3].x>ax[as].x) if (d[d3].x*2+ax[as].x>=c[d2].x+ax[as].x*2| |
d2r-d2+1==1&&d[d3].x>ax[as].x) {as--;
AX[AS]=D[D3];
d3++;
Flag=true;
else {as--;
AX[AS]=C[D2];
d2++; }*/if (d2r-d2+1==1) {if (d[
d3].x>ax[as].x) { as--;
AX[AS]=D[D3];
d3++;
Flag=true; else {as-
-;
AX[AS]=C[D2];
d2++;
}} else {
if (d[d3].x>ax[as].x) {as--;
AX[AS]=D[D3];
d3++;
Flag=true;
} else { as--;
AX[AS]=C[D2];
d2++;
{}}} if (d2r-d2+1>0) {
while (d2r-d2+1>0) {as--;
AX[AS]=C[D2];
d2++;
} else if (d3r-d3+1>0) {while (d3r-d3+1>0)
{as--;
AX[AS]=D[D3];
d3++;
} bool Flag1=false,flag2=false;
ans=0;
for (j=1;j<=n+1;j++) {if (Flag1) ans+= (ax[j].s*2);
else if (Flag2) ans+= (AX[J].X*2+AX[J].Y); else ans+= (AX[J].X+AX[J].Y);
Flag1=false;
Flag2=false;
if (ax[j].x==10) flag1=true;
else if (ax[j].s==10) flag2=true;
} ansx=max (Ansx,ans);
Int J;
for (i=1;i<=n-1;i++) if (ax[i].s==10) break;
int tx=i;
for (int tx=1;tx<=n-1;tx++) {for (i=n-1;i>=1;i--) {
if (ax[i].x==10)//{score t=ax[i];
AX[I]=AX[TX];
ax[tx]=t;
ans=0;
BOOL Flag1=false,flag2=false;
for (j=1;j<=n+1;j++) { if (FLAG1) ans+= (ax[j].s*2);
else if (Flag2) ans+= (AX[J].X*2+AX[J].Y);
else ans+= (AX[J].X+AX[J].Y);
Flag1=false;
Flag2=false;
if (ax[j].x==10) flag1=true;
else if (ax[j].s==10) flag2=true;
} ansx=max (Ansx,ans);
T=ax[i];
AX[I]=AX[TX];
ax[tx]=t; // }
}
}
//------------------------------------------------------------- ---------------------------------------------
//------------------------------------------------------------ ----------------------------------------------
//-------------------------------------------------------------- --------------------------------------------
//-------------------------------------------------------------
---------------------------------------------} else if (x1>0) {while (x1>0)
{as--;
ax[as].x=10;
ax[as].y=0;
ax[as].s=10;
x1--;
for (i=xt;i<=n;i++) {as--;
Ax[as]=a[i];
BOOL Flag1=false,flag2=false;
ans=0;
/* printf ("\ n");
for (j=1;j<=n+1;j++) printf ("%d%d%d\n", AX[J].X,AX[J].Y,AX[J].S); printf ("\ n"); */for (j=1;j<=n+1;j++) {if flag1) ans+= (ax[j].s*2);
else if (Flag2) ans+= (AX[J].X*2+AX[J].Y);
else ans+= (AX[J].X+AX[J].Y);
Flag1=false;
Flag2=false;
if (ax[j].x==10) flag1=true;
else if (ax[j].s==10) flag2=true;
} ansx=max (Ansx,ans);
} printf ("%d\n", ANSX);
return 0; }
So far JSOI2014 the second round of the title complete completion of all