zoukankan      html  css  js  c++  java
  • 14. 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/22/13/12/2

     

    14. <wbr>Cantor表

     

    输入描述 Input Description

    整数N1≤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;

    }

  • 相关阅读:
    vue 组件
    vue 中的computed和watch
    Vue 框架 笔记
    初次使用git配置以及git如何使用ssh密钥(将ssh密钥添加到github)
    JavaScript 执行机制
    Vue.js 动画
    封装nodeJS中 $on $emit $off 事件
    JS中的事件委托
    什么是“闭包”(closure)为什么要用它?
    js使用面向对象编写下拉菜单
  • 原文地址:https://www.cnblogs.com/csgc0131123/p/5290535.html
Copyright © 2011-2022 走看看