zoukankan      html  css  js  c++  java
  • [CF555C] Case of Chocolate

    [CF555C] Case of Chocolate - map

    Description

    给定一个 (n imes n(nleq 10^9)) 的方格阵列。 接下来,我们将从该方阵的副对角线开始进行一些操作。 操作 "(y x U)" 或 "(y x L)" 分别表示一个人从第 (x) 行第 (y) 列开始走,(U) 表示向上,(L) 表示向左。保证初始位置在副对角线上面。已经有人走过的不能再走,每次操作走到不能走为止。对于每次操作,输出能走几格。

    Solution

    对于每个向上操作,答案取决于它右边的第一个已经发生的操作,如果是向上那么它们到达的位置相同,如果是向左那么只能走到这个操作对应的位置

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    #define U 'U'
    #define L 'L'
    
    const int N = 505;
    
    map<int, pair<int, int>> mp;
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        int n, q;
        cin >> n >> q;
    
        mp[0] = {0, U};
        mp[n + 1] = {0, L};
    
        while (q--)
        {
            int x, y;
            char ch;
            cin >> x >> y >> ch;
    
            auto it = mp.lower_bound(x);
            if (it->first == x)
            {
                cout << 0 << endl;
            }
            else
            {
                if (ch == L)
                    it--;
                int ans = abs(x - it->first);
                if (it->second.second == ch)
                {
                    ans += it->second.first;
                }
    
                mp[x] = {ans, ch};
                cout << ans << endl;
            }
        }
    }
    
  • 相关阅读:
    Java中的变量
    Java是什么
    leetcode 75. 颜色分类
    leetcode 283. 移动零
    剑指 Offer 65. 不用加减乘除做加法
    剑指 Offer 53
    剑指 Offer 58
    剑指 Offer 58
    剑指 Offer 57
    剑指 Offer 57. 和为s的两个数字
  • 原文地址:https://www.cnblogs.com/mollnn/p/14676672.html
Copyright © 2011-2022 走看看