码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ - 3935 2016

时间:2019-04-14 17:58:14      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:max   lines   hex   ios   asi   一个   ase   mat   math   

In mathematics, a polygonal number is a number represented as dots or pebbles arranged in the shape of a regular polygon. The dots are thought of as alphas (units). These are one type of 2-dimensional figurate numbers. The following picture shows how triangular numbers, square numbers, pentagonal numbers and hexagonal numbers represented as dots arranged in the shape of corresponding regular polygon.

技术图片

2016 is not only a leap year but also a triangular and hexagonal year. If you are patient enough, you can count the number of the dots in the left triangle or in the right hexagon in the following picture. The number of dots in each shape is 2016.

技术图片

Therefore, 2016 is a triangular-hexagonal-leap year. The previous triangular-hexagonal-leap year is 1540 and the next is 2556. So living to see 2016 is very rare experience.

You task is to list the triangular-hexagonal-leap years from 2016 to 990528. 990528 is also a triangular-hexagonal-leap year.

Input

This problem has no input.

Output

Please print each triangular-hexagonal-leap year in increasing order.

For example, if you are asked to list the triangular-hexagonal-leap years from 780 to 2556, the output should be:

780
1128
1540
2016
2556

Sample Output

2016
2556
...  <-- some lines are skipped
990528
思路:这道题对于我这个数学很不好的人来说,真的很骚,我冥思苦想,也想不出是这样一个思路。
(三角形)2016 = 63*64/2,(六边形)2016 = 32*63,找在三角形和六边形中共同出现的那个数,用map存起来,再输出共同部分。
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;
#define ll long long
const int inf = 0xffffff;
const int maxn = 1e6;
bool cmp(int x)
{
    if((x%4 == 0 && x%100 != 0) || (x%400 == 0))
        return 1;
    return 0;
}
int main()
{
    map<int, int>a[2];
    for(int i = 63; i*(i+1) <= 990528*2; i++)//把三角形的n*(n+1)/2存起来
    {
        a[0][i*(i+1)/2] = 1;
    }
    for(int i = 32; i*(2*i-1) <= 990528; i++)//把六边形的n*(3*n-1)/2
    {
        a[1][i*(2*i-1)] = 1;
    }
    map<int, int>::iterator i;
    for(i = a[0].begin(); i != a[0].end(); i++)//找三角形和六边形共同出现的数字
        if(a[1][i->first] && cmp(i->first))
            printf("%d\n", i->first);
    return 0;
}

 


ZOJ - 3935 2016

标签:max   lines   hex   ios   asi   一个   ase   mat   math   

原文地址:https://www.cnblogs.com/RootVount/p/10706011.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!