codeforces 899B
这道题老有意思了哈哈哈哈~
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,代表连续的月数,接下来是n个月每个月有多少天,让你判断这连续出现的月数有没有可能实现
注意1=<n<=24 ,所以会有平闰年之分,比如可以28 28,28 29,29 28但是不能出现29,29.还有很多细节的地方
//先贴一个错误的但是A了的代码嘻嘻
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int a,n,i,b[100],j,t,t1,mmax,t2;
while(~scanf("%d",&n))
{
memset(b,0,sizeof(b));
for(i=0;i<n;i++)
scanf("%d",&b[i]);
if(n==1)
printf("YES\n");
else
{
a=n-1;
j=1;
t=0;
t1=1;
t2=0;
mmax=0;
if(b[0]==29)
t++;
if(b[0]==28)
t2++;
while(a--)
{
if(b[j]==28)
t2++;
if(b[j]==29)
t++;
if(b[j-1]==31)
{
if(b[j]==31)
t1++;
else
t1=1;
if(t1>mmax)
mmax=t1;
j++;
}
else if(b[j-1]==28||b[j-1]==29)
{
if(b[j]==31)
{
j++;
}
}
else if(b[j-1]==30)
{
if(b[j]==31)
{
j++;
}
}
}
if(j==n&&t<=1&&mmax<=2)
{
if(t2+t>=2&&j<=12)
printf("NO\n");
else if(t2+t==0&&j>=12)
printf("NO\n");
else if(t2+t!=2&&j==24)
printf("NO\n");
else
printf("YES\n");
}
else
printf("NO\n");
}
}
return 0;
}
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.
Examples
Input
harry potter
Output
hap
Input
tom riddle
Output
tomr
这题没读懂题意啊啊啊啊啊超恐怖
给你两个字符串,把它们连起来,两个字符串的首字符一定会有,然后看第一个字符串第二个字符开始,如果小于第二个字符串的首字符就加进去,否则的话就退出不继续加进去
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
int k,i;
char a[20],b[20];
scanf("%s %s",a,b);
k=strlen(a);
printf("%c",a[0]);
for(i=1;i<k;i++)
{
if(a[i]<b[0])
printf("%c",a[i]);
else
break;
}
printf("%c\n",b[0]);
return 0;
}
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
模拟
注意把数组开大点,错了很多遍...就是因为没把数组开大点
qswl
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 1e6;
int t[maxn];
int main()
{
int h1,a1,c1,h2,a2,t1,t2;
int i,j;
scanf("%d %d %d",&h1,&a1,&c1);
scanf("%d %d",&h2,&a2);
i=0;
while(h2>0)
{
t1=h1-a2;
t2=h2-a1;
if(t1<=0&&t2>0)
{
t[i++]=0;
h1+=c1-a2;
}
else
{
t[i++]=1;
h2-=a1;
h1-=a2;
}
}
printf("%d\n",i);
for(j=0;j<i;j++)
{
if(t[j]==1)
printf("STRIKE\n");
else
printf("HEAL\n");
}
return 0;
}