Skip to content

Commit e5f6de2

Browse files
author
lanyuanxiaoyao
committed
修改文件: _posts/2014-10-04-as-high-as-ltc.md
1 parent 78108c4 commit e5f6de2

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

_posts/2014-10-04-as-high-as-ltc.md

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,47 @@ tags: [杭电HDU]
77
---
88
## Problem
99
>**Problem Description**
10-
Your task is to Calculate the sum of some integers.
10+
大家提到LTC都佩服的不行,不过,如果竞赛只有这一个题目,我敢保证你和他绝对在一个水平线上
11+
你的任务是:
12+
计算方程x^2+y^2+z^2= num的一个正整数解。
1113
**Input**
12-
Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.
14+
输入数据包含多个测试实例,每个实例占一行,仅仅包含一个小于等于10000的正整数num。
1315
**Output**
14-
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
16+
对于每组测试数据,请按照x,y,z递增的顺序输出它的一个最小正整数解,每个实例的输出占一行,题目保证所有测试数据都有解。
1517
**Sample Input**
16-
4 1 2 3 4
17-
5 1 2 3 4 5
18-
0
18+
3
1919
**Sample Output**
20-
10
21-
15
20+
1 1 1
2221

2322
## Solution
2423
```cpp
25-
#include<stdio.h>
26-
int main()
27-
{
28-
int n,i,m,sum;
29-
while((scanf("%d",&n)!=EOF)&&(n!=0))
30-
{
31-
sum=0;
32-
i=1;
33-
while(i<=n)
34-
{
35-
scanf("%d",&m);
36-
{
37-
sum=sum+m;
38-
}
39-
i++;
40-
}
41-
printf("%d\n",sum);
24+
#include<stdio.h>
25+
#include<math.h>
26+
int main(void)
27+
{
28+
int x,i,j,k,sign,num,t;
29+
30+
while(scanf("%d",&x)!=EOF){
31+
sign=0;
32+
for(i=1;i*i<x;i++){
33+
for(j=1;j*j<x;j++){
34+
for(k=1;k*k<x;k++){
35+
t=i*i+j*j+k*k;
36+
if(t==x){
37+
sign=1;
38+
break;
39+
}
40+
}
41+
if(sign==1){
42+
break;
43+
}
44+
}
45+
if(sign==1){
46+
break;
47+
}
48+
}
49+
printf("%d %d %d\n",i,j,k);
4250
}
43-
return 0;
44-
}
51+
return 0;
52+
}
4553
```

0 commit comments

Comments
 (0)