zoukankan      html  css  js  c++  java
  • ZOJ

    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.

    Polygonal Numbers: Triangular, Square, Pentagonal and Hexagonal numbers

    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.

    2016 is a triangular-hexagonal-leap year

    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
    ", i->first);
        return 0;
    }

  • 相关阅读:
    iis7 下配置 ASP.NET MVC 项目遇到的问题 (WIN7 64位 旗舰版 第一次配置站点)
    C# .NET 使用 NPOI 读取 .xlsx 格式 Excel
    C# .NET 使用 NPOI 生成 .xlsx 格式 Excel
    SQL和T-SQL之间的区别
    .net core的服务器模式和工作站模式
    Windows Mysql8 设置大小写敏感
    每个国家对应的语言Locale和国家代码对照表(转)
    IL指令集
    使用 nvm 管理不同版本的 node 与 npm
    SSIS 包部署 Package Store 后,在 IS 中可以执行,AGENT 执行却报错
  • 原文地址:https://www.cnblogs.com/RootVount/p/10706011.html
Copyright © 2011-2022 走看看