题意:直角边为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. Android (Android Studio)无法启动adb 解决方案

    打开cmd 输入:     netstat -aon|findstr "5037"      回车  taskkill /pid xxxx /f     ps:xxxx为占用端口 ...

  2. quartz开源作业调度框架的配置

    quartz开源作业调度框架的job服务实现,Quartz是一个完全由java编写的开源作业调度框架,使用时候需要创建一个实现org.quartz.Job接口的java类,Job接口包含唯一的方法: ...

  3. linux测试带宽命令,Linux服务器网络带宽测试iperf

    linux测试带宽命令,Linux服务器网络带宽测试iperf必须先运行iperf serveriperf -s -i 2客户端iperf -c 服务端IP地址 iperf原理解析 iperf工具可以 ...

  4. 使用Astah画UML类图经验总结

    从学习需求工程与UML开始,就开始接触到Astah这款软件,但是当时完全是为了对UML各种图的了解加深才使用了这款软件.当时画图,都是完全凭借自己想,并没有考虑实际情况,而且画的图都是很简单的,甚至有 ...

  5. 安全测试工具之Burpsuite

    端口即服务,每一个服务对应一个或多个端口.端口扫描即通过一些方法检测到一台主机的一段特定端口是否提供相应的服务.利用这些扫描结果,正常用户可以访问系统所提供的服务,而黑客却可以利用这些服务中的漏洞对系 ...

  6. Python3 判断文件和文件夹是否存在、创建文件夹

    Python3 判断文件和文件夹是否存在.创建文件夹 python中对文件.文件夹的操作需要涉及到os模块和shutil模块. 创建文件: 1) os.mknod(“test.txt”) 创建空文件  ...

  7. VIM 使用心得

    序 到百度外卖任职以后,发现在我们部门无论 mac 还是 windows,程序员们清一色地都在使用 VIM 来编辑代码,期间穿插着各种插件.快捷键.眼花缭乱的命令.我在大学时只会极少的 VIM 命令, ...

  8. QTQuick控件基础(1)

    一.Item QtQuick所有的可视项目都继承自Item,它定义了可视化项目所有通用特性(x\y\width\height\anchors等)具体包括 1.作为容器 2.不透明性 没有设置opaci ...

  9. Python3基础 if elif 示例 判断一个数在哪个区间内

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. LightOJ 1199 Partitioning Game(sg函数)题解

    题意:可以把一堆石子分成不相等的两堆,不能操作为败 思路:把一个石子拆成两个,变成了两个独立的游戏,mex里加上两者的sg异或.sg打表. 代码: #include<set> #inclu ...