Codevs 1083 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,…

输入描述 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<cstring>
 4 using namespace std;
 5 int map[100][100],n;
 6 int main()
 7 {
 8     cin>>n;
 9     int s=0,t,k=1;
10     while(s<n)
11     {
12         s+=k;
13         k++;
14     }
15     t=s-n+1;
16     if((k-1)%2==0)
17     printf("%d/%d",k-t,t);
18     else 
19     printf("%d/%d",t,k-t);
20     
21     return 0;
22 }

思路:斜着一列列的看~,自己慢慢想去吧

原文地址:https://www.cnblogs.com/suishiguang/p/6005374.html