8月1号水题走一波-个人赛四

A. Generate Login

The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.

You are given the first and the last name of a user. Return the alphabetically(字母顺序地) earliest login they can get (regardless of other potential Polygon users).

As a reminder, a prefix(前缀) of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".

Input

The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.

Output

Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.

Examples
input
harry potter
output
hap
input
tom riddle
output
tomr
 

 

题目意思:给你用户的名和姓,让你生成一个按字母顺序的最短登录名,原则是:名(也就是a串)和姓(也就是b串)都要保留第一个字母,a串除了第一的字母之后的要取到字典序不大于b串第一个字母位置。

说起来还是很繁琐,其实这个有点生活气息,我们平时上网也有这样处理用户名字的,当时我是第二个出这道题的,多少是有点猜的,不过猜对了。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 char a[100],b[100];
 6 char c[100];
 7 int main()
 8 {
 9     int i,lena,lenb,counts;
10     scanf("%s",&a);
11     scanf("%s",&b);
12     counts=1;
13     lena=strlen(a);
14     lenb=strlen(b);
15     for(i=1;i<lena;i++)
16     {
17         if(a[i]<b[0])
18         {
19             counts++;
20         }
21         else
22         {
23             break;
24         }
25     }
26     for(i=0;i<counts;i++)
27     {
28         c[i]=a[i];
29     }
30     c[i]=b[0];
31     i++;
32     c[i]='\n';
33     printf("%s",c);
34     return 0;
35 }

 

 

Boxes Packing

Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.

Mishka can put a box i into another box j if the following conditions are met:

  • i-th box is not put into another box;
  • j-th box doesn't contain any other boxes;
  • box i is smaller than box j (ai < aj).

Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.

Help Mishka to determine the minimum possible number of visible boxes!

Input

The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.

Output

Print the minimum possible number of visible boxes.

Examples
Input
3
1 2 3
Output
1
Input
Copy
4
4 2 4 3
Output
2

 

Note

In the first example it is possible to put box 1 into box 2, and 2 into 3.

In the second example Mishka can put box 2 into box 3, and box 4 into box 1.

 

题目意思:套盒子,尺寸大的盒子能装下尺寸小的盒子,给你一些盒子,问你最后最少能剩下多少的盒子。

解题思路:这个题有点俄罗斯套娃的意思,大的能装下小的,那么我们只需要看看相同尺寸箱子中最多的个数就可以了。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int a[5010];
 6 int main()
 7 {
 8     int n,counts,maxs,i;
 9     scanf("%d",&n);
10     for(i=0; i<n; i++)
11     {
12         scanf("%d",&a[i]);
13     }
14     sort(a,a+n);
15     counts=1;
16     maxs=1;
17     for(i=1; i<n; i++)
18     {
19         if(a[i]==a[i-1])
20         {
21             counts++;
22             if(maxs<counts)
23             {
24                 maxs=counts;
25             }
26         }
27         else
28         {
29             counts=1;
30         }
31     }
32     printf("%d\n",maxs);
33     return 0;
34 }

 

这里再给出使用map这一容器的做法:

键是箱子的大小,即箱子的类型。

值是该类型箱子的数量。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<map>
 5 using namespace std;
 6 int main()
 7 {
 8     int n,maxs,i,num;
 9     maxs=-1;
10     map<int,int>mp;
11     scanf("%d",&n);
12     for(i=0; i<n; i++)
13     {
14         scanf("%d",&num);
15         mp[num]++;
16         maxs=max(maxs,mp[num]);
17     }
18     printf("%d\n",maxs);
19     return 0;
20 }

 

 

The Modcrab

Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.

After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health points and an attack power of a2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.

Vova's character has h1 health points and an attack power of a1. Also he has a large supply of healing potions, each of which increases his current amount of health points by c1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that c1 > a2.

The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a1) or drink a healing potion (it increases Vova's health by c1; Vova's health can exceed h1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a2. The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's attack.

Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.

Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.

Input

The first line contains three integers h1, a1, c1 (1 ≤ h1, a1 ≤ 100, 2 ≤ c1 ≤ 100) — Vova's health, Vova's attack power and the healing power of a potion.

The second line contains two integers h2, a2 (1 ≤ h2 ≤ 100, 1 ≤ a2 < c1) — the Modcrab's health and his attack power.

Output

In the first line print one integer n denoting the minimum number of phases required to win the battle.

Then print n lines. i-th line must be equal to HEAL if Vova drinks a potion in i-th phase, or STRIKE if he attacks the Modcrab.

The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after Vova's last action.

If there are multiple optimal solutions, print any of them.

Examples
Input
10 6 100
17 5
Output
4
STRIKE
HEAL
STRIKE
STRIKE
Input
11 6 100
12 5
Output
2
STRIKE
STRIKE
Note

In the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win.

In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.

 

题目意思:我们这个故事的主人公要去打怪兽,他攻击一下怪兽反击一下,问他最少需要多少回合就能击败怪兽,攻击和喝药回血都算是一个回合,怪兽一直攻击。

解题思路:因为要回合最少,那么尽量在不死的情况下多处于攻击状态就能得到一个最少的回合数。注意我们要在主人公攻击之前判断在本轮结束之后血量是否会降到0一下,如果是那么就要回血治疗,否则就去攻击。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int h1,a1,c1,h2,a2,i,counts;
 8     int ans[10010];
 9     scanf("%d%d%d",&h1,&a1,&c1);
10     scanf("%d%d",&h2,&a2);
11     counts=0;
12     while(h2>0)
13     {
14         if(h1<=a2&&a1<h2)
15         {
16             h1=h1+c1;
17             h1=h1-a2;
18             ans[counts]=0;
19         }
20         else
21         {
22             h2=h2-a1;
23             h1=h1-a2;
24             ans[counts]=1;
25         }
26         counts++;
27     }
28     printf("%d\n",counts);
29     for(i=0;i<counts;i++)
30     {
31         if(!ans[i])
32         {
33             printf("HEAL\n");
34         }
35         else
36         {
37             printf("STRIKE\n");
38         }
39     }
40     return 0;
41 }

 

Months and Years

Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.

A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.

In this problem you are given n (1 ≤ n ≤ 24) integers a1, a2, ..., an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.

Input

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

The second line contains n integers a1, a2, ..., an (28 ≤ ai ≤ 31) — the numbers you are to check.

Output

If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

You can print each letter in arbitrary case (small or large).

Examples
Input
Copy
4
31 31 30 31
Output
Yes

Input
2
30 30
Output
No

Input
5
29 31 30 31 30
Output
Yes

Input
3
31 28 30
Output
No

Input
3
31 31 28
Output
Yes

Note

In the first example the integers can denote months July, August, September and October.

In the second example the answer is no, because there are no two consecutive months each having 30 days.

In the third example the months are: February (leap year) — March — April – May — June.

In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.

In the fifth example the months are: December — January — February (non-leap year).

 

题目意思:给你一些连续的月份的天数,问你能否真实的出现在生活中。

解题思路:这道题的数据量辛亏很小,最多才给24个月的 ,这道题的坑点在于平年和闰年的出现问题,24个月其实能够跨过三个年份了,可能是平年平年闰年,闰年平年平年,或者平年闰年平年。我们完全可以暴力一下,将月份的信息打表,然后搜索就可以了。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,i,j,k;
 8     int a[30],counts,flag;
 9     int month[150]={
10  31,31,28,31,30,31,30,31,31,30,31,30,31,
11     31,28,31,30,31,30,31,31,30,31,30,31,
12     31,28,31,30,31,30,31,31,30,31,30,31,
13     31,29,31,30,31,30,31,31,30,31,30,31,
14     31,28,31,30,31,30,31,31,30,31,30,31,
15     31,28,31,30,31,30,31,31,30,31,30,31,
16     31,28,31,30,31,30,31,31,30,31,30,31,
17     31,29,31,30,31,30,31,31,30,31,30,31,
18     31,28,31,30,31,30,31,31,30,31,30,31,
19     31,28,31,30,31,30,31,31,30,31,30,31,
20     31,28,31,30,31,30,31,31,30,31,30,31,
21     31,29,31,30,31,30,31,31,30,31,30,31,
22     };
23     scanf("%d",&n);
24     for(i=0;i<n;i++)
25     {
26        scanf("%d",&a[i]);
27     }
28     flag=0;
29     for(i=0;i<150;i++)
30     {
31          counts=0;
32          j=0;
33          k=i;
34          while(1)
35          {
36              if(j>=n)
37              {
38                  break;
39              }
40              if(a[j]==month[k])
41              {
42                  counts++;
43              }
44              j++;
45              k++;
46          }
47          if(counts==n)
48          {
49              flag=1;
50              break;
51          }
52     }
53     if(flag)
54     {
55         printf("Yes\n");
56     }
57     else
58     {
59         printf("No\n");
60     }
61     return 0;
62 }

 

 

 

 

转载于:https://www.cnblogs.com/wkfvawl/p/9409730.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值