atcoder 之February 29th

Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB

Problem

Charlie was born January 1st of the year A,
on the Earth. He will leave the Earth on December 31st of the year B.

He wants to know how many times he passes February 29th on the Earth.

February 29th is a leap day. A year that contains a leap day is called a leap year. You can determine if a year is leap year or not by following rules.

  • If the year is divisible by 4, it is a leap year except the following case.
  • If the year is divisible by 100, it is NOT a
    leap year except the following case.
  • If the year is divisible by 400, it is a leap year.

Output how many times Charlie passes February 29th on the Earth. Note that Charlie lives very long.


Input

The input will be given in the following format from the Standard Input.

A B
  • On the first line, you will be given the year A(1≦A≦2,000,000,000), when Charlie born,
    followed by a space and the year B(AB≦2,000,000,000), when he leaves the Earth.

Achievements and Points

  • When you pass every test case where 1≦AB≦3,000 , you will be awarded 25 points.
  • In addition, if you pass all the rest test cases you will be awarded 25 more points.

Output

Output how many times Charlie passes February 29th on the Earth in one line. Make sure to insert a line break at the end of the output.


Inout Example 1

  1. 1988 2014

Output Example 1

  1. 7

Charlie can pass February 29th of 1988199219962000200420082012.
The total is 7 times.


Input Example 2

  1. 997 1003

Output Example 2

  1. 0

Note that the year 1000 is NOT a
leap year.


Input Example 3

  1. 1 2000000000

Output Example 3

  1. 485000000

Note that Charlie lives very long.

思路:这题就是求那个年份之间的闰年数目,简单题,直接上代码。

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int temp1=b/4-(a-1)/4;
			int temp2=b/100-(a-1)/100;
			int temp3=b/400-(a-1)/400;
			System.out.println(temp1-temp2+temp3);
		}
	}
}
时间: 2024-08-02 06:28:00

atcoder 之February 29th的相关文章

atcoder 它February 29th

Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB Problem Charlie was born January 1st of the year A, on the Earth. He will leave the Earth on December 31st of the year B. He wants to know how many times he passes February 29th on the Ea

UESTC 893 First Date 计算时间

点击打开链接 First Date Time Limit: 5678/1234MS (Java/Others)     Memory Limit: 65432/65432KB (Java/Others) Submit  Status In 1582, pope Gregory XIII decreed a calendar reform to bring the mean length of the calendar year (counted in days) more in line wit

AtCoder Regular Contest 075 E - Meaningful Mean 树状数组求顺序对, 前缀和

题目链接: http://arc075.contest.atcoder.jp/tasks/arc075_c 题意: 给你一个序列和一个数k,求有多少对l,r,使得a[l]+a[l+1]+...+a[r]的算术平均数大于等于k 1≤N≤2×10^5 1≤K≤10^9 1≤ai≤10^9 思路: 首先对于所有数减去k,这样就不用除(r-l+1), 然后我们发现所求的就是有多少对l,r,使得sum[r]-sum[l-1] >= 0, sum是减去k之后的序列的前缀和 用树状数组对sum求有多少个顺序对

vc++6 Platform SDK February 2003

vc++6.0 sp6 ftp://ejiasoft:[email protected]/else/VC++.6.0.with.SP6.ISO MSDN http://ftp.sdshiyan.cn/soft/program/DN60ACHS1.rar http://ftp.sdshiyan.cn/soft/program/DN60ACHS2.rar MSDN帮助文件1 ftp://ejiasoft:[email protected]/else/MSDN/DN60ACHS1.iso MSDN帮助

February 29(模拟)

D - D Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1414 Description It is 2012, and it's a leap year. So there is a "February 29" in this year, which is called leap day. Interestin

lightoj - 1414 February 29

February 29 Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Submit Status Description It is 2012, and it's a leap year. So there is a "February 29" in this year, which is called leap day. Interesting thing is the in

Supra TK Society High Tops Purple White 24 February at 9pm on ABC Network.Episode 8 is titled

my OCD crossed into an eating disorder. I noticed one day that I had sat down to eat breakfast at exactly eight o'clock – and I thought it felt almost comforting. I thought it would be nice to eat at exactly 11 or 12, as I could make a pattern out of

AtCoder 2346 No Need

传送门:http://arc070.contest.atcoder.jp/tasks/arc070_b?lang=en 题意: 对于一个数组的任意一个子集,如果它的元素和大于等于K这个子集就叫做good subset,如果将一个数所在的所有good subset都减去这个数,这些集合依旧是good subset那么这个数被称为无用数.现在给定一个数组,求其中的无用数的个数.  题解: 如果一个数不是无用数,那么所有大于等于这个数的数都不会是无用数,那么我们先对这个数组进行排序,每次二分结果就行了

Atcoder Yet Another Palindrome Partitioning(状压dp)

Atcoder Yet Another Palindrome Partitioning 思路: 一个字符串满足条件的情况是奇数字母个数小于等于1,也就是异或起来是1<<j(0<=j<=25) 记mark是异或起来的值 状态转移: dp[mark]=dp[mark]+1; dp[mark]=min(dp[mark^(1<<j)]+1,dp[mark]);(0<=j<=25) 注意dp[0]被转移后可能会变成1,但是由它转移的需要dp[0]=0,所以每次记得把d