您的位置:首页 > 其它

14. Cantor表

2016-02-27 18:56 190 查看
时间限制: 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,…




Cantor表" title="14. 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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: