zoukankan      html  css  js  c++  java
  • 【codeforces 515A】Drazil and Date

    【题目链接】:http://codeforces.com/contest/515/problem/A

    【题意】

    每次只能走到相邻的四个格子中的一个;
    告诉你最后走到了(a,b)走了多少步->s
    (你一开始在位置(0,0)
    问你可不可能;

    【题解】

    先算出从0,0走到(a,b)的步数(最短)->temp;
    之后,如果s-temp为偶数就可行,否则不可行;
    (s< temp肯定不行);
    为偶数的话,去了可以再回来.
    没看到a,b能为负数。。

    【Number Of WA

    1

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define ps push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%lld",&x)
    #define ref(x) scanf("%lf",&x)
    
    typedef pair<int, int> pii;
    typedef pair<LL, LL> pll;
    
    const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
    const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
    const double pi = acos(-1.0);
    const int N = 110;
    
    LL a, b, s;
    
    int main()
    {
        //freopen("F:\rush.txt", "r", stdin);
        cin >> a >> b >> s;
        a = abs(a), b = abs(b);
        LL temp = a + b;
        if (s < temp) return puts("No"), 0;
        temp = s - temp;
        if (temp % 2 == 0) return puts("Yes"), 0;
        puts("No");
        //printf("
    %.2lf sec 
    ", (double)clock() / CLOCKS_PER_SEC);
        return 0;
    }
  • 相关阅读:
    结构型设计模式(上)
    创建型设计模式(下)
    创建型设计模式(上)
    HTTP 简述
    MVC、MVP与MVVM架构模式
    PHP 部分语法(二)
    PHP 部分语法(一)
    TypeScript 学习笔记(四)
    WORD 和Uint16的区别
    extern的用法
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626471.html
Copyright © 2011-2022 走看看