题目链接

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3935

题意

要求找出 从 2016-990528 中 是闰年 并且满足

这两个公式的年份

输出就可以了

思路

其实可以发现 在第一个公式中 2016 = 63*64 第二个公式中 2016=32*63

然后 第一个公式 从 63开始跑 第二个公式从 32开始跑

用 MAP 保存 最后从小到大 输出 两个MAP中都有 并且是闰年的年份就可以

AC代码

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctype.h>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std; const int maxn = 990528; bool isleap(int x)
{
return ((x % 4 == 0 && x % 100 != 0) || (x % 400 == 0));
} int main()
{
map <int, int> m[2];
for (int i = 63; i * (i + 1) <= maxn * 2; i++)
m[0][i * (i + 1) / 2] = 1;
for (int i = 32; i * (2 * i - 1) <= maxn; i++)
m[1][i * (2 * i - 1)] = 1;
map <int, int>::iterator it;
for (it = m[0].begin(); it != m[0].end(); it++)
{
if (m[1][it->first] && isleap(it->first))
printf("%d\n", it -> first);
}
}

ZOJ - 3935 2016 【数的筛选】的更多相关文章

  1. ZOJ 3935 2016

    简单规律题...没看懂题目直接从输出中找到了规律. 先不管是不是闰年,前后两项的差值会形成一个等差数列,公差是64... 输出的时候再判一下闰年即可. #include<cstdio> # ...

  2. ZOJ 1842 Prime Distance(素数筛选法2次使用)

    Prime Distance Time Limit: 2 Seconds      Memory Limit: 65536 KB The branch of mathematics called nu ...

  3. php转化输入日期为Unix 纪元到当前时间的秒数 日期筛选

    多条件筛选时 日期筛选 部分 demo   http://pan.baidu.com/s/1hqGF5Ik 时间输入控件http://www.jq22.com/jquery-info332 输入控件 ...

  4. Number of Containers ZOJ - 3175(数论题)

    Problem Description For two integers m and k, k is said to be a container of m if k is divisible by  ...

  5. Handshakes(思维) 2016(暴力)

    Handshakes Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Sta ...

  6. Project Euler 98:Anagramic squares 重排平方数

    Anagramic squares By replacing each of the letters in the word CARE with 1, 2, 9, and 6 respectively ...

  7. 排它平方数|2013年蓝桥杯A组题解析第二题-fishers

    排它平方数 小明正看着 203879 这个数字发呆. 原来,203879 * 203879 = 41566646641 这有什么神奇呢?仔细观察,203879 是个6位数,并且它的每个数位上的数字都是 ...

  8. python推荐淘宝物美价廉商品

    完成的目标: 输入搜索的商品 以及 淘宝的已评价数目.店铺的商品描述(包括如实描述.服务态度.快递的5.0打分): 按要求,晒选出要求数量的结果,并按"物美价廉算法"排序后输出 思 ...

  9. UVA1213Sum of Different Primes(素数打表 + DP)

    题目链接 题意:选择k个素数,使得和为N(1120)的方案数: 筛选出 <= N 的素数,然后就背包 写的时候没初始dp[0][0] = 1;而且方案数也没相加,真是弱逼 #include &l ...

随机推荐

  1. Toast问题记录:This Toast was not created with Toast.makeText()

    最近使用自己封装的Toast时,遇到一个问题 java.lang.RuntimeException: This Toast was not created with Toast.makeText() ...

  2. python常用模块1

    一. 什么是模块: 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写的代码 ...

  3. 总结下常用js中的小语法和技巧

    1,数组对象遍历 对一个级数对象进行遍历,取出每个值 var arr={ "result":[ {"time":"2018-10-24 12:12:1 ...

  4. linux环境设置export

    一. shell显示与设置环境变量 1.export //echo $PATH 2.export | grep ROS 3.export ROS_IP=192.168.0.5(添加环境变量ROS_IP ...

  5. mysql事务四种隔离级别

    事务的基本要素:原子性,一致性,隔离性,持久性. 事务并发问题:脏读,不可重复读,幻读. mysql隔离级别:read-uncommitted,read-committed,repeatable-re ...

  6. Java Static Import的用法

    在头部使用的imoirt static ***方式叫做静态引入,在Java SE 1.5.0(JDK 5)引入的特性. 官方文档的介绍: 为了访问静态成员,有必要限定它们来自的类的引用.例如,必须这样 ...

  7. Android:MVC模式(下)

    在上一篇文章中,我们将 View 类单独出来并完成了设计和编写.这次我们将完成 Model 类,并通过 Controller 将两者连接起来,完成这个计算器程序. 模型(Model)就是程序中封装了数 ...

  8. 百科知识 DMG文件如何打开

    1 DMG格式是在MAC系统上的一个镜象文件,也可以说是压缩文件,如果你是使用苹果机或在PC上装了MAC OS X for X86,在MAC系统上双击这个文件就可以解开了:现在在Windows平台,我 ...

  9. C#.NET的TabControl如何隐藏和显示页面

    如果需要显示某个页面,则让他的Parent就是TabControl的控件名称,如果要隐藏,则等于null      private void ToolStripMenuItemTeachPanelBa ...

  10. [LeetCode][Java] Unique Paths II

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...