zoukankan      html  css  js  c++  java
  • A. Drazil and Date

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0, 0) and Varda's home is located in point (a, b). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (x, y) he can go to positions (x + 1, y), (x - 1, y), (x, y + 1) or (x, y - 1).

    Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (a, b) and continue travelling.

    Luckily, Drazil arrived to the position (a, b) successfully. Drazil said to Varda: "It took me exactly s steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0, 0) to (a, b) in exactly s steps. Can you find out if it is possible for Varda?

    Input

    You are given three integers a, b, and s ( - 109 ≤ a, b ≤ 109, 1 ≤ s ≤ 2·109) in a single line.

    Output

    If you think Drazil made a mistake and it is impossible to take exactly s steps and get from his home to Varda's home, print "No" (without quotes).

    Otherwise, print "Yes".

    Sample test(s)
    Input
    5 5 11
    Output
    No
    Input
    10 15 25
    Output
    Yes
    Input
    0 5 1
    Output
    No
    Input
    0 0 2
    Output
    Yes
    Note

    In fourth sample case one possible route is: .

    题意:给出坐标和步数 判断在使用完所有步数时能否到达指定

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<cmath>
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int x,y,s;
    10     cin>>x>>y>>s;
    11     if(abs(x)+abs(y)<=s&&(int)(s-abs(x)-abs(y))%2==0) cout<<"Yes"<<endl;
    12     else cout<<"No"<<endl;
    13 }

    坐标点

    分析:上下左右每次只行走一个单位 那么到达指定坐标(x,y)的最小距离一定为|x|+|y| 此时如果步数s小于则一定到不了,如果大于并且多余的步数是2的倍数则一定能准确到达;

  • 相关阅读:
    【Apollo】Apollo 分布式部署
    【Spring】SpringBatch快速入门
    Nacos、Apollo、Spring Cloud Config微服务配置中心对比
    IDEA或Android Studio用书签功能标识代码 Stars
    Jetpack架构组件学习(0)——总结篇 Stars
    Android Studio导出APP的数据库db文件 Stars
    Jetpack架构组件学习(1)——LifeCycle的使用 Stars
    JavaFx Tooltip悬浮提示使用及自定义 Stars
    JavaFx WebView使用研究 Stars
    Jetpack架构组件学习(2)——ViewModel和Livedata使用 Stars
  • 原文地址:https://www.cnblogs.com/wsaaaaa/p/4295855.html
Copyright © 2011-2022 走看看