14. Cantor表
2016-02-27 18:56
274 查看
时间限制: 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;
}
空间限制:
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;
}
相关文章推荐
- 14. Cantor表
- hdu1240 Asteroids!(三维bfs水)
- 在分类里面写的@property
- Linux(Ubuntu 14.04)如何安装32库
- 从robots.txt開始网页爬虫之旅
- C++变量命名规则
- python之旅【第一篇】
- Win7+VS2013+OpenGL详细配置
- 【BZOJ3261】最大异或和【可持久化Trie树】
- C# 枚举、字符串、值的相互转换
- CF 231A team
- ZOJ 3782 Ternary Calculation(模拟)
- Android学习历程15-Android 软键盘的强制隐藏
- Scrum中的产品需求预审
- MySQL知识(十七)——视图
- BZOJ 3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛|动态规划|排列组合
- Linux精讲——find命令
- ADB backupAgent 提权漏洞分析 (CVE-2014-7953)
- JSP九大内置对象
- JSP九大内置对象