Codeforces Round #378 (Div. 2) A B C D 施工中

A. Grasshopper And the String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.

Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.

The picture corresponds to the first example.

The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.

Input

The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.

Output

Print single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.

Examples
Input
ABABBBACFEYUKOTT
Output
4
Input
AAA
Output
1

题意:
题解:
 1 /******************************
 2 code by drizzle
 3 blog: www.cnblogs.com/hsd-/
 4 ^ ^    ^ ^
 5  O      O
 6 ******************************/
 7 #include<bits/stdc++.h>
 8 #include<map>
 9 #include<set>
10 #include<cmath>
11 #include<queue>
12 #include<bitset>
13 #include<math.h>
14 #include<vector>
15 #include<string>
16 #include<stdio.h>
17 #include<cstring>
18 #include<iostream>
19 #include<algorithm>
20 #pragma comment(linker, "/STACK:102400000,102400000")
21 using namespace std;
22 #define  A first
23 #define B second
24 const int mod=1000000007;
25 const int MOD1=1000000007;
26 const int MOD2=1000000009;
27 const double EPS=0.00000001;
28 typedef __int64 ll;
29 const ll MOD=1000000007;
30 const int INF=1000000010;
31 const ll MAX=1ll<<55;
32 const double eps=1e-14;
33 const double inf=~0u>>1;
34 const double pi=acos(-1.0);
35 typedef double db;
36 typedef unsigned int uint;
37 typedef unsigned long long ull;
38 int n;
39 char a[105];
40 int main()
41 {
42     cin>>a;
43     int maxn=0;
44     int len=strlen(a);
45     for(int i=0; i<len; i++)
46     {
47         if(a[i]=='A'||a[i]=='E'||a[i]=='I'||a[i]=='O'||a[i]=='U'||a[i]=='Y')
48         {
49             maxn=i+1;
50             break;
51         }
52     }
53     for(int i=0; i<len; i++)
54     {
55         int j=i;
56         if(a[i]=='A'||a[i]=='E'||a[i]=='I'||a[i]=='O'||a[i]=='U'||a[i]=='Y')
57         {
58 
59             for( j=i+1; j<len; j++)
60             {
61                 if(a[j]=='A'||a[j]=='E'||a[j]=='I'||a[j]=='O'||a[j]=='U'||a[j]=='Y')
62                 {
63                     maxn=max(maxn,j-i);
64                     break;
65                 }
66             }
67         }
68     }
69     for(int i=len-1; i>=0; i--)
70     {
71         if(a[i]=='A'||a[i]=='E'||a[i]=='I'||a[i]=='O'||a[i]=='U'||a[i]=='Y')
72         {
73             maxn=max(maxn,len-i);
74             break;
75         }
76     }
77     if(maxn==0)
78         printf("%d
",len+1);
79     else
80         printf("%d
",maxn);
81     return 0;
82 }
B. Parade
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.

There will be n columns participating in the parade, the i-th column consists of li soldiers, who start to march from left leg, and ri soldiers, who start to march from right leg.

The beauty of the parade is calculated by the following formula: if L is the total number of soldiers on the parade who start to march from the left leg, and R is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |L - R|.

No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index i and swap values li and ri.

Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of columns.

The next n lines contain the pairs of integers li and ri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively.

Output

Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.

Consider that columns are numbered from 1 to n in the order they are given in the input data.

If there are several answers, print any of them.

Examples
Input
3
5 6
8 9
10 3
Output
3
Input
2
6 5
5 6
Output
1
Input
6
5 9
1 3
4 8
4 5
23 54
12 32
Output
0
Note

In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.

If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.

It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.

 1 /******************************
 2 code by drizzle
 3 blog: www.cnblogs.com/hsd-/
 4 ^ ^    ^ ^
 5  O      O
 6 ******************************/
 7 #include<bits/stdc++.h>
 8 #include<map>
 9 #include<set>
10 #include<cmath>
11 #include<queue>
12 #include<bitset>
13 #include<math.h>
14 #include<vector>
15 #include<string>
16 #include<stdio.h>
17 #include<cstring>
18 #include<iostream>
19 #include<algorithm>
20 #pragma comment(linker, "/STACK:102400000,102400000")
21 using namespace std;
22 #define  A first
23 #define B second
24 const int mod=1000000007;
25 const int MOD1=1000000007;
26 const int MOD2=1000000009;
27 const double EPS=0.00000001;
28 typedef __int64 ll;
29 const ll MOD=1000000007;
30 const int INF=1000000010;
31 const ll MAX=1ll<<55;
32 const double eps=1e-14;
33 const double inf=~0u>>1;
34 const double pi=acos(-1.0);
35 typedef double db;
36 typedef unsigned int uint;
37 typedef unsigned long long ull;
38 int n;
39 struct  node
40 {
41     ll l,r;
42     ll pos;
43     ll w;
44 }N[100005];
45 bool cmp(struct node aa,struct node bb)
46 {
47     return aa.w>bb.w;
48 }
49 int main()
50 {
51     scanf("%d",&n);
52     ll aa=0,bb=0;
53     for(int i=1; i<=n; i++)
54     {
55         scanf("%I64d %I64d",&N[i].l,&N[i].r);
56         N[i].pos=i;
57         aa+=N[i].l;
58         bb+=N[i].r;
59     }
60     ll exm=aa-bb;
61     for(int i=1; i<=n; i++)
62     {
63             ll zha=N[i].l-N[i].r;
64             ll zhong;
65             zha=exm-zha*2;
66             if(exm<0)
67                 zhong=-exm;
68             else
69                 zhong=exm;
70             if(zha<0)
71                 zha=-zha;
72             N[i].w=zha-zhong;
73     }
74     sort(N+1,N+1+n,cmp);
75     if(N[1].w<0)
76     printf("0
");
77     else
78     printf("%I64d
",N[1].pos);
79     return 0;
80 }
C. Epidemic in Monstropolis
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city.

Soon, monsters became hungry and began to eat each other.

One monster can eat other monster if its weight is strictly greater than the weight of the monster being eaten, and they stand in the queue next to each other. Monsters eat each other instantly. There are no monsters which are being eaten at the same moment. After the monster A eats the monster B, the weight of the monster A increases by the weight of the eaten monster B. In result of such eating the length of the queue decreases by one, all monsters after the eaten one step forward so that there is no empty places in the queue again. A monster can eat several monsters one after another. Initially there were n monsters in the queue, the i-th of which had weight ai.

For example, if weights are [1, 2, 2, 2, 1, 2] (in order of queue, monsters are numbered from 1 to 6 from left to right) then some of the options are:

  1. the first monster can't eat the second monster because a1 = 1 is not greater than a2 = 2;
  2. the second monster can't eat the third monster because a2 = 2 is not greater than a3 = 2;
  3. the second monster can't eat the fifth monster because they are not neighbors;
  4. the second monster can eat the first monster, the queue will be transformed to [3, 2, 2, 1, 2].

After some time, someone said a good joke and all monsters recovered. At that moment there were k (k ≤ n) monsters in the queue, the j-th of which had weight bj. Both sequences (a and b) contain the weights of the monsters in the order from the first to the last.

You are required to provide one of the possible orders of eating monsters which led to the current queue, or to determine that this could not happen. Assume that the doctor didn't make any appointments while monsters were eating each other.

Input

The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial weights of the monsters.

The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke.

The fourth line contains k integers b1, b2, ..., bk (1 ≤ bj ≤ 5·108) — the weights of the monsters after the joke.

Monsters are listed in the order from the beginning of the queue to the end.

Output

In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line.

Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, separated by space, the symbol 'L' if the monster which stays the x-th in the queue eats the monster in front of him, or 'R' if the monster which stays the x-th in the queue eats the monster behind him. After each eating the queue is enumerated again.

When one monster eats another the queue decreases. If there are several answers, print any of them.

Examples
Input
6
1 2 2 2 1 2
2
5 5
Output
YES
2 L
1 R
4 L
3 L
Input
5
1 2 3 4 5
1
15
Output
YES
5 L
4 L
3 L
2 L
Input
5
1 1 1 3 3
3
2 1 6
Output
NO
Note

In the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue:

  • the second monster eats the monster to the left (i.e. the first monster), queue becomes [3, 2, 2, 1, 2];
  • the first monster (note, it was the second on the previous step) eats the monster to the right (i.e. the second monster), queue becomes [5, 2, 1, 2];
  • the fourth monster eats the mosnter to the left (i.e. the third monster), queue becomes [5, 2, 3];
  • the finally, the third monster eats the monster to the left (i.e. the second monster), queue becomes [5, 5].

Note that for each step the output contains numbers of the monsters in their current order in the queue.

D. Kostya the Sculptor
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.

Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya.

If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way.

Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.

Input

The first line contains the integer n (1 ≤ n ≤ 105).

n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.

Output

In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data.

You can print the stones in arbitrary order. If there are several answers print any of them.

Examples
Input
6
5 5 5
3 2 4
1 4 1
2 1 3
3 2 4
3 3 4
Output
1
1
Input
7
10 7 8
5 10 3
4 2 6
5 5 5
10 2 8
4 2 1
7 7 7
Output
2
1 5
Note

In the first example we can connect the pairs of stones:

  • 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1
  • 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively.
  • 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5
  • 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1
  • 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5

Or take only one stone:

  • 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5
  • 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1
  • 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5
  • 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5
  • 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1
  • 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5

It is most profitable to take only the first stone.

题意:

题解:

 1 /******************************
 2 code by drizzle
 3 blog: www.cnblogs.com/hsd-/
 4 ^ ^    ^ ^
 5  O      O
 6 ******************************/
 7 #include<bits/stdc++.h>
 8 #include<map>
 9 #include<set>
10 #include<cmath>
11 #include<queue>
12 #include<bitset>
13 #include<math.h>
14 #include<vector>
15 #include<string>
16 #include<stdio.h>
17 #include<cstring>
18 #include<iostream>
19 #include<algorithm>
20 #pragma comment(linker, "/STACK:102400000,102400000")
21 using namespace std;
22 #define  A first
23 #define B second
24 const int mod=1000000007;
25 const int MOD1=1000000007;
26 const int MOD2=1000000009;
27 const double EPS=0.00000001;
28 typedef __int64 ll;
29 const ll MOD=1000000007;
30 const int INF=1000000010;
31 const ll MAX=1ll<<55;
32 const double eps=1e-14;
33 const double inf=~0u>>1;
34 const double pi=acos(-1.0);
35 typedef double db;
36 typedef unsigned int uint;
37 typedef unsigned long long ull;
38 int mp[100005][4];
39 map <  int , map<int ,int> > m;
40 map <  int , map<int ,int> > pos;
41 int maxn,co,an;
42 int an1,an2;
43 int n;
44 int main()
45 {
46     scanf("%d",&n);
47     maxn=0;
48     m.clear();
49     pos.clear();
50     for(int i=1; i<=n; i++)
51     {
52         scanf("%d %d %d",&mp[i][0],&mp[i][1],&mp[i][2]);
53         sort(mp[i],mp[i]+3);
54         if(maxn<mp[i][0]){
55             maxn=mp[i][0];
56             co=1;
57             an=i;
58         }
59         if(m[mp[i][1]][mp[i][2]]>0)
60         {
61             int exm=m[mp[i][1]][mp[i][2]]+mp[i][0];
62             if(maxn<min(exm,mp[pos[mp[i][1]][mp[i][2]]][1]))
63             {
64                 maxn=min(exm,mp[pos[mp[i][1]][mp[i][2]]][1]);
65                 co=2;
66                 an1=pos[mp[i][1]][mp[i][2]];
67                 an2=i;
68             }
69         }
70         if(m[mp[i][1]][mp[i][2]]<mp[i][0])
71         {
72            m[mp[i][1]][mp[i][2]]=max(m[mp[i][1]][mp[i][2]],mp[i][0]);
73            pos[mp[i][1]][mp[i][2]]=i;
74         }
75 
76     }if(co==1)
77             printf("1
%d
",an);
78         else
79             printf("2
%d %d
",an1,an2);
80     return 0;
81 }
原文地址:https://www.cnblogs.com/hsd-/p/6028604.html