Educational Codeforces Round 13 A.Johny Likes Numbers && B. The Same Calendar
来源:互联网 发布:淘宝金酷娃玩具吊车 编辑:程序博客网 时间:2024/04/29 23:53
传送门
A. Johny Likes Numbers
time limit per test0.5 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.
Input
The only line contains two integers n and k (1 ≤ n, k ≤ 109).
Output
Print the smallest integer x > n, so it is divisible by the number k.
Examples
input
5 3
output
6
input
25 13
output
26
input
26 13
output
39
题目大意:
给定两个数 n 和 k,让你求的是 >n 的第一个能够被 k 整除的数
解题思路:
首先让 n 模上 k,然后 n + k- (n%k) ,OK
代码:
#include <iostream>using namespace std;int main(){ int n, k; while(cin>>n>>k) { cout<<n+k-n%k<<endl; } return 0;}
B. The Same Calendar
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.
Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100(https://en.wikipedia.org/wiki/Leap_year).
Input
The only line contains integer y (1000 ≤ y < 100’000) — the year of the calendar.
Output
Print the only integer y’ — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.
Examples
input
2016
output
2044
input
2000
output
2028
input
50501
output
50507
Note
Today is Monday, the 13th of June, 2016.
题目大意:
就是给你一个年份,让你求的是下一次跟当前给的年份完全一样的年份,这里所说的完全一样指的是这一年的第一天是周几与当前年是周几完全一样,而且必须是闰年和闰年或者平年和平年。
解题思路:
首先给一个数ans 让ans == 0,然后从当前的年份一直往上加,如果是闰年的话就加 2 因为366%7==2,否则加1(355%7 == 1),当ans%7==0 的时候同时是不是闰年也跟当前年份一样的时候就退出,输出 i 。
My Code:
#include <iostream>using namespace std;bool isleap(int y){ if( (y%400==0) || (y%4==0 && y%100!=0) ) return 1; return 0;}int main(){ int y; while(cin>>y) { int ans = 0, i; for(i=y+1; ; i++) { if(isleap(i)) { ans += 2;///366%7 == 2 ans %= 7; } else { ans++;///365%7 == 1 ans %= 7; } if(ans==0 && (isleap(y)==isleap(i))) break; } cout<<i<<endl; } return 0;}
- Educational Codeforces Round 13 A.Johny Likes Numbers && B. The Same Calendar
- Educational Codeforces Round 13 A Johny Likes Numbers(水题)
- A. Johny Likes Numbers
- 【水水水】678A - Johny Likes Numbers
- Johny Likes Numbers
- Educational Codeforces Round 2 A. Extract Numbers
- Educational Codeforces Round 7--B. The Time
- Educational Codeforces Round 7 B. The Time
- Educational Codeforces Round 8 (A B C)
- Educational Codeforces Round 17 A+B
- Educational Codeforces Round 30(A+B)
- Educational Codeforces Round 31 A B C
- Educational Codeforces Round 32 A B C
- Educational Codeforces Round 22 A. The Contest
- codeforces Educational Codeforces Round 2 A. Extract Numbers
- Codeforces Educational Codeforces Round 2 A. Extract Numbers
- Educational Codeforces Round 2 A. Extract Numbers(模拟)
- Educational Codeforces Round 2 A.Extract Numbers(模拟)
- Android UI根据屏幕分辨率决定加载布局
- 平方数的研究
- 打好Android基础,实战中运用
- 老板/员工流式并行计算模型
- 如何基于FFMPEG和SDL写视频播放器
- Educational Codeforces Round 13 A.Johny Likes Numbers && B. The Same Calendar
- 通过maven创建javaweb项目的搭建工作
- 一切编程语言都是纸老虎
- 二叉树节点量碰规则的计算
- 132. Palindrome Partitioning II
- springmvc——入门学习
- 详解Xshell连接本地安装的Linux虚拟机—— Debian
- python 网络爬虫——爬取小米应用商店排名前100App
- 使用 drawBitmapMesh 扭曲图片