cantor的数表
来源:互联网 发布:杭州seo异同 编辑:程序博客网 时间:2024/06/10 09:34
有如下数列,第一项是1/1,第二项是1/2,第三项是2/1,第四项是3/1,第五项是2/2......输入n,输出第n项。
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
例如输出:
14 3 7
2/4
2/1
1/4
分析:
数表的顺序是如下摆列的:
1_ 2 6 _ 7 15
/ / / /
3 5 8 14
| / / /
4 9 13
/ /
10 12
| /
11
先判断n在第几条斜线上,然后判断该斜线奇偶性,因为奇偶处理情况相反。令sum为斜线上最大元素值,count为第几斜线。
对于奇斜线上的数,可以分析得到,n的分子为sum - n + 1,分母为count - sum + n,偶斜线上相反。
代码如下:
//cantor的的数表#include <stdio.h>int main(){int n;while (scanf("%d",&n) == 1){int count = 1,sum = 0;for (;;){sum += count;if (sum >= n){if (!(count % 2))//如果在第偶数斜线条{printf("%d / %d\n",count - sum + n,sum - n + 1);} else{printf("%d / %d\n",sum - n + 1, count - sum + n);}break;}count++;}}return 0;}
- Cantor的数表
- cantor的数表
- 白皮书&&cantor的数表
- Cantor的数表
- Cantor的数表
- cantor的数表
- Cantor的数表 数学
- Cantor的数表
- Cantor的数表
- cantor的数表
- Cantor的数表
- Cantor的数表
- Cantor的数表
- Cantor的数表
- Cantor的数表
- 【Cantor 的数表 5.4.1】
- 【Cantor 的数表 5.4.1】
- Cantor的数表 【找规律】
- 拉卡拉手机刷卡器音频通讯技术原理初步分析
- C++查漏补缺——String(1)
- h264 cabac 总结
- Uva 216 - Getting in Line
- JDBC与Oracle的连接
- cantor的数表
- 基础总结篇之二:Activity的四种launchMode
- maven group artifact常用的仓库搜索地址
- 我所理解的设计模式(C++实现)——简单工厂模式(Simple Factory Pattern)
- getElementsByName 在IE下面的bug 的解决
- CreateThread()、_beginthreadex()及、AfxBeginThread()的联系和区别
- 准备开始写博客了
- Access denied for user 'root'@'localhost' (using password: YES)
- 杭电1024