zoukankan      html  css  js  c++  java
  • D. Anton and Chess 模拟题 + 读题

    http://codeforces.com/contest/734/problem/D

    一开始的时候看不懂题目,以为象是中国象棋那样走,然后看不懂样例。

    原来是走对角线的,长知识了。

    所以我们就知道,王有八个方向,所以每个方向选一个来做代表就行了。

    那么选谁呢?可以排序,按照他们离王的距离从小到大排,这样就能选出最近的那个(不用被棋挡住)

    然后注意下方向的表达,在王的右上角,还要和王在同一对角线才行~不能简单地判x和y的大小关系

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    const int maxn = 500000 + 20;
    LL xx0, yy0;
    struct node {
        char ch;
        LL x, y;
        node() {}
        node(char cc, LL xx, LL yy) : ch(cc), x(xx), y(yy) {}
        bool operator < (const struct node & rhs) const {
            LL dis = (x - xx0) * (x - xx0) + (y - yy0) * (y - yy0);
            LL dis2 = (rhs.x - xx0) * (rhs.x - xx0) + (rhs.y - yy0) * (rhs.y - yy0);
            return dis < dis2;
        }
    }arr[maxn];
    vector<struct node>pos[66];
    void work() {
        IOS;
        int n;
        cin >> n;
        cin >> xx0 >> yy0;
        for (int i = 1; i <= n; ++i) {
            char str[11];
            cin >> str;
            arr[i].ch = str[0];
            cin >> arr[i].x >> arr[i].y;
        }
        sort(arr + 1, arr + 1 + n);
    //    for (int i = 1; i <= n; ++i) {
    //        cout << arr[i].ch << " " << arr[i].x << " " << arr[i].y << endl;
    //    }
        for (int i = 1; i <= n; ++i) {
            int face = 0;
            if (arr[i].x == xx0 && arr[i].y > yy0) face = 1;
            else if (arr[i].x < xx0 && arr[i].y > yy0 && arr[i].x + arr[i].y == xx0 + yy0) face = 2;
            else if (arr[i].y == yy0 && arr[i].x < xx0) face = 3;
            else if (arr[i].x < xx0 && arr[i].y < yy0 && arr[i].x - arr[i].y == xx0 - yy0) face = 4;
            else if (arr[i].x == xx0 && arr[i].y < yy0) face = 5;
            else if (arr[i].x > xx0 && arr[i].y < yy0 && arr[i].x + arr[i].y == xx0 + yy0) face = 6;
            else if (arr[i].y == yy0 && arr[i].x > xx0) face = 7;
            else if (arr[i].x > xx0 && arr[i].y > yy0 && arr[i].x - arr[i].y == xx0 - yy0) face = 8;
            if (pos[face].size() != 0) continue;
            pos[face].push_back(arr[i]);
        }
    //    cout << "fff" << endl;
        for (int i = 1; i <= 8; ++i) {
            if ((i == 1 || i == 5) && pos[i].size() && (pos[i][0].ch == 'Q' || pos[i][0].ch == 'R')) {
                printf("YES
    ");
                return;
            } else if ((i == 2 || i == 6) && pos[i].size() && (pos[i][0].ch == 'Q' || pos[i][0].ch == 'B')) {
                printf("YES
    ");
                return;
            } else if ((i == 3 || i == 7) && pos[i].size() && (pos[i][0].ch == 'Q' || pos[i][0].ch == 'R')) {
                printf("YES
    ");
                return;
            } else if ((i == 4 || i == 8) && pos[i].size() && (pos[i][0].ch == 'B' || pos[i][0].ch == 'Q')) {
                printf("YES
    ");
                return;
            }
        }
        printf("NO
    ");
    }
    
    int main() {
    #ifdef local
        freopen("data.txt","r",stdin);
    #endif
        work();
        return 0;
    }
    View Code
  • 相关阅读:
    BZOJ1001 狼抓兔子 终于过了!
    BZOJ 1901: Zju2112 Dynamic Rankings( 树状数组套主席树 )
    BZOJ 2302: [HAOI2011]Problem c( dp )
    BZOJ 1407: [Noi2002]Savage( 数论 )
    BZOJ 2661: [BeiJing wc2012]连连看( 费用流 )
    BZOJ 1021: [SHOI2008]Debt 循环的债务( dp )
    BZOJ 3170: [Tjoi 2013]松鼠聚会( sort )
    BZOJ 2301: [HAOI2011]Problem b( 数论 )
    BZOJ 2434: [Noi2011]阿狸的打字机( AC自动机 + DFS序 + 树状数组 )
    BZOJ 3231: [Sdoi2008]递归数列( 矩阵快速幂 )
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6068366.html
Copyright © 2011-2022 走看看