zoukankan      html  css  js  c++  java
  • 求方程解问题

    测试你是否和LTC水平一样高

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 14886    Accepted Submission(s): 4890


    Problem Description
    大家提到LTC都佩服的不行,不过,如果竞赛只有这一个题目,我敢保证你和他绝对在一个水平线上!
    你的任务是:
    计算方程x^2+y^2+z^2= num的一个正整数解。
     
    Input
    输入数据包含多个测试实例,每个实例占一行,仅仅包含一个小于等于10000的正整数num。
     
    Output
    对于每组测试数据,请按照x,y,z递增的顺序输出它的一个最小正整数解,每个实例的输出占一行,题目保证所有测试数据都有解。
     
    Sample Input
    3
     
    Sample Output
    1 1 1
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 using namespace std;
     5 int main()
     6 {
     7     int x,y,num,i,flag=0,temp;
     8     double z;
     9     while(scanf("%d",&num)!=EOF)
    10     {
    11         flag=0;
    12         for(x=1;x<=sqrt(num);x++)
    13         {
    14             for(y=1;y<=sqrt(num-x*x);y++)
    15             {
    16                 temp=num-x*x-y*y;        
    17                 z=sqrt(temp);        /*求平方根*/
    18                 if(abs(z-int(z))<=0.000001&&int(z))        /*判断平方根是否为整数*/
    19                 {
    20                     printf("%d %d %d
    ",x,y,int(z));
    21                     flag=1;
    22                     break;
    23                 }
    24             }
    25         if(flag)
    26             break;
    27         }
    28     }
    29 }
  • 相关阅读:
    Swift -- Swfit 笔记
    web -- CSS 图片宽高不固定的垂直居中方法
    web -- Angularjs 笔记2
    web -- Angularjs 笔记
    web -- Angularjs 备忘录应用
    Swift -- swift 函数代码
    Swift -- 创建空数组和空字典
    Linux -- FresBSD的镜像文件说明
    Linux -- ubuntu下安装程序的三种方法
    Linux -- Ubuntu 命令2
  • 原文地址:https://www.cnblogs.com/a1225234/p/4690431.html
Copyright © 2011-2022 走看看