zoukankan      html  css  js  c++  java
  • 1083 Cantor表

    题目描述 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,…

    输入描述 Input Description

    整数N(1≤N≤10000000)

    输出描述 Output Description

    表中的第N项

    样例输入 Sample Input

    7

    样例输出 Sample Output

    1/4

    数据范围及提示 Data Size & Hint

    见描述

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 using namespace std;
     6 int tot=1;
     7 int ans=2;
     8 int now=1;// 1向下 2向上 
     9 int a[101][101];
    10 int main()
    11 {
    12     int n;
    13     cin>>n;
    14     int i=1,j=1;
    15 //    cout<<1<<" ";
    16     while(tot<n)
    17     {
    18         if(now==1)
    19         {
    20             tot++;
    21             if(j==1)
    22             {
    23                 if(j==1)
    24                 i++;
    25                 else j++;
    26                 now=2;
    27                 continue;
    28             }
    29             else
    30             {
    31                 i++;
    32                 j--;
    33             }
    34             
    35         }
    36         if(now==2)
    37         {
    38             tot++;
    39             if(i==1)
    40             {
    41                 if(i==1)
    42                 j++;
    43                 else i++;
    44                 now=1;
    45                 continue;
    46             }
    47             else
    48             {
    49                 i--;
    50                 j++;    
    51             }
    52         }
    53         else now=1;    
    54     }
    55     cout<<j<<"/"<<i;
    56     return 0;
    57 }
  • 相关阅读:
    端午节习俗
    彩绘漂亮MM集
    高效使用数码相机的诀窍
    项目管理缩略语
    数码相机如何当做摄像头(文字版)
    标签式按纽
    显示一个Form中的所有内容
    生活中要常常鼓励别人
    青苹果论坛重新开放
    第一次爱的人
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/6575827.html
Copyright © 2011-2022 走看看