Tsinsen A1134 Cantor表

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;
}

你可能感兴趣的:(ACM-01)