题目链接

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. Delphi 从PaintBox拷贝一部分内容到TBitmap

    将指定的TPaintBox内容(假如为paintbox1)拷贝到一个TBitmap(如Bitmap),可以这么做 Bitmap.Width := PaintBox1.Width; Bitmap.Hei ...

  2. Codeforces Gym101606 I.I Work All Day (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    I I Work All Day 这个题就是取模找最小的. 代码: 1 #include<iostream> 2 #include<cstdio> 3 #include< ...

  3. HDU 5726 GCD(ST&RMQ)

    题目链接 GCD 先ST倍增预处理,f[i][j]表示从i开始(包含第i个数)的连续2^j个数的最大公约数. 这样就可以在O(1)内询问得到a[l]到a[r]之间的所有数的最大公约数的值. 然后对于每 ...

  4. 一次完整的http请求过程以及网络I/O模型select、epoll

    a.一次完整的http请求过程 1.域名解析,得到域名对应的IP; 2.三次握手,客户端与服务器通过socket建立TCP/IP连接; 3.浏览器向服务器发送http请求,如:GET/index.ht ...

  5. 济南day3

    连续几天都有点炸 预计的分拿不到,调整好心态,考试的时候多想一下,think twice,code once 唉,什么情况啊 题解链接 0+0+0 T1读错题输出反了 n*m%2判断是否==1 T2 ...

  6. error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools":解决方案

    我是在安装scrapy时遇到这个问题的,安装其他组件也可能会遇到.但问题解决办法都是大致相同的. 以安装scrapy为例: 在pycharm中安装twisted时出现: error: Microsof ...

  7. datetimepicker使用总结

    datetimepicker使用总结 2019-03-06    16:55:00 使用效果: 官方教程:http://www.bootcss.com/p/bootstrap-datetimepick ...

  8. IntelliJ IDEA导入包的顺序调整和按包类型分类(保持和Eclipse一致)

    调整的内容如下: 空行 import java.* 空行 import javax.* 空行 import com.* 空行 import all other imports 空行 import st ...

  9. [bug]Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

    写在前面 在mysql中这个异常是非常常见的,超时分为连接超时和执行超时,而连接超时,大部分原因是网络问题,或客户端到服务端的端口问题造成. bug场景 有的时候,使用MySqlDataReader在 ...

  10. intent 支持的action 动作

    String ACTION_AIRPLANE_MODE_CHANGED Broadcast Action: The user has switched the phone into or out of ...