zoukankan      html  css  js  c++  java
  • codeforces-69A

    A. Young Physicist
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

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

    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
    这道题的大致意思是输入3列n行的数,所有列的和为0输出YES,否则输出NO。
    以下是c的代码
     1 #include<stdio.h>
     2 void main()
     3 {
     4     int a[101][3];
     5     int i, n, j;
     6     scanf("%d", &n);
     7     for (i = 0; i < n; i++)
     8         for (j = 0; j < 3; j++)
     9             scanf("%d", &a[i][j]);
    10     int sum;
    11     for (i = 0; i < 3; i++)
    12     {
    13         sum = 0;
    14         for (j = 0; j < n; j++)
    15         {
    16             sum += a[j][i];
    17         }
    18         if (sum != 0)
    19         {
    20             printf("NO
    ");
    21             i = 4;
    22             break;
    23         }
    24     }
    25     if (i == 3)
    26         printf("YES
    ");
    27 }
  • 相关阅读:
    状态模式
    maven-war-plugin 插件 web.xml 缺失时忽略
    Java远程方法协议(JRMP)
    Java Singleton的3种实现方式
    浅谈分布式消息技术 Kafka
    浅谈分布式事务
    J2EE开发时的包命名规则,养成良好的开发习惯
    使用Dom4j创建xml文档
    Java HttpClient Basic Credential 认证
    Spring MVC的Post请求参数中文乱码的原因&处理
  • 原文地址:https://www.cnblogs.com/chenruijiang/p/7795443.html
Copyright © 2011-2022 走看看