• tititi


    描述 Description  
      现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的。他是用下面这一张表来证明这一命题的:
    1/1  1/2  1/3  1/4  1/5 …
    2/1  2/2  2/3  2/4  …
    3/1  3/2  3/3  …
    4/1  4/2  …
    5/1  …

    我们以Z字形给上表的每一项编号。
    第一项是1/1,然后是1/2,2/1,3/1,2/2,…

    ::点击图片在新窗口中打开::



         
         
      输入格式 Input Format  
      输入:整数N(1≤N≤10000000)
         
         
      输出格式 Output Format  
      输出:表中的第N项
         
         
      样例输入 Sample Input  
     
         
         
      样例输出 Sample Output  
     
         
         
      时间限制 Time Limitation  
      各个测试点1s
         
         
      注释 Hint  
      很简单的!!
         
         
      来源 Source  
      NOIP1999普及组第一题
     
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<iomanip>
    using namespace std;
    int main()
    {
       int N,i=0,a=0,x,y;
       cin>>N;
       do
       {i++;  
       a+=i;}
       while(a<N);
       x=i-a+N;
       y=a-N+1;
       if(i%2==0) cout<<x<<'/'<<y<<endl;
       if(i%2==1) cout<<y<<'/'<<x<<endl;
       //cout<<setiosflags(ios::fixed)<<setprecision(1);
       return 0;
    }
    #include<stdio.h>
       #include<math.h> 
       int main(void) 
       {float f; int N,n,zi,mu; scanf("%d",&N); 
       f=(-1+sqrt(1+8*N))/2; 
       n=(int)f; 
       if(f-(float)n!=0) n+=1;
       if(n%2==0) {zi=N-(n-1)*n/2; mu=n+1-zi; } 
       else {zi=n*(n+1)/2-N+1; mu=n+1-zi; } 
       printf("%d/%d",zi,mu);  }
       


    第一种为自写,第二种上网查的)(*^__^*) ……

  • 相关阅读:
    HTTP响应状态码整理
    Python通用爬虫,聚焦爬虫概念理解
    HTTP无状态协议理解
    会话与事务知识点总结
    并发一致性知识点整理
    使用隔离级别read committed隐式解决并发冲突
    多并发笔记整理
    git基本使用
    Docker其他
    Docker Bind Mount 与 Volume
  • 原文地址:https://www.cnblogs.com/jzyz-lfy/p/7262486.html
Copyright © 2020-2023  润新知