先按照绿点进行分块
第一个绿点和最后一个绿点之后很好处理不说了

两个绿点之间的讨论:
有两种方案
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的更多相关文章

  1. Good Bye 2017 A B C

    Good Bye 2017 A New Year and Counting Cards 题目链接: http://codeforces.com/contest/908/problem/A 思路: 如果 ...

  2. Good Bye 2017 部分题解

    D. New Year and Arbitrary Arrangement 分析 \(dp[i][j]\) 表示已有 \(i\) 个 \(a\) 和 \(j\) 个 \(ab\) 的情况下继续构造能得 ...

  3. [Codeforces]Good Bye 2017

    A - New Year and Counting Cards #pragma comment(linker, "/STACK:102400000,102400000") #inc ...

  4. 【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 ...

  5. 【CodeForces】908 E. New Year and Entity Enumeration

    [题目]E. New Year and Entity Enumeration [题意]给定集合T包含n个m长二进制数,要求包含集合T且满足以下条件的集合S数:长度<=m,非和与的结果都在集合中. ...

  6. Hello 2018, Bye 2017

    2017年过去了,过去一年经历了太多,改变了好多好多,可以说人生进入了另一个阶段,有可能是成熟吧. 回顾2017 去年换了新工作,离开了将近工作了8年的公司,不带走一丝云彩,为其任劳任怨,最后没有任何 ...

  7. Good Bye 2017(送命场)

    9815人数场,9500+围观神仙打架...断断续续打Codeforces也快有一年啦,第一次打Good Bye场,满怀前排膜tourist的心愿参加了这场送命场,虽然没看到tourist.不过还是得 ...

  8. 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 时加一 ...

  9. 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 ...

随机推荐

  1. CentOS7修改SSH远程连接端口

      CentOS7修改SSH远程连接端口              

  2. Linux history命令

    history命令主要用于显示历史命令, 重新执行历史命令. Linux系统当你在shell(控制台)中输入并执行命令时,shell会自动把你的命令记录到历史列表中,一般保存在用户目录下的.bash_ ...

  3. Shell与脚本

    shell是Linux操作系统的用户接口,我们经常需要编写脚本让操作系统自动执行一系列指令的需求,本文将简单介绍开发shell脚本的所需的语言特性. shell脚本是指令序列,其指令可以直接在终端中执 ...

  4. trie 树 模板

    #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> ...

  5. bzoj 4871: [Shoi2017]摧毁“树状图” [树形DP]

    4871: [Shoi2017]摧毁"树状图" 题意:一颗无向树,选两条边不重复的路径,删去选择的点和路径剩下一些cc,求最多cc数. update 5.1 : 刚刚发现bzoj上 ...

  6. BZOJ 4004: [JLOI2015]装备购买 [高斯消元同余 线性基]

    和前两(一)题一样,不过不是异或方程组了..... 然后bzoj的新数据是用来卡精度的吧..... 所有只好在模意义下做啦 只是巨慢无比 #include <iostream> #incl ...

  7. Ubuntu下的Samba服务器配置

    一. samba的安装: sudo apt-get insall samba 二. 创建共享目录: mkdir /home/phinecos/share sodu chmod 777 /home/ge ...

  8. LeetCode - 626. Exchange Seats

    Mary is a teacher in a middle school and she has a table seat storing students' names and their corr ...

  9. linux下LAMP环境的搭配

    之前电脑上换了ubuntu16.04,本地需要重新配置,但是忘得一干二净,所以重新配置了一下,并再此记录一下. 安装apache: sudo apt-get install apache2 重启apa ...

  10. Java经典编程题50道之十九

    打印出如下图案(菱形)        *      ***    ******  ********    ******      ***        * public class Example19 ...