B. Months and Years(题解)
来源:互联网 发布:vb.net 安卓 编辑:程序博客网 时间:2024/06/08 02:30
原题地址:http://codeforces.com/contest/899/problem/B
题意:给出一串数字(1<=n<=24),判断是否可能是某一年或几年中的连续的月份
- 题目很水,因为n的数值很小,只要暴力枚举所有情况,一一比较就可以
- 唯一的坑点就在与n是<=24的,这就意味着这出现的数据是有可能的三年的数据,而不是两年。(因此要列举6年每个月的天数,即平平平闰平平)
下面给出代码
#include <bits/stdc++.h>using namespace std;int val[72]= {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,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 main(){ int n,a[25]; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&a[i]); } for(int i=0; i<=72-n; i++) { if(a[0]==val[i]) { bool ok=true; int t=0; for(int j=i; t<n; j++,t++) { if(a[t]!=val[j]) ok=false; } if(ok==true) { printf("YES\n"); return 0; } } } printf("NO\n"); 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
- Calculate years, months, days & calender days between 2 given dates
- 【codeforces 764B】Timofey and cubes 题解
- Codeforces #360B: Levko and Array 题解
- POJ 3393 Lucky and Good Months by Gregorian Calendar(模拟题)
- POJ 3393Lucky and Good Months by Gregorian Calendar(模拟)
- poj3393Lucky and Good Months by Gregorian Calendar
- Codeforces 793B Igor and his way to work 题解
- 小白题解 Codeforces 798B Mike and strings
- 小白题解 Codeforces 785B Anton and Classes
- Codeforces 821B Okabe and Banana Trees 题解
- Codeforces Round #442 (Div. 2) B. Nikita and string 题解
- 使用git将项目上传到github(最简单方法)
- spring boot 使用属性加载顺序
- ipset详解
- Python 从入门到实践 8-9 课后习题
- Android | Android数据存储
- B. Months and Years(题解)
- 四大组件之一:Service详细介绍
- JavaSE基础语法中的运算符
- Java 线程池艺术探索
- @CacheEvict中的allEntries与beforeInvocation的区别
- win10 常用快捷键
- ECMAScript 6 简介
- iOS11遇到的坑总结
- Jmeter并发测试(抽奖系统)