题目链接

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. android-samples-mvp

    Model–view–presenter (MVP)介绍 mvp在wiki上的介绍为 Model  定义用户界面所需要被显示的数据模型,一个模型包含着相关的业务逻辑 View  View不应该处理业务 ...

  2. POJ1430 Binary Stirling Numbers

    @(POJ)[Stirling數, 排列組合, 數形結合] Description The Stirling number of the second kind S(n, m) stands for ...

  3. pt-pmp :pt toolkit

    http://www.cnblogs.com/ivictor/p/6012183.html

  4. Go -- 接口赋值

    在go语言中,接口赋值分为2中情况: 1.将对象实例赋值给接口: 2.将一个接口赋值给另一个接口. 1.将对象实例赋值给接口: 要求对象实现了接口的所有方法. 2.将接口赋值给另一个接口: 假设接口A ...

  5. 进程间通信IPC、LPC、RPC

    进程间通信(IPC,Inter-Process Communication),指至少两个进程或线程间传送数据或信号的一些技术或方法.进程是计算机系统分配资源的最小单位.每个进程都有自己的一部分独立的系 ...

  6. 基于HTML5的PACS--HTML5图像处理

    在此之前,此系统是结合DICOM的WADO标准,在浏览器里通过javascript操作返回的JPG图片.这种服务器端解析,客户端展现的方式,对实现图像的移动.缩放.旋转.测量等图像操作能够实现实时的交 ...

  7. Proftpd快速搭建FTP服务器

    前言 在Linux系统中,FTP服务器软件有很多,都已经成熟,像vsftpd, wu-ftp, Pure-FTPd等.但这些软件安装配置起来都比较麻烦,搭建个人的FTP服务器,还是Proftpd比较简 ...

  8. beautifulsoup的一些使用

    自动补全代码: import requests from bs4 import BeautifulSoup response=requests.get('https://www.ithome.com/ ...

  9. 百科知识 tar文件如何打开

    tar 是什么文件格式,是干什么用的,用什么打开 tarball压缩格式,源于Linux的一个指令,Windows上可以用WinRAR打开 Linux的实用程序tar最初是为了制作磁带存档而设计的(把 ...

  10. C 标准库 - <errno.h>

    C 标准库 - <errno.h> 简介 C 标准库的 errno.h 头文件定义了整数变量 errno,它是通过系统调用设置的,在错误事件中的某些库函数表明了什么发生了错误.该宏扩展为类 ...