Day3: Salted Fish Losing Dreams

Posted by kester on Sun, 04 Aug 2019 13:43:08 +0200

Nothing in the world can stop me from moving forward unless I debug a water problem for half an hour...

0/40(60?)/0

 

3403. Standard IO

Time Limits: 1000 ms  Memory Limits: 524288 KB  Detailed Limits  
Goto ProblemSet

Description

Xiao X has a great headache when he sees piles of homework. I hope you can help him with your wisdom. Consider the sequence A=[A1,A2,...,An], define the transformation f (A, k)=[A2, A3,,,,.Ak, A1, Ak+2, Ak+3,,,,,,,,,,,,,A2k, Ak+1,...], that is to say, subdivide a into k segments, each of which (if there are not enough K at last, all into a new paragraph, see the example), and then move the first segment to the last of each paragraph.

Now, little X wants to know the result of F (f (f (f (f ([1,2,3,..., n],2),3),..., n).
 

Input

The input line contains an integer n.

Output

The output row contains n integers, representing the final sequence.
 

Sample Input

4

Sample Output

4 2 3 1

[Sample Notes]
f ([1,2,3,4],2) = [2,1,4,3]
f ([2,1,4,3],3) = [1,4,2,3] (3 is separately grouped and moved to the last place of the group, still 3)
f ([1,4,2,3],4) = [4,2,3,1]
 

Data Constraint

For 60% of the data, 1 < n < 10 ^ 3.

For 100% data, 1 < n < 10 ^ 6.

Before hearing a fairy say the solution to this problem, he thought that the correct solution was dp...

The solution is to move the array to the right, and then move the number that jumps to the end to the next number that will jump to the end.

eg: 1 2 3 4 

k=2:1  2  1 4 3

k=3:1  2 1 4 2  3

Notice the number of jumps in the last interval. It should predict whether n%k is equal to 0, and if divides, it doesn't need to be managed (I've been pitted for a long time).

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 const int N=1e6+10;
 5 int n;
 6 int b[N*2];
 7 int main(){
 8     scanf("%d",&n);
 9     for(int i=1;i<=n;i++){
10         b[i]=i;
11     } 
12     for(int k=2;k<=n;k++){
13         int tail=n-n%k+k-1,re=b[tail];
14         for(int i=tail;i>=k-1;i-=k){
15             b[i]=b[i-k];
16         }
17         if(n%k!=0)
18         b[n+k-1]=re;
19     }
20     for(int i=n;i<=2*n-1;i++)
21     printf("%d ",b[i]);
22     return 0;
23 }

 

3404. Standard IO

Time Limits: 1000 ms  Memory Limits: 524288 KB  Detailed Limits  
Goto ProblemSet

Description

In order to show his superb game skills, Xiao X found Xiao Y to play a card game with great enthusiasm one day. Each card has two messages: type (attack or defense) and strength.

Small Y has n cards and small X has m cards. Small X's cards are known to be aggressive.

Each round of the game is operated by a small X, first of all from their hands to choose a card X that has not been used. If Xiao Y has no card, the damage is the strength of X, otherwise Xiao X has to choose a card Y from Xiao Y's hand. If Y is aggressive (when the strength of X is not less than the strength of Y), Y disappears after the end of this round, and the damage to Xiao Y is the difference between the strength of X and that of Y; if Y is defensive (when the strength of X is greater than that of Y), Y disappears after this round and Xiao Y is not harmed.

Small X can finish its operation at any time (cards do not have to be used up). Hope you are smart enough to help him operate, so that Xiao Y suffers the greatest total damage.
 

Input

The first line of input contains two integers n and m.

The next n lines contain a string and an integer, representing the type of a card with small Y ("ATK" for attack, and "DEF" for defense) and the strength value, respectively.

Next, line m contains an integer for each line, representing the strength of a card with small X.

Output

The output line contains an integer that represents the maximum total damage to small Y.
 

Sample Input

Enter 1:
2 3
ATK 2000
DEF 1700
2500
2500
2500

Enter 2:
3 4
ATK 10
ATK 100
ATK 1000
1
11
101
1001
 

Sample Output

Output 1:
3000
[Example 1]
In the first round, Xiao X chooses his first card and Xiao Y's second card, and Xiao Y's second card disappears.
In the second round, Xiao X chooses his second card and Xiao Y's first card. Xiao Y's first card disappears and suffers 500 damage at the same time.
In the third round, Xiao X chose his third card. At this time, Xiao Y had no card on his hand and suffered 2500 injuries.
Xiao X ended the game, Xiao Y received 3000 damage.

Output 2:
992
[Example 2]
In the first round, Xiao X chooses his third card and Xiao Y's first card. Xiao Y's first card disappears and suffers 91 damage at the same time.
In the second round, Xiao X chooses his fourth card and Xiao Y's second card. Xiao Y's second card disappears and suffers 901 damage at the same time.
Xiao X ended the game, Xiao Y received 992 damage.
 
 

Data Constraint

Each scale has half of the data to meet the small Y only attack cards.

For 30% of the data, 1 < n,m < 6.

For 60% of the data, 1 < n,m < 10 ^ 3.

For 100% data, 1 < n,m < 10 ^ 5, the force values are all non-negative integers not exceeding 10 ^ 6.

The question is greed.

Consider several scenarios:

1. Consume only the opponent's attack cards:

We attack the opponent's smallest attack card with the largest attack card, and then take the second largest attack and the second smallest, which proves as follows:

If there is a card x < an attack card y of the opponent, we share the card point X and the opponent is Y, then we score X-Y, but we know that X-Y < 0 will not gain more advantages in attacking again, so we will not attack.

2. Reproduce direct damage by consuming all cards of the opponent:

If all cards are consumed, the defense cards should be attacked first, and the defense cards should be eliminated with large or slightly larger cards before attacking others. Assuming that all attack cards can be consumed, the score will be sum[x]-def[x]-atk[y] (sum is the total score of our card, DEF is the total score of the attack defense cards, and ATK is the total score of the enemy attack cards). Number)

In the above two cases, the maximum is enough.

I don't know why it's only 80.

 

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 typedef long long ll;
 7 const ll N=1e5+10;
 8 ll n,m,ans,maxans;
 9 ll atk[N],dfn[N],ca,cb,vis[N],flag1,flag2;
10 ll x[N];
11 int main(){
12     freopen("card17.in","r",stdin);
13     scanf("%lld%lld",&n,&m);
14     char a[10];
15     ca=cb=0;
16     for(ll i=1,k;i<=n;i++){
17         cin>>a;
18         scanf("%lld",&k);
19         if(a[0]=='A') atk[++ca]=k;
20         else dfn[++cb]=k;
21     }    
22     sort(atk+1,atk+ca+1);
23     sort(dfn+1,dfn+cb+1);
24     for(ll i=1;i<=m;i++) scanf("%lld",&x[i]);
25     sort(x+1,x+m+1);
26     ll ans=0;
27     ll i,j;
28     for(i=1,j=1;i<=ca&&j<=m;){
29         while((x[j]<atk[i]&&j<=m)||vis[j]) j++;
30         if(j>m) break;
31         ans+=x[j]-atk[i];
32         vis[j]=1;
33         i++;
34     }
35     if(i>ca) flag1=1;
36     for(i=1,j=1;i<=cb&&j<=m;){
37         while((x[j]<dfn[i]&&j<=m)||vis[j]) j++;
38         if(j>m) break;
39         vis[j]=1,i++;
40     }
41     if(i>cb) flag2=1;
42     if(flag1&flag2) for(i=1;i<=m;i++) if(!vis[i]) ans+=x[i];
43     maxans=max(ans,maxans);
44     memset(vis,0,sizeof(vis));
45     flag1=flag2=ans=0;
46     for(i=1,j=1;i<=cb&&j<=m;){
47         while((x[j]<dfn[i]&&j<=m)||vis[j]) j++;
48         if(j>m) break;
49         vis[j]=1,i++;
50     }
51     if(i>cb) flag2=1;
52     for(i=1,j=1;i<=ca&&j<=m;){
53         while((x[j]<atk[i]&&j<=m)||vis[j]) j++;
54         if(j>m) break;
55         ans+=x[j]-atk[i];
56         vis[j]=1;
57         i++;
58     }
59     if(i>ca) flag1=1;
60     if(flag1&flag2) for(i=1;i<=m;i++) if(!vis[i]) ans+=x[i];
61     maxans=max(maxans,ans);
62     memset(vis,0,sizeof(vis));
63     flag1=flag2=ans=0;
64     ll pt[N];
65     for(ll i=m,j=1;i>=1&&j<=ca;){
66         if(x[i]>atk[j]) ans+=x[i]-atk[j],vis[i]=1,i--,j++;
67         else break;
68     }
69     ll t=0;
70     for(ll i=1;i<=m;i++) if(vis[i]) t++; 
71     if(t==ca) flag1=1;
72     for(i=1,j=1;i<=cb&&j<=m;){
73         while((x[j]<dfn[i]&&j<=m)||vis[j]) j++;
74         if(j>m) break;
75         vis[j]=1,i++;
76     }
77     if(i>cb) flag2=1;
78     if(flag1&flag2) for(i=1;i<=m;i++) if(!vis[i]) ans+=x[i];
79     maxans=max(maxans,ans);
80     printf("%lld",maxans);
81     return 0;
82 }

 

3405. Stage Performance (Standard IO)

Time Limits: 1000 ms  Memory Limits: 524288 KB  Detailed Limits  
Goto ProblemSet

Description

Xiao X finally found his own stage, hoping to have a great performance.

It may be considered that the stage is a matrix of n rows and m columns. Some of the lattices in the matrix are stacked with decorations, while others are empty spaces. Xiao X can slide in the open space, but can't hit ornaments or slide out of the stage, otherwise the performance will fail.

In order to make Xiao X perform as smoothly as possible, Xiao Y wrote the direction of movement for Xiao X in advance. At each moment, the obedient little X will slide one grid to the adjacent square according to the direction of the time period (east, west, south, north) written by little Y. Because Xiao Y had not explored the stage before, if

Xiao X moves directly according to Xiao Y, which is easy to fail.

However, Xiao Y is an angel with the magic of letting Xiao X stop in place, that is, at some point, Xiao X thought he had moved but did not actually move. In order to make Xiao X perform as perfectly as possible, Xiao Y wants to make Xiao X glide on the stage as long as possible (of course, it can't fail in the middle of the performance). Unfortunately, Xiao Y's IQ is not enough.

In order to complete such a complex calculation, I hope you can help her decide when to use magic. Of course, the first thing she cares about is what the longest distance is.
 

Input

The first line of input contains five integers n,m, x, y and k. (x, y) is the initial position of small X, and k is the number of periods of time.

Next, n lines each contain m characters, describing the stage ("..." means that the location is empty, and "x" means that the location has decorations.

The next K line contains three integers Si Ti di (1 <= I <= k), indicating that the direction of small X is di in the time period [si,ti]. Di is one of 1,2,3,4, representing north, south, West and East in turn (corresponding to upper, lower, left and right in the matrix, respectively).

Output

The output line contains an integer representing the longest distance for small X to glide.
 

Sample Input

4 5 4 1 3
..xx.
.....
...x.
.....
1 3 4
4 5 1
6 7 3

Sample Output

6
 

Data Constraint

Ensure that the input period is continuous, that is s1 =1, Si = t I-1 + 1 (1 < I < = k), TK = t.

For 30% of the data, 1 < t < 20.

For 60% of the data, 1 < t < 200.

For 100% data, 1 < n,m,k < 200, 1 < t < 10 ^ 5.

This debugging is killing me.

Read the title. This question is not difficult to set. Let f[k][i][j] denote the longest step to stop at (i,j) after the K turn.

f[k][i][j]=max(f[k-1][x][y]+step), where (x,y) represents the last stop position, enumerate the position, and then update the step in the direction.

Note that the initial state is - 1 except for the starting point.

 

 1 #include<bits/stdc++.h>
 2 #pragma GCC optimize(3) 
 3 using namespace std;
 4 const int N=210;
 5 const int T=1e5+10;
 6 int n,m,xx,yy,k;
 7 int a[N][N];
 8 int f[N][N][N],ans;
 9 struct Time{
10     int s,t,d;
11 }r[N];
12 int main(){
13     scanf("%d%d%d%d%d",&n,&m,&xx,&yy,&k);
14     char q;
15     for(int i=1;i<=n;i++){
16         for(int j=1;j<=m;j++){
17             cin>>q;
18             a[i][j]=(q=='.'?0:1);
19         }
20     }
21     int s,t,d;
22     int maxt=0;
23     for(int i=1;i<=k;i++){
24         scanf("%d%d%d",&s,&t,&d);
25         r[i]=(Time){s,t,d};
26     }
27     memset(f,-1,sizeof(f));
28     f[0][xx][yy]=0;
29     for(int i=1;i<=k;i++){
30         for(int x=1;x<=n;x++){
31             for(int y=1;y<=m;y++){
32                 if(f[i-1][x][y]==-1) continue;
33                 f[i][x][y]=max(f[i][x][y],f[i-1][x][y]);
34                 if(r[i].d==1){
35                     for(int step=1;step<=r[i].t-r[i].s+1;step++){
36                         if(a[x-step][y]||x-step<=0) break;
37                         f[i][x-step][y]=max(f[i][x-step][y],f[i-1][x][y]+step);
38                         if(f[i][x-step][y]>ans) ans=f[i][x-step][y];
39                     }
40                 }
41                 else if(r[i].d==2){
42                     for(int step=1;step<=r[i].t-r[i].s+1;step++){
43                         if(a[x+step][y]||x+step>n) break;
44                         f[i][x+step][y]=max(f[i][x+step][y],f[i-1][x][y]+step);
45                         if(f[i][x+step][y]>ans) ans=f[i][x+step][y];
46                     }
47                 }
48                 else if(r[i].d==3){
49                     for(int step=1;step<=r[i].t-r[i].s+1;step++){
50                         if(a[x][y-step]||y-step<=0) break;
51                         f[i][x][y-step]=max(f[i][x][y-step],f[i-1][x][y]+step);
52                         if(f[i][x][y-step]>ans) ans=f[i][x][y-step];
53                     }
54                 }
55                 else{
56                     for(int step=1;step<=r[i].t-r[i].s+1;step++){
57                         if(a[x][y+step]||y+step>m) break;
58                         f[i][x][y+step]=max(f[i][x][y+step],f[i-1][x][y]+step);
59                         if(f[i][x][y+step]>ans) ans=f[i][x][y+step];
60                     }
61                 }
62             }
63         }
64     }
65     printf("%d",ans);
66     return 0;
67 }

 

 

Summary: Next time it will be 100 points more than today, otherwise it will be too delicious.

Topics: PHP less