zoukankan      html  css  js  c++  java
  • acm寒假特辑 1月17日 CodeForces

    B - 2 CodeForces - 69A

    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.

    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

    题目大意:受力平衡(向量相加为0)
    思路:x,y,z轴各自相加总和为0;

    //miku saiko
    #include<iostream>
    using namespace std;
    int main()
    {
    	int n, a[105][3], sumx = 0,sumy = 0, sumz = 0;
    	cin >> n;
    	for (int i=0;i<n;i++)
    	{
    		for (int j=0;j<3;j++)
    		{
    			cin >> a[i][j];
    		}
    	}
    	for (int i=0;i<n;i++)
    	{
    		sumx += a[i][0]; sumy += a[i][1]; sumz += a[i][2];
    	}
    	if (sumx == 0 && sumy == 0 && sumz == 0)
    	{
    		cout << "YES" << endl;
    	}
    	else
    		cout << "NO" << endl;
        return 0;
    }
    
  • 相关阅读:
    养花
    【bzoj1419】Red is good
    C++模板
    逆元求组合数
    【IOI2000】【洛谷1435】回文字串
    Centos 下启动mysql 报错: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)解决方法
    linux系统下进行安装phpMyAdmin(基于Centos)
    达梦数据的安装(Windows10 、linux环境下、麒麟系统下)
    2020-3-3 链表刷题(203. 移除链表元素)
    2020-02-03 刷题
  • 原文地址:https://www.cnblogs.com/gidear/p/10433285.html
Copyright © 2011-2022 走看看