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=,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)的更多相关文章
- Codeforces 555C Case of Chocolate 其他
原文链接https://www.cnblogs.com/zhouzhendong/p/9272797.html 题目传送门 - CF555C 题意 给定一个 $n\times n(n\leq 10^9 ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- 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/ ...
- Codeforces Round #310 (Div. 1) C. Case of Chocolate (线段树)
题目地址:传送门 这题尽管是DIV1的C. . 可是挺简单的. .仅仅要用线段树分别维护一下横着和竖着的值就能够了,先离散化再维护. 每次查找最大的最小值<=tmp的点,能够直接在线段树里搜,也 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- nginx 参考文章汇总
Nginx 反向代理.负载均衡.页面缓存.URL重写及读写分离详解: http://freeloda.blog.51cto.com/2033581/1288553 Nginx开发从入门到精通: htt ...
- pm2 观察报错时 pm2 start app.js --watch
pm2 start app.js --watch[PM2][ERROR] Script already launched, add -f option to force re-execution
- [转载]C#操作符??和?:
先看如下代码: string strParam = Request.Params["param"]; if ( strParam== null ) { strParam= ...
- x86,x64,Any CPU区别
https://blog.csdn.net/zuguangboy/article/details/51509670 1,即主程序(编译出来是exe文件的)是x86平台下编译的,而它所依赖的一个项目(或 ...
- tf.placeholder使用说明
tf.placeholder(dtype, shape=None, name=None) placeholder,占位符,在tensorflow中类似于函数参数,运行时必须传入值. dtype:数据类 ...
- STM32系统时钟为什么没有定义呢
对于使用3.5版本库开发的STM32学习者 有时候不清楚为什么没有时钟定义 那么我们就简单的讲解下吧: 1,函数从启动文件开始运行(汇编文件) 2,若是hd.s 请看151行LDR R0, = ...
- fhq treap抄袭笔记
目录 碎碎念 点一下 注意!!! 模板 fhq treap 碎碎念 我咋感觉合并这么像左偏树呢 ps:难道你们的treap都是小头堆的吗 fhq真的是神人 现在看以前学的splay是有点恶心,尤其是压 ...
- Ubuntu 16.04设置IP、网关、DNS
说明:在网上给的教程上面通常会有这样的一个误导思路,按照配置文件设置后会不生效的问题,甚至没有一点效果,经过排查发现Linux下设置IP这个话题的入口线索应该分为两种:1为Server版,2为Desk ...
- redis.conf 配置 详解 中文 2.8
# redis version 2.8.19 # 1k => 1000 bytes# 1kb => 1024 bytes# 1m => 1000000 bytes# 1m ...
- Excel中Application和ApplicationClass的区别
Application和ApplicationClass的联系和区别Application和ApplicationClass都继承自接口_Application.Application为接口.Appl ...