Cantor表
来源:互联网 发布:重建僵尸大陆3修改数据 编辑:程序博客网 时间:2024/05/11 20:37
把分子和分母均小于108的分数按下面的办法排成一个数表。
1/2→1/2 1/3→1/4 1/5 ……
↙ ↗ ↙ ↗
2/1 2/2 2/3 2/4 2/5 ……
↓↗ ↙ ↗
3/1 3/2 3/3 3/4 3/5 ……
↙ ↗
4/1 4/2 4/3 4/4 4/5 ……
↓↗
5/1 5/2 ……
……
我们以Z方形方法给上表的每项编号。第一项是1/1,然后是1/2、2/1、3/1、2/2、1/3、1/4、2/3……。编程输入项号N(1<=N<=10),输出表中第N项。
样例输入:
3
14
7
12345
样例输出:
2/1
2/4
1/4
59/99
#include<stdio.h>#include<string.h>#include<math.h>#include<ctype.h>#include <stdlib.h>int add(int x){ return x==1?1:add(x-1)+x;}int main(){ int x,y,i,n,cost[20010]; char buf[1000]; while(scanf("%d",&n)==1) { for(i=1;add(i)<n;i++); x=add(i)-n; //printf("%d %d %d\n",i,add(i),x); if(i%2==1) printf("%d/%d\n",x+1,i-x); else printf("%d/%d\n",n-add(i-1),i+1-n+add(i-1)); } return 0;}
0 0
- Cantor表
- Cantor表
- Cantor表
- cantor表
- Cantor表
- Cantor表
- Cantor表
- cantor表
- Cantor表
- Cantor表
- Cantor表
- Cantor表
- Cantor表
- Cantor表
- WikiOI 1083 Cantor表
- wikioi p1083 Cantor表
- wikioi 1083 Cantor表
- CODEVS 1083 Cantor表
- Struts2中xxx-validation.xml 无法引入xwork-validator-1.0.2.dtd
- BurpSuite抓包改包上传
- 反思:别被敏捷忽悠
- jdk1.6 download address
- 数组各个元素不相等的判断方式
- Cantor表
- 搞笑
- android判断是否是锁屏
- NYOJ233 Sort it
- IO流详解
- CentOS6.5配置LAMP
- 预装Windows 8系统的电脑如何划分更多的磁盘分区
- 如何获取android的所有运行中的进程
- u-boot移植第五弹——2013.10u-boot通过tftp下载到内存中运行