题目链接

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. AC日记——Flag Codeforces 16a

    A. Flag time limit per test 2 seconds memory limit per test 64 megabytes input standard input output ...

  2. vs-react-插件

  3. L1-2. 点赞【求多组数据中出现次数最多的】

    L1-2. 点赞 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持.每 ...

  4. CCCC L2-023. 图着色问题【set去重判不同种类个数/简单图论/判断两相邻点是否存在同色以及颜色个数】

    L2-023. 图着色问题 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 图着色问题是一个著名的NP完全问题.给定无向图 G ...

  5. Codeforces 635D Factory Repairs【树状数组】

    又是看了很久的题目... 题目链接: http://codeforces.com/contest/635/problem/D 题意: 一家工厂生产维修之前每天生产b个,维修了k天之后每天生产a个,维修 ...

  6. ML | PCA

    what's xxx PCA principal components analysis is for dimensionality reduction. 主要是通过对协方差矩阵Covariance ...

  7. 100 Most Influential Books According to Stack Overflow

    Please read this blog post to see why this is here. This data was created on 02/13/2012 20:00:00 All ...

  8. scp 时出现permission denied

    如果scp到 /usr/local/目录下,则无权限,可更改到用户目录下

  9. 谈oracle数据比对(DBMS_COMPARISON)

    今天是2014-08-19,我今天收到csdn给我发的申请博客专家的邀请,自己感觉实在羞愧啊. 自从换了工作也一直没有精力在写点东西了.今天我一个同事,在群里贴出了一个数据比对的包(DBMS_COMP ...

  10. 随想录(fatfs的学习)

    [ 声明:版权全部,欢迎转载,请勿用于商业用途.  联系信箱:feixiaoxing @163.com] 上学的时候就对文件系统非常有兴趣.可是苦于没有合适的fs代码能够学习.市面上的fs代码,要么太 ...