ZOJ - 3935 2016 【数的筛选】
题目链接
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 【数的筛选】的更多相关文章
- ZOJ 3935 2016
简单规律题...没看懂题目直接从输出中找到了规律. 先不管是不是闰年,前后两项的差值会形成一个等差数列,公差是64... 输出的时候再判一下闰年即可. #include<cstdio> # ...
- ZOJ 1842 Prime Distance(素数筛选法2次使用)
Prime Distance Time Limit: 2 Seconds Memory Limit: 65536 KB The branch of mathematics called nu ...
- php转化输入日期为Unix 纪元到当前时间的秒数 日期筛选
多条件筛选时 日期筛选 部分 demo http://pan.baidu.com/s/1hqGF5Ik 时间输入控件http://www.jq22.com/jquery-info332 输入控件 ...
- 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 ...
- Handshakes(思维) 2016(暴力)
Handshakes Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Sta ...
- Project Euler 98:Anagramic squares 重排平方数
Anagramic squares By replacing each of the letters in the word CARE with 1, 2, 9, and 6 respectively ...
- 排它平方数|2013年蓝桥杯A组题解析第二题-fishers
排它平方数 小明正看着 203879 这个数字发呆. 原来,203879 * 203879 = 41566646641 这有什么神奇呢?仔细观察,203879 是个6位数,并且它的每个数位上的数字都是 ...
- python推荐淘宝物美价廉商品
完成的目标: 输入搜索的商品 以及 淘宝的已评价数目.店铺的商品描述(包括如实描述.服务态度.快递的5.0打分): 按要求,晒选出要求数量的结果,并按"物美价廉算法"排序后输出 思 ...
- UVA1213Sum of Different Primes(素数打表 + DP)
题目链接 题意:选择k个素数,使得和为N(1120)的方案数: 筛选出 <= N 的素数,然后就背包 写的时候没初始dp[0][0] = 1;而且方案数也没相加,真是弱逼 #include &l ...
随机推荐
- 小程序-支持的最小像素px
经过我手机多次测试,支持的最小px为: 8px;
- 东方14模拟赛之noip2015/day1/3/神奇的幻方
总时间限制: 10000ms 单个测试点时间限制: 1000ms 内存限制: 128000kB 描述 幻方是一种很神奇的N*N 矩阵:它由数字 1,2,3, … …,N*N 构成,且每行.每列及 ...
- SRM1154--Topcoder初体验
SRM 711 DIV2 <br > 在frank_c1的帮助下,辣鸡Xiejiadong也开始做Topcoder辣...... <br > 这算是一次Topcoder的初体验 ...
- Java -----transient 和static
越来越喜欢深究java基础了,讲讲 transient 和static 对序列化的影响.废话少说,直接上代码就可以了 package serializable; import java.io.Ser ...
- CODECHEF Oct. Challenge 2014 Children Trips
@(XSY)[分塊, 倍增] Description There's a new trend among Bytelandian schools. The "Byteland Tourist ...
- BT中的磁力链接(转)
注意:磁力链接不是迅雷的,而是BT网络中的一种协议. 磁力链接与种子文件 磁力链接并不是一个新概念,早在2002年,相关的标准草稿就已经制定了.但直到2012年海盗湾为规避版权问题删除了站点上的所有T ...
- android toolbar 假标题居中
<android.support.v7.widget.Toolbar android:id="@+id/toolbar_top" android:layout_height= ...
- sshpass结合ssh和scp可以自动完成密码登录,无需手动输入密码
使用方法: 1.sshpass -p 123456 ssh admin@1.1.1.1 "touch file" 远程创建文件file 2.sshpass -p 123456 s ...
- IOS 教你玩转UITableViewController和TableView
iphone和Ipad开发中UITableViewController和TableView应该是用得比較多得控件. 可是你是会由于写这些控件写得多了而厌烦. 全部怎么让这个控件一直能用.怎么让这个控件 ...
- mysql存储过程之循环
链接: http://www.blogjava.net/rain1102/archive/2011/05/16/350301.html