一个很简单的题目,但是后面的判断我晕了……求解题

sanguine1211 2011-03-27 09:48:55
Young Physicist
Time Limit:1000MS Memory Limit:65536KB

Description

A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input

The first line contains a positive integer t ( t ≤ 100 ), means the case number.
For every case the first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xicoordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).

Output

Every case print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.

Sample Input

2
3
4 1 7
-2 4 -1
1 -5 -3
3
3 -1 7
-5 2 -4
2 -1 -3
Sample Output

NO
YES

#include<stdio.h>
#define N 101
int main()
{
int a[N][N],b[N];
int i,j,m,n,t,k=0,num=0;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
t=m;
for(i=0;i<m;i++)
for(j=0;j<t;j++)
scanf("%d",&a[i][j]);
for(j=0;j<t;j++)
{
for(i=0;i<m;i++)
num=num+a[i][j];
if(num==0)


后面就不会了。。。求帮助啊!!!
...全文
192 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ulfsaar 2011-03-28
  • 打赏
  • 举报
回复
楼主给下原题链接吧
sanguine1211 2011-03-28
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 ulfsaar 的回复:]

C/C++ code

#include<stdio.h>
void main()
{
int i, m, n, nTemp, nSum1, nSum2, nSum3;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
nSum1 = 0;
nSum2 = 0;
nSum3 ……
[/Quote]

谢谢了。我后来改成这种方法做了,一开始看的像二维数组,就用二维数组做,结果麻烦多了
sanguine1211 2011-03-28
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ulfsaar 的回复:]

楼主给下原题链接吧
[/Quote]

EOJ
acm.cs.ecnu.edu.cn
Ulfsaar 2011-03-28
  • 打赏
  • 举报
回复

#include<stdio.h>
void main()
{
int i, m, n, nTemp, nSum1, nSum2, nSum3;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
nSum1 = 0;
nSum2 = 0;
nSum3 = 0;
for(i=0;i<3*m;++i)
{
scanf("%d",&nTemp);
if (i%3 == 0)
{
nSum1 += nTemp;
}
else if (i%3 == 1)
{
nSum2 += nTemp;
}
else
{
nSum3 += nTemp;
}
}

if (nSum1 == 0 && nSum2 == 0 && nSum3 == 0)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
}
Ulfsaar 2011-03-28
  • 打赏
  • 举报
回复
你给下原题链接,我们就可以自己check下程序是否符合要求了
xzjxylophone 2011-03-28
  • 打赏
  • 举报
回复
感觉 读文件 去做比较简单点, 用scan去做 我就有点蒙了~~~
xzjxylophone 2011-03-28
  • 打赏
  • 举报
回复
题目 大概意思:
一个小孩被罚做一道题目
题目意思如下:
给一组数据(假设是一个文件):
Sample Input
2
3
4 1 7
-2 4 -1
1 -5 -3
3
3 -1 7
-5 2 -4
2 -1 -3

数据是这样被定义的
第一行数据(用t表示,1 <= t <= 100)表示总共有多少个需要验证的例子
第一个测试的样例描述在:
第二行数据(用N1表示,1 <= N1 <= 100)表示紧跟着该行数据以下N1行如果满足下列条件
x,y,z的分量的总和都为0 输入YES,否则输入NO

第二个测试的样例描述在:
第K行(K=N1+1+1),假设数据位N2,表示紧跟着该行数据以下N1行如果满足下列条件
x,y,z的分量的总和都为0 输入YES,否则输入NO

同理 第三个,第四个测试样例都是这样去验证~~~

Ulfsaar 2011-03-27
  • 打赏
  • 举报
回复
理解错了,请忽略
Ulfsaar 2011-03-27
  • 打赏
  • 举报
回复
用这个试试,我电脑没装VC

#include<stdio.h>
void main()
{
int i,m,n,t,nSum;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
nSum = 0;
for(i=0;i<3*m;i++)
{
scanf("%d",&t);
nSum += t;
}

if( nSum == 0)
printf("YES\n");
else
printf("NO\n");
}
}
heartgoon2010 2011-03-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ulfsaar 的回复:]
是判断总和为零么?
[/Quote]
不是。判断是不是每一维之和都是0
heartgoon2010 2011-03-27
  • 打赏
  • 举报
回复
这样就对了:
#include<stdio.h>
#define N 101
int main()
{
int a[N][N],b[N];
int i,j,m,n,t,k=0,num=0;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
t=m;
for(i=0;i<m;i++)
for(j=0;j<t;j++)
scanf("%d",&a[i][j]);
for(j=0;j<t;j++)
{
for(i=0;i<m;i++)
num=num+a[i][j];
if(num==0){b[k]=1;}
else{
b[k]=0;
break;
}
}
k++;
num=0;//注意了
}
for(i=0;i<k;i++)
{
if(b[i]==1) printf("YES\n");
else printf("NO\n");
}

}
Ulfsaar 2011-03-27
  • 打赏
  • 举报
回复
是判断总和为零么?
heartgoon2010 2011-03-27
  • 打赏
  • 举报
回复
#include<stdio.h>
#define N 101
int main()
{
int a[N][N],b[N];
int i,j,m,n,t,k=0,num=0;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
t=m;
for(i=0;i<m;i++)
for(j=0;j<t;j++)
scanf("%d",&a[i][j]);
for(j=0;j<t;j++)
{
for(i=0;i<m;i++)
num=num+a[i][j];
if(num==0){b[k]=1;}
else{
b[k]=0;
break;
}
}
k++;
}
for(i=0;i<k;i++)
{
if(b[i]==1) printf("YES\n");
else printf("NO\n");
}

}
感觉没什么问题,就是得不到预期的结果,你看能不能找出问出来。

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧