其他分享
首页 > 其他分享> > 洛谷 P1014 Cantor表

洛谷 P1014 Cantor表

作者:互联网

新手村的纪念

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,tot=0,i=0;//tot用来存储左上角三角形中元素个数
    cin>>N;
    int a=1,b=1;
    while(tot+(++i)<N){
        tot+=i;
    }
    if(i%2==0){//偶数和奇数情况正好是相反的
        a=N-tot;
        b=i+1-a;
    }
    else{
        b=N-tot;
        a=i+1-b;
    }
    printf("%d/%d\n",a,b);
    //system("pause");
    return 0;
}
Coming Liu 发布了4 篇原创文章 · 获赞 0 · 访问量 144 私信 关注

标签:洛谷,查看,int,P1014,元素,tot,点击,Cantor,题目
来源: https://blog.csdn.net/roadtohacker/article/details/104165541