算法竞赛入门——Cantor的数表
来源:互联网 发布:手机算命软件下载 编辑:程序博客网 时间:2024/05/16 11:26
如下列数,第一项是1/1,第二项是1/2,第三项是2/1,第四项是3/1,第五项是2/2,……。输入n。输出第n项。1/1 1/2 1/3 1/4 1/52/1 2/2 2/3 2/43/1 3/2 3/34/1 4/25/1输入样例:314712345输出样例:2/12/41/459/99
分析:本题可以看成对1~n进行求和
代码如下:
#include <iostream>#include <stdio.h>#include <stdlib.h>using namespace std;int main(){ int n,s=1,sum=1; while(cin>>n) { /*for(int i=1;i<=n;i++) { for(int j=1;j<=n-i+1;j++) { cout<<i<<"/"<<j<<" "; } cout<<endl; }*/ while(sum<n) { s++; sum+=s; } //cout<<s<<endl; int h=sum-n; //cout<<h<<endl; cout<<h+1<<"/"<<s-h<<endl; } return 0;}
本题代码中包含了调试过程,仅供参考。。。。
阅读全文
0 0
- 算法竞赛入门——Cantor的数表
- 算法竞赛入门 5.4.1 Cantor的数表
- 算法竞赛入门经典 5.4.1Cantor数表
- 算法竞赛入门经典-第五章cantor数表
- 算法篇-数学基础-Cantor的数表
- Cantor的数表
- cantor的数表
- 白皮书&&cantor的数表
- Cantor的数表
- Cantor的数表
- cantor的数表
- Cantor的数表 数学
- Cantor的数表
- Cantor的数表
- cantor的数表
- Cantor的数表
- Cantor的数表
- Cantor的数表
- 理解BPMN2.0(1)
- Linux系统下的进程键的通信
- webpack.config.js配置详解
- MAC使用IDA PRO远程调试LINUX程序
- python time时间格式化
- 算法竞赛入门——Cantor的数表
- h3c 配置 时钟
- RecyclerView Bug:IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解决方案
- X Chen笔记---KVM调整虚拟机硬盘大小
- 赫夫曼树(哈夫曼树)
- android 唤醒手机上的地图应用
- spring-cloud-zuul服务网关(五)
- spring顶级框架
- 堆和优先权队列