codeforces 555c// Case of Chocolate// Codeforces Round #310(Div. 1)

题意:直角边为n的网格巧克力,一格为一块,选择斜边上一点,从左或上吃,直到吃到空气,称为一次操作。给出几个操作,问各能吃几块。如果x是当前要吃的横坐标,在已经吃过的中找x1>=x的第一个x1,即lower_bound()。如果x1==x,结果就是0;否则假设x是往上吃,x1也是往上吃,因为x和x1间没有往左吃的,因此x1结束的地方也是x结束的地方。如果x往上吃,x1往左吃,因为x1横坐标最小,纵坐标最大,对x能吃到的位置仅受到它的影响。

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000") 
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=1000010,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-9;
struct nd{
    char drc;
    int res;
    int x,y;
    nd(char a,int b,int _x,int _y):drc(a),res(b),x(_x),y(_y){}
};

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin); 
    int n,m;
    cin>>n>>m;
    map<int,nd> mp;
    for(int i=0;i<m;++i)
    {
        int x,y;
        char drc;
        cin>>x>>y>>drc;
        if(i==0)
        {
            int res=0;
            if(drc=='U')
            {
                res=y;
            }
            else res=x;
            cout<<res<<endl;
            mp.insert(make_pair(x,nd(drc,res,x,y)));
        }
        else
        {
            int res=0;
            if(drc=='U')
            {
                auto it=mp.lower_bound(x);
                if(it->first==x)res=0;
                else if(it==mp.end())res=y;
                else if(it->second.drc=='U')
                {
                    res=y-it->second.y+it->second.res;
                }
                else
                {
                    res=y-it->second.y;
                }
            }
            else
            {
                auto it=mp.lower_bound(x);
                if(it==mp.end())
                {
                    --it;
                    if(it->second.drc=='U')res=x-it->second.x;
                    else res=x-it->second.x+it->second.res;
                }
                else if(it->first!=x)
                {
                    if(it==mp.begin())res=x;
                    else
                    {
                        --it;
                        if(it->second.drc=='U')res=x-it->second.x;
                        else res=x-it->second.x+it->second.res;
                    }
                }
                else
                {res=0;
//                    if(it->second.drc=='U')res=x-it->second.x;
//                    else res=x-it->second.x+it->second.res;
                }
            }
            mp.insert(make_pair(x,nd(drc,res,x,y)));
            cout<<res<<endl;
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/gaudar/p/9672689.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值