题意:直角边为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=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-;
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();
//freopen("d:\\1.txt","r",stdin);
int n,m;
cin>>n>>m;
map<int,nd> mp;
for(int i=;i<m;++i)
{
int x,y;
char drc;
cin>>x>>y>>drc;
if(i==)
{
int res=;
if(drc=='U')
{
res=y;
}
else res=x;
cout<<res<<endl;
mp.insert(make_pair(x,nd(drc,res,x,y)));
}
else
{
int res=;
if(drc=='U')
{
auto it=mp.lower_bound(x);
if(it->first==x)res=;
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=;
// 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 ;
}

codeforces 555c// Case of Chocolate// Codeforces Round #310(Div. 1)的更多相关文章

  1. Codeforces 555C Case of Chocolate 其他

    原文链接https://www.cnblogs.com/zhouzhendong/p/9272797.html 题目传送门 - CF555C 题意 给定一个 $n\times n(n\leq 10^9 ...

  2. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  3. 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

  4. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  5. Codeforces Round #310 (Div. 1) C. Case of Chocolate set

    C. Case of Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/ ...

  6. Codeforces Round #310 (Div. 1) C. Case of Chocolate (线段树)

    题目地址:传送门 这题尽管是DIV1的C. . 可是挺简单的. .仅仅要用线段树分别维护一下横着和竖着的值就能够了,先离散化再维护. 每次查找最大的最小值<=tmp的点,能够直接在线段树里搜,也 ...

  7. Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题

    B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  8. Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题

    A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  9. Codeforces Round #310 (Div. 1) B. Case of Fugitive set

    B. Case of Fugitive Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/p ...

随机推荐

  1. python管道pipe,两个进程,使用管道的两端分别执行写文件动作,带锁(lock)

    #coding=utf-8import multiprocessing as mp def write_file(content,lock):    lock.acquire()    with op ...

  2. python基础七--集合

    12.221.昨日内容回顾 小数据池: int:-5--256 str:1.不能有特殊字符 2.*int不能超过20 编码:所能看到的最小构成单位叫字符 ascii : 8位 1字节 表示1个字符 u ...

  3. SNMP学习笔记之iReasoning MIB Browser

    0x00 MIB Browser iReasoning MIB浏览器是一个强大和易于使用的工具由iReasoning SNMP API提供支持. MIB浏览器是工程师管理启用SNMP的网络设备和应用程 ...

  4. Confluence5.8部分空间名称显示为问号的解决方案

    Confluence5.8部分空间名称显示为问号的解决方案 原因: 连接MySQL的时候,有没有在连接串中指定&useUnicode=true&characterEncoding=ut ...

  5. centos 安装最新稳定版本docker

    直接yum安装的docker版本是 : docker --versionDocker version 1.12.6, build 85d7426/1.12.6 一些新特性需要安装最新的稳定版本 国内可 ...

  6. 20162311 解读同伴的收获&解决同伴的问题(11月29日,周三)

    20162311 解读同伴的收获&解决同伴的问题(11月29日,周三) 解读同伴的收获 我的同组同学是20162325学号金立清同学 同组同学的收获是:递归算法的非递归实现.分治法.动态规划法 ...

  7. linux平台关闭某个进程的脚本

    在开发LINUX平台下的程序时,经常需要为我们的开发的程序写启动程序和关闭程序的脚本. 启动脚本比较好做,关闭程序脚本如下: 具体思路是通过ps命令找到程序的进程ID号,然后通过Kill命令将程序Ki ...

  8. Asp.net简单概念知识

    1. 简述 private. protected. public. internal 修饰符的访问权限.答 . private :   私有成员, 在类的内部才可以访问.      protected ...

  9. BZOJ1355: [Baltic2009]Radio Transmission KMP

    Description 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. Input 第一行给出字符串的长度,1 < L ≤ 1, ...

  10. sql server 存储过程 procedure

    https://www.cnblogs.com/selene/p/4483612.html