zoukankan      html  css  js  c++  java
  • 3.Cantor表

     

    时间限制: 1 s

     空间限制: 128000 KB

     题目等级 : 白银 Silver

    题解

     查看运行结果

    题目描述 Description

    现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的。他是用下面这一张表来证明这一命题的:1/1 1/2 1/3 1/4 1/5 … 2/1 2/2 2/3 2/4 … 3/1 3/2 3/3 … 4/1 4/2 … 5/1 … … 我们以Z字形给上表的每一项编号。第一项是1/1,然后是1/2,2/1,3/1,2/2,…

     

    14. <wbr>Cantor表

     

    输入描述 Input Description

    整数N(1≤N≤10000000)

    输出描述 Output Description

    表中的第N项

    样例输入 Sample Input

    7

    样例输出 Sample Output

    1/4

    数据范围及提示 Data Size & Hint

    见描述

    分类标签 Tags 点此展开 

    NOIP全国联赛普及组 大陆地区 1999

    代码:

    #include

    using namespace std;

    #include

    int i=0;int n;int x=1,y=1;

    void ys()

    {

           while(x!=1&&i

           {

                  x--;y++;

                  i++;

           }

    }

    void zx()

    {

           while(y!=1&&i

           {

                  x++;y--;

                  i++;

           }

    }

    int main()

    {

          

           scanf("%d",&n);

           i=1;

           while(i

           {

                  if(x==1)

                  {

                         y++;i++;

                  }

                  zx();

                  if(y==1)

                  {

                         x++;i++;

                  }

                  ys();

           }

           printf("%d/%d",x,y);

           return 0;

    }

  • 相关阅读:
    SP503 【PRINT
    UVA10924 【Prime Words】
    UVA902 【Password Search】
    UVA10339 【Watching Watches】
    UVA11057 【Exact Sum】
    DP题单解题报告合集
    P1829 [国家集训队]Crash的数字表格 / JZPTAB
    莫比乌斯反演入门
    莫比乌斯函数
    题解 P3168 [CQOI2015]任务查询系统
  • 原文地址:https://www.cnblogs.com/csgc0131123/p/5290282.html
Copyright © 2011-2022 走看看