1.17第二题

B - 2

Time limit 2000 ms
Memory limit 262144 kB

Problem 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 n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).

Output

Print the word “YES” if the body is in equilibrium, or the word “NO” if it is not.

Sample Input

3
4 1 7
-2 4 -1
1 -5 -3

3
3 -1 7
-5 2 -4
2 -1 -3

Sample Output

NO

YES

问题链接:CodeForces - 69A

问题简述:

输入n代表n组坐标,问坐标是否达到平衡点

问题分析:

问坐标是否达到平衡点,即所以x坐标相加等于0,所以y坐标加起来等于0,所有z坐标加起来等于0

程序说明:

利用三个数组存放x、y、z坐标,利用a1,b1,c1来把对应x,y,z坐标累加,最后判断a1,b1,c1是不是等于0即可

AC通过的C语言程序如下:

#include <iostream>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[150],b[150],c[150];
	int a1=0, b1=0, c1=0;
	for (int i = 1;i <= n;i++)
	{
		cin >> a[i];
		cin >> b[i];
		cin >> c[i];
		a1 += a[i];
		b1 += b[i];
		c1 += c[i];
	}
	if((a1==0)&&(b1==0)&&(c1==0))
	{
		cout << "YES";
	}
	else{ cout << "NO"; }
}

猜你喜欢

转载自blog.csdn.net/weixin_44003969/article/details/86537259