C - Young Physicist

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 zicoordinate 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.

Examples

Input

34 1 7-2 4 -11 -5 -3

Output

NO

Input

33 -1 7-5 2 -42 -1 -3

Output

YES解题思路:题目的意思就是检查n行3列中每一列数字之和是否都为0,是的话为"YES",否则为"NO",水过。AC代码:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main(){
 4     int n,a[105][3],b[3];
 5     cin>>n;
 6     memset(b,0,sizeof(b));
 7     for(int i=0;i<n;++i){
 8         for(int j=0;j<3;++j){
 9             cin>>a[i][j];b[j]+=a[i][j];
10         }
11     }
12     bool flag=false;
13     for(int i=0;i<3;++i)
14         if(b[i]!=0){flag=true;break;}
15     if(flag)cout<<"NO"<<endl;
16     else cout<<"YES"<<endl;
17     return 0;
18 }

原文地址:https://www.cnblogs.com/acgoto/p/9128850.html

时间: 2024-11-13 06:33:39

C - Young Physicist的相关文章

[2016-03-22][CF][69A][Young Physicist]

时间:2016-03-22 19:41:34 星期二 题目编号:[2016-03-22][CF][69A][Young Physicist] 题目大意:判断向量和是否为0 分析:对应坐标相加 遇到的问题:不能用x+y+z来判断是否都为0,除非输入都是正数 #include <cstdio> using namespace std; int main(){ int a,b,c,x,y,z,n; x = y = z = 0; scanf("%d",&n); for(in

codeforces水题100道 第九题 Codeforces Beta Round #63 (Div. 2) Young Physicist (math)

题目链接:http://www.codeforces.com/problemset/problem/69/A题意:给你n个三维空间矢量,求这n个矢量的矢量和是否为零.C++代码: #include <cstdio> #include <iostream> using namespace std; int x, y, z; int main() { int n, tx, ty, tz; cin >> n; while (n--) { cin >> tx >

Young Maids

E - Young Maids Time limit : 2sec / Memory limit : 256MB Score : 800 points Problem Statement Let N be a positive even number. We have a permutation of (1,2,…,N), p=(p1,p2,…,pN). Snuke is constructing another permutation of (1,2,…,N), q, following th

线性DP POJ2279 Mr.Young&#39;s Picture Permutations

Mr. Young's Picture Permutations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1128   Accepted: 562 Description Mr. Young wishes to take a picture of his class. The students will stand in rows with each row no longer than the row behin

算法导论 6-3 Young氏矩阵

一.题目 二.思考 最小Young氏矩阵和最小堆的思想差不多,可以通过比较两者的同异来理解Young氏矩阵 不同点:   min-Heap min-Young 堆顶(最小值) H[1] Y[i][j] 最后一个元素的位置 H[N] Y[N][N] 最后一个元素 不一定是最大值 一定是最大值 parent H[i]的parent是H[i/2] Y[i][j]的parent是Y[i-1][j]和Y[i][j-1] child H[i]的child是H[i*2]和H[i*2+1] Y[i][j]的ch

Young Table(暴力,交换位置)

Young Table Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 237B Appoint description:  System Crawler  (2016-04-26) Description You've got table a, consisting of n rows, numbered from 1

p,将Young 区升级为Older区Older区的大小等

第一个线程负责回收Heap的Young区第二个线程在Heap不足时,遍历Heap,将Young 区升级为Older区Older区的大小等于-Xmx减去-Xmn,不能将-Xms的值设的过大,因为第二个线程被迫运行会降低JVM的性能. JVM的垃圾回收机制详解和调优1.JVM的gc概述 gc即垃圾收集机制是指jvm用于释放那些不再使用的对象所占用的内存.java语言并不要求jvm有gc,也没有规定gc如何工作.不过常用的jvm都有gc,而且大多数gc都使用类似的算法管理内存和执行收集操作. 在充分理

young tableaus

Young tableaus  这是 Introduction_to_algorithms一个 路学校运动, 我也难倒,互联网没有找到现有的应答. 今天 python 代码贴,供你参考. #! /usr/bin/python """ young tableau m x n matrix """ import sys class element(): def __init__(self, x, y): self.x = x self.y = y d

Forever Young

Let's dance in style 让我们翩然起舞 Let's dance for a while 让我们尽情欢笑 Heaven can wait 天堂也得等著我们 We're only watching the skies 我们只是仰望凝视著天空 Hoping for the best 愿望有最好的结果 But expecting the worst 却作了最坏的打算 Are you going to drop the bomb or not 你到底是否即将要投下炸弹 Let us di