B. Months and Years(暴力)
来源:互联网 发布:win10怎么安装java 编辑:程序博客网 时间:2024/06/01 10:05
思路:
由于闰年的至少四年出现一次由于n<=25,所以列举三个月的情况即可,三个月分为 平平闰,平闰平, 闰平平, 平平平这四种情况,一一列举出来与给定的数组比较
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[36]={31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31};//平闰平int b[36]={31,29,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};//闰平平int c[36]={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,31,30,31};//平平闰int d[36]={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};//平平平int m[36];int main(){ ios::sync_with_stdio(false); int n; cin>>n; for(int i=0;i<n;i++) cin>>m[i]; for(int i=0;i<36;i++){ if(m[0]==a[i]){ int cnt=0; for(int j=0;j<n;j++){ if(i+j>35) break; if(m[j]==a[i+j]) cnt++; } if(cnt==n) { cout<<"YES"<<endl;return 0; } } } for(int i=0;i<36;i++){ if(m[0]==b[i]){ int cnt=0; for(int j=0;j<n;j++){ if(i+j>35) break; if(m[j]==b[i+j]) cnt++; } if(cnt==n) { cout<<"YES"<<endl;return 0; } } } for(int i=0;i<36;i++){ if(m[0]==c[i]){ int cnt=0; for(int j=0;j<n;j++){ if(i+j>35) break; if(m[j]==c[i+j]) cnt++; } if(cnt==n) { cout<<"YES"<<endl;return 0; } } } for(int i=0;i<36;i++){ if(m[0]==d[i]){ int cnt=0; for(int j=0;j<n;j++){ if(i+j>35) break; if(m[j]==d[i+j]) cnt++; } if(cnt==n) { cout<<"YES"<<endl;return 0; } } } cout<<"NO"<<endl; return 0;}
阅读全文
0 0
- B. Months and Years(暴力)
- B. Months and Years(题解)
- codeforces——B. Months and Years
- Codeforces Round #452 (Div. 2) B. Months and Years
- codeforces Div.2 899B Months and Years
- 7 months to 7 years
- Find the difference between two days in days, months and years
- Codeforces 380B Sereja and Tree(暴力)
- Codeforces #325 B. Laurenty and Shop (暴力枚举)
- CodeForces 135B Rectangle and Square(暴力)
- Codefroces 821B Okabe and Banana Trees(暴力)
- CF#877 B. Nikita and string(思维,暴力)
- Calculate years, months, days & calender days between 2 given dates
- codeforces-441B-Valera and Fruits【暴力】
- CodeForces387B B - George and Round 贪心+暴力
- codeforces B. Mike and strings 暴力+字符串
- B. Dima and To-do List----暴力
- Codeforces 400B Inna and New Matrix of Candies(暴力)
- LP/QP/QCQP/SOCP/SDP/CCCP等系列优化方法的比较
- linux 命令 wget
- Debian9中无法连接Mariadb(Mysql)的原因及解决方法
- 学习记录之操作系统终章 概念篇
- OGNL与EL
- B. Months and Years(暴力)
- 程序员中国制造--2017
- OLAP工具-greenplum(GPDB)初识
- Android 清空缓存
- java基础学习——遇到的不懂问题
- 用eclipse运行 结果为什么没有菜单和菜单栏
- v8js中js 函数与 php 函数传值
- 前程无忧python工作薪资爬取及数据分析
- 安卓开发中非常炫的效果集合