[CF从零单排#11]69A - Young Physicist

题目来源:http://codeforces.com/problemset/problem/69/A

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 x i coordinate, the y i coordinate and the z i coordinate of the force vector, applied to the body ( - 100 ≤ x i, y i, z i ≤ 100).

Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.

Examples
input
3
4 1 7
-2 4 -1
1 -5 -3
output
NO
input
3
3 -1 7
-5 2 -4
2 -1 -3
output
YES

题目大意:

第一行输入一个整数n,接下来有n行数据,每行代表着向量的三维坐标(x,y,z)的值。问经过n个向量的调整后,能回到原点(0,0,0)吗?如果可以,输出YES,否则输出NO。

题目分析:

模拟题,只需要将所有的x值进行求和,y值进行求和, z值进行求和。问最后三个的值是否都为0.

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, x, y, z, a, b, c;
	cin >> n;
	a = b = c = 0;
	for(int i=1; i<=n; i++){
		cin >> x >> y >> z;
		a += x;
		b += y;
		c += z;
	}
	if(a==0 && b==0 && c==0)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}
上一篇:Younger Americans feel their voting weight


下一篇:jvm 参数详解