Good Bye 2017 E. New Year and Entity Enumeration
先按照绿点进行分块
第一个绿点和最后一个绿点之后很好处理不说了
两个绿点之间的讨论:
有两种方案
1:红(蓝)点和绿点顺序连接,距离为相邻绿点距离(也就是双倍绿点距离)
2:红(蓝)点和绿点的点阵中寻找最大的距离边,不连这一条,其他都顺序连,当然这样不连通,最后再绿点连接。(一个绿点距离+红(蓝)点阵处理 可以看到样例就是这样做的)
#include<iostream>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 3e5+5;
#define MS(x,y) memset(x,y,sizeof(x))
#define MP(x, y) make_pair(x, y)
int dis[N]; int color[N];
vector<int> so;
int main() {
int n;
while(~scanf("%d", &n)) {
so.clear();
for(int i = 0; i < n; ++i) {
int a; char b[10];
scanf("%d %s", &a, b);
dis[i] = a;
color[i] = b[0]=='G'? 3 : (b[0]=='R'? 1:2);
}
int ans = 0;
for(int i = 0; i < n; ++i) {
if(color[i] == 3) {
so.push_back(i);
}
}
if(so.empty()) {
int st = -1, ed = 0;
for(int i = 0; i < n; ++i) {
if(color[i] == 1 && st == -1) st = i;
if(color[i] == 1) ed = i;
}
if(st != -1) ans += dis[ed] - dis[st];
st = -1; ed = 0;
for(int i = 0; i < n; ++i) {
if(color[i] == 2 && st == -1) st = i;
if(color[i] == 2) ed = i;
}
if(st != -1) ans += dis[ed] - dis[st];
printf("%d\n", ans);
continue;
}
//1
for(int i = 0; i < so[0]; ++i) {
if(color[i] == 1) {
ans += dis[so[0]] - dis[i]; break;
}
}
for(int i = 0; i < so[0]; ++i) {
if(color[i] == 2) {
ans += dis[so[0]] - dis[i]; break;
}
}
//2
for(int i = 0; i <= so.size()-2; ++i) {
int len = dis[so[i+1]] - dis[so[i]];
int tt = 0;
int maxx = 0; int pre = so[i];
for(int j = so[i] + 1; j <= so[i+1]; ++j) {
if(color[j] != 1 ) {
// printf("%d\n", j);
maxx = max(maxx, dis[j] - dis[pre]);
pre = j;
}
}
tt += dis[so[i + 1]] - dis[so[i]] - maxx;
maxx = 0; pre = so[i];
for(int j = so[i] + 1; j <= so[i+1]; ++j) {
if(color[j] != 2) {
maxx = max(maxx, dis[j] - dis[pre]);
pre = j;
}
}
tt += dis[so[i + 1]] - dis[so[i]] - maxx;
if(tt > len) tt = len;
tt += len;
ans += tt;
}
//3
for(int i = n-1; i > so[so.size()-1]; --i) {
if(color[i] == 1) {
ans += dis[i] - dis[so[so.size()-1]]; break;
}
}
for(int i = n-1; i > so[so.size()-1]; --i) {
if(color[i] == 2) {
ans += dis[i] - dis[so[so.size()-1]]; break;
}
}
printf("%d\n", ans);
}
return 0;
}
Good Bye 2017 E. New Year and Entity Enumeration的更多相关文章
- Good Bye 2017 A B C
Good Bye 2017 A New Year and Counting Cards 题目链接: http://codeforces.com/contest/908/problem/A 思路: 如果 ...
- Good Bye 2017 部分题解
D. New Year and Arbitrary Arrangement 分析 \(dp[i][j]\) 表示已有 \(i\) 个 \(a\) 和 \(j\) 个 \(ab\) 的情况下继续构造能得 ...
- [Codeforces]Good Bye 2017
A - New Year and Counting Cards #pragma comment(linker, "/STACK:102400000,102400000") #inc ...
- 【CF908E】New Year and Entity Enumeration 位运算+DP
[CF908E]New Year and Entity Enumeration 题意:给定$M=2^m-1$,我们称一个集合S是好的,当且仅当它满足:1.$\forall a\in S,a\ \ma ...
- 【CodeForces】908 E. New Year and Entity Enumeration
[题目]E. New Year and Entity Enumeration [题意]给定集合T包含n个m长二进制数,要求包含集合T且满足以下条件的集合S数:长度<=m,非和与的结果都在集合中. ...
- Hello 2018, Bye 2017
2017年过去了,过去一年经历了太多,改变了好多好多,可以说人生进入了另一个阶段,有可能是成熟吧. 回顾2017 去年换了新工作,离开了将近工作了8年的公司,不带走一丝云彩,为其任劳任怨,最后没有任何 ...
- Good Bye 2017(送命场)
9815人数场,9500+围观神仙打架...断断续续打Codeforces也快有一年啦,第一次打Good Bye场,满怀前排膜tourist的心愿参加了这场送命场,虽然没看到tourist.不过还是得 ...
- Good Bye 2017 D. New Year and Arbitrary Arrangement
看了别人的题解 首先这题是一个dp dp[i][j] i是当前有多少个a j是当前有多少个ab子序列 dp[i][j] = dp[i+1][j]*Pa + dp[i][i+j]*Pb; i,j 时加一 ...
- Good Bye 2017 G. New Year and Original Order
G. New Year and Original Order time limit per test 2 seconds memory limit per test 256 megabytes inp ...
随机推荐
- [Sdoi2017]新生舞会 [01分数规划 二分图最大权匹配]
[Sdoi2017]新生舞会 题意:沙茶01分数规划 貌似\(*10^7\)变成整数更科学 #include <iostream> #include <cstdio> #inc ...
- ZOJ 3229 Shoot the Bullet [上下界最大流]
ZOJ 3229 Shoot the Bullet 题意:此生无悔入东方 上下界最大流 spj挂掉了我也不知道对不对,把代码放这里吧以后正常了可能会评测一下 #include <iostream ...
- BZOJ 1176: [Balkan2007]Mokia [CDQ分治]
题意: 有一个n * n的棋盘,每个格子内有一个数,初始的时候全部为0.现在要求维护两种操作: 1)Add:将格子(x, y)内的数加上A. 2)Query:询问矩阵(x0, y0, x1, y1)内 ...
- 用UltraISO制作CentOS U盘安装盘
1 下载UltraISO 网上有很多版本,下个绿色版的就ok了. 下载地址:http://www.pc6.com//softview/SoftView_13698.html 2 下载Cen ...
- 隱藏在素數規律中的Pi -- BZOJ1041解題報告
退役狗在刷程書的過程中看到了一個有趣的視頻, 講解了一個有趣的問題. 在網上隨便搜索了一下居然還真的找到了一道以它爲背景的OI題目, BZOJ1041. 下面的內容會首先回顧一下視頻所討論的知識, 有 ...
- cisco模拟器GNS3和虚拟机VMware的整合
微软和思科环境: 在思科认证的学习中,我们需要用到许多类的模拟器,但这些模拟器并不能够更真实的模拟我们的用户机在应用中所出现的现象.因此,我们借由微软的环境来更真实地体现我们所搭建的网络中的一些应用. ...
- centos 配置 php 执行shell的权限
在执行特定的shell命令,如 kill,killall 等需要配置root权限 php脚本运行在apache服务器下 可以看到 httpd 是以 apache 用户执行的 看一下 该用户信息 现在 ...
- SQL SERVER FOR LINUX初体验
今天得空,就在Ubuntu17.04上安装了SQL SERVER 2017体验下,总体来说还是不错的. 在Ubuntu上安装SQL SERVER 2017还是比较方便的,只需几条命令即可: curl ...
- session垃圾回收机制
主要有以下三个参数 session.gc_maxlifetime:session生命周期 session.gc-devisor:启动session回收机制频率的被除数(分母) session.gc_p ...
- HTML5VEDIO标签阿里云-微信浏览器兼容性问题
在网页展示媒体对象,离不开HTML5的 audio和video对象.但这两个目前来看兼容性方面还得关注一下. 目前在做一个阿里云下载video 并在微信端播放mp4格式的视频的时候,碰到了一些兼容性问 ...