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 ...
随机推荐
- 持续集成之三:搭建Maven私服Nexus
安装环境 Red Hat Enterprise Linux Server release 7.3 (Maipo) jdk1.7.0_80 apache-tomcat-7.0.90 mysql-5.7. ...
- 2018-2019-2 20165209 《网络对抗技术》Exp7: 网络欺诈防范
2018-2019-2 20165209 <网络对抗技术>Exp7: 网络欺诈防范 1 基础问题回答和实验内容 1.1基础问题回答 (1)通常在什么场景下容易受到DNS spoof攻击. ...
- ping和telnet的区别
内容主要转自: http://jingyan.baidu.com/article/8065f87fc3b31123312498e5.html http://zhidao.baidu.com/link? ...
- 浅谈elasticsearch 集群
elasticsearch 集群 摘要: elasticsearch 集群 搭建elasticsearch的集群 现在假设我们有3台es机器,想要把他们搭建成为一个集群 基本配置 每个节点都要进行这样 ...
- NFS常用命令
1.客户端查看服务端可挂载卷 showmount -t 服务端IP 2.不重启加载NFS配置文件 exportfs -avr
- TI 实时操作系统SYS/BIOS使用总结
1:概述: SYS/BIOS 是一个可扩展的实时的操作系统.具有非常快速的响应时间(在中断和任务切换时达到较短的延迟),响应时间的确定性,强壮的抢占系统,优化的内存分配和堆栈管理(尽量少的消耗和碎片) ...
- C# 取form表单的数据
//key代表form表单中html元素的name属性值 public static string StringForm(string key) { string result = null; res ...
- 【前端】Vue.js实现网格列表布局转换
网格列表布局转换 实现效果: 实现代码及注释: <!DOCTYPE html> <html> <head> <title>布局转换</title& ...
- Ubuntu 16.04设置IP、网关、DNS
说明:在网上给的教程上面通常会有这样的一个误导思路,按照配置文件设置后会不生效的问题,甚至没有一点效果,经过排查发现Linux下设置IP这个话题的入口线索应该分为两种:1为Server版,2为Desk ...
- BZOJ 5424: 烧桥计划
BZOJ 5424: 烧桥计划 目前暂居rk1QAQ 首先,设\(f[i][k]\)为前i个点中,选了第i个点,总共选了k个点的答案.那么就有: \[f[i][k]=min_{j<i}\{f[j ...