B. Months and Years
 
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

代码:

 1 #include<iostream>
2 #include<cstdio>
3 #include<cmath>
4 using namespace std;
5 const int N=2*1e5+10;
6 int a[N];
7 int month[300]={31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,
8 31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,};
9 int ans[N];
10 int main(){
11 int n;
12 cin>>n;
13 for(int i=1;i<=n;i++){
14 scanf("%d",&a[i]);
15 }
16 for(int i=0;i<=150;i++){
17 if(month[i]==a[1]){
18 int flag1=0;
19 for(int j=1;j<=n;j++){
20 if(month[i+j-1]!=a[j]){
21 flag1=1;
22 break;
23 }
24 }
25 if(flag1==0){
26 cout<<"YES"<<endl;
27 return 0;
28 }
29 }
30 }
31 cout<<"NO"<<endl;
32 }

Codeforces 899 B.Months and Years的更多相关文章

  1. Codeforces 899 F. Letters Removing (二分、树状数组)

    题目链接:Letters Removing 题意: 给你一个长度为n的字符串,给出m次操作.每次操作给出一个l,r和一个字符c,要求删除字符串l到r之间所有的c. 题解: 看样例可以看出,这题最大的难 ...

  2. Codeforces 899 C.Dividing the numbers-规律

      C. Dividing the numbers   time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. Codeforces 899 A.Splitting in Teams

      A. Splitting in Teams   time limit per test 1 second memory limit per test 256 megabytes input sta ...

  4. Codeforces 899 1-N两非空集合最小差 末尾最多9对数计算 pair/链表加优先队列最少次数清空

    A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...

  5. Codeforces Round #452 (Div. 2)-899A.Splitting in Teams 899B.Months and Years 899C.Dividing the numbers(规律题)

    A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. 【CodeForces】899 F. Letters Removing

    [题目]F. Letters Removing [题意]给定只含小写字母.大写字母和数字的字符串,每次给定一个范围要求删除[l,r]内的字符c(l和r具体位置随删除变动),求m次操作后的字符串.n&l ...

  7. 【CodeForces】899 E. Segments Removal

    [题目]E. Segments Removal [题意]给定n个数字,每次操作删除最长的连续相同数字(等长删最左),求全部删完的最少次数.n<=2*10^6,1<=ai<=10^9. ...

  8. Codeforces 899B Months and Years

    题目大意 给定 $n$($1\le n\le 24$)个正整数 $a_1,\dots, a_n$ 判断 $a_1$ 到 $a_n$ 是否可能为连续 $n$ 个月份的天数. 解法 由于 $n\le 24 ...

  9. 【Codeforces Round #452 (Div. 2) B】Months and Years

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 闰,平,平 平,闰,平 平,平,闰 平,平,平 4种情况都考虑到就好. 可能有重复的情况. 但是没关系啦. [代码] #includ ...

随机推荐

  1. But You Didn'd【但是你没有】

    But You Didn't Remember the day I borrowed your brand new car and dented it? I thought you'd kill me ...

  2. BFS:HDU-1242-Rescue(带守卫的迷宫问题)(优先队列)

    解题心得: 1.读清楚题意,本题的题意是有多个'r'(起点),多个r多个bfs比较最短的时间即可,但是hdoj的数据比较水,直接一个起点就行了,迷宫里有多个守卫,如果在路途中遇到守卫会多花费一个时间点 ...

  3. git上传自己的代码

    感谢这个哥们的博客,不过里面有些错误. http://www.cnblogs.com/ruofengzhishang/p/3842587.html 下面是我自己的实践成功的: 这篇文章写得是windo ...

  4. TCP/IP网络编程之多线程服务端的实现(二)

    线程存在的问题和临界区 上一章TCP/IP网络编程之多线程服务端的实现(一)的thread4.c中,我们发现多线程对同一变量进行加减,最后的结果居然不是我们预料之内的.其实,如果多执行几次程序,会发现 ...

  5. 【Minimum Path Sum】cpp

    题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right w ...

  6. 【Palindrome Partitioning】cpp

    题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...

  7. 嵌入式之download

    ISP ISP(In-System Programming)在系统可编程,指电路板上的空白器件可以编程写入最终用户代码, 而不需要从电路板上取下器件,已经编程的器件也可以用ISP方式擦除或再编程.IS ...

  8. Bugku杂项-convert

    一进去就发现一堆二进制数,然后考虑怎么才能把这个和隐写扯上关系.首先,二进制我们肉眼就是看不懂再说什么的,这里就想到了转换,再联想上hex将原始数据转化为16进制.我们可以先把2进制转化为16进制,然 ...

  9. jmter+ANT+jekins之配置文件简单优化(build.xml)

    <?xml version="1.0" encoding="utf-8"?> <project name="ant-jmeter-t ...

  10. Python+Selenium练习篇之1-摘取网页上全部邮箱

    前面已经介绍了Python+Selenium基础篇,通过前面几篇文章的介绍和练习,Selenium+Python的webUI自动化测试算是入门了.接下来,我计划写第二个系列:练习篇,通过一些练习,了解 ...