Tsinsen A1134 Cantor表

来源:互联网 发布:mac磁盘清理软件排名 编辑:程序博客网 时间:2024/05/16 01:11

http://oj.tsinsen.com/A1134

分析:数过去就好了..这题坑啊,样例给的是错的,输入7应该输出4/1,样例说是1/4…害我晕了半天

代码:

#include "bits/stdc++.h"using namespace std;int main () {    int q; scanf("%d", &q);    int n = 1, s = 0;    while (s + n < q) s += (n++);    for (int m = 1; m <= n; ++m)        if (s + m == q) {            printf("%d/%d\n", n + 1 - m, m);            break;        }    return 0;}
0 0
原创粉丝点击