比赛题解 (2)—— 思维

A——————————CodeForces - 909A

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.

题意:

名字中有 first name and last name ,现在有一个登录用户名,要求是这两个名字的前缀组合起来的

现在求一个最早的登录用户名,何为最早?

1、这个字符串是其他登录用户民的前缀(即是一个最短的)

3、必须包含 first name 的首字母 and last name 的首字母 (因为由这两个的前缀组成的,所以最少得包含首字母)

2、这个字符串是由 first name and last name 的前缀组成的,要满足 first name  中的前缀小于  last name 中的字母,按字典序由      小到大

这三点是由这一段得出来的,当时也是看了好久才明白

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 (a 字符串有一个字母 a)that is alphabetically earlier than the corresponding letter in b(比相应的字母 b 要排序在前,就是字典序在前 )

思路:

首先将 first name and last name 的首字母分别固定在 新字符串的首位和末尾,然后在 first name 中找 小于(不是等于,若判断是等于的话,它不是  不包含等于末尾  的前缀 ) last name 首字母的插入到新字符串中,最后输出新字符串即可

Code:

 

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{

    string s,c,ss;
    s.clear();
    c.clear();
    ss.clear();
    cin>>s;
    cin>>c;
 
    ss[0]=s[0];
    int flag=1;
    for(int i=1;s[i];i++){
        if(s[i]<c[0])
            ss[flag++]=s[i];
        else
            break;
    }
    ss[flag++]=c[0];
    ss[flag]='\0';
    for(int i=0;i<flag;i++)
        cout<<ss[i];
    cout<<endl;
}

 


B——————————CodeForces - 903C

详解这篇博客

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

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.

 

 


D——————————CodeForces 903B

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

题意:

Vova的角色有 H1 的健康点和 A1 的攻击力。此外,他有大量的治疗药剂 c1 ,每一个都增加了他目前的健康点量 

Vova可以攻击怪物,从而减少怪物 A1 的健康点,或喝治疗药水,它增加了Vova的健康C1

怪物可以攻击Vova,减少 Vova A 2 的健康点

开始理解错了题意,以为杀一次怪物会减少 A2 的健康点,其实是

杀一次怪物会 减少怪物 A1 的健康点

 

重点:

当Vova 健康值小于 攻击后的减少值(攻击一次之后使血量 减少至 0一下)

或者是 怪物的健康值大于 减少值的时候

需要增加血量,进行HEAL操作

否则进行STRIKE操作

CODE:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int h,a,c;
    int h1,a1;
    int flag=0;
    int ans[20002];
    memset(ans,0,sizeof(ans));
    scanf("%d %d %d",&h,&a,&c);
    scanf("%d %d",&h1,&a1);

    while(h1>0)
    {
        if(h<=a1 && a<h1)
        {
            ans[flag++]=2;
            h+=c;
            h-=a1;
        }
        else
        {
            ans[flag++]=1;
            h-=a1;
            h1-=a;

        }
    }
    cout<<flag<<endl;
    for(int i=0; i<flag; i++)
    {
        if(ans[i]==2)
            printf("HEAL\n");
        if(ans[i]==1)
            printf("STRIKE\n");
    }
}

 

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

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).

 

题意:

给定 n 个月份,判断是否在某一年中存在这几个月份

思路:

我是直接模拟的

定义一个常量数组,存12个月份,用一点小技巧,将 2 月份 存 0,减少了判断是闰年平年的麻烦

由于给定的数组长度是 24,就两年,这两年需要满足:

1、不能是连着出现两年的 闰年

2、可以是 闰年平年 或者 平年闰年

思路:

当判断 第一个和数组中的某位数相同时,再开一个循环 依次判断是否相等

CODE:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
typedef long long LL;
using namespace std;
#define INF 0x3f3f3f3f
int main()
{
    int n;
    int a[30];
    int sum=0,sum1=0;
    int b[20]= {0,31,0,31,30,31,30,31,31,30,31,30,31};
    //  int c[20]= {0,31,29,31,30,31,30,31,31,30,31,30,31};
    int flag=0;
    scanf("%d",&n);
    if(n==1)
        printf("Yes\n");
    else
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            if(a[i]==28)
            {
                // flag=1;
                a[i]=0; //将 2月份 设置成数组中的0
                sum1++;
            }
            if(a[i]==29) 
            {
                //  kk=i;
                //flag=2;
                a[i]=0;
                sum++;
            }
        }
        int t=0;
        if(sum>1)
            printf("No\n"); // 不能连续出现两年闰年
        else
        {
            sum=0;
            int j=1;
            int x,y;
            for(int i=1; i<25; i++)
            {
                sum=0;
                if(i%12==0)
                    x=12;
                else
                    x=i%12; // 循环数组里的数
                if(a[1]==b[x])
                {
                    sum++;
                    for(int k=2; k<25; k++)
                    {
                        x++;
                        if(x%12==0)
                            x==12;
                        else
                            x=x%12;
                        if(a[k]==b[x])
                        {
                            sum++;
                            if(sum==n)
                            {
                                t=1;
                                break;
                            }
                        }
                        else
                            break;
                    }
                }
                if(t==1)
                    break;
            }
            if(t==1)
                printf("Yes\n");
            else
                printf("No\n");
        }
    }

}


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值