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

两个绿点之间的讨论:
有两种方案
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. jboss7.1.1相关error及解决办法

    问题1: 报错提示: 公司的网站系统使用的中间是jboss7.1.1 Final,由于有些数据和服务测试环境不具备,免不了要在测试环境调试些jsp页面,发现从jboss社区里下载的jboss应用有个问 ...

  2. HDU2089 不要62 BZOJ1026: [SCOI2009]windy数 [数位DP]

    基础题复习 这次用了dfs写法,感觉比较好 #include <iostream> #include <cstdio> #include <cstring> #in ...

  3. 洛谷 P3672 小清新签到题 [DP 排列]

    传送门 题意:给定自然数n.k.x,你要求出第k小的长度为n的逆序对对数为x的1~n的排列 $n \le 300, k \le 10^13$ 一下子想到hzc讲过的DP 从小到大插入,后插入不会对前插 ...

  4. 基于Spring Boot,使用JPA操作Sql Server数据库完成CRUD

    完成一个RESTful服务,提供几个访问接口,用来操作较简单的联系人信息,数据保存在Sql Server数据库中. 1.使用STS创建工程. 使用STS创建RESTful工程,可以参考: <用S ...

  5. 编译预处理命令define

    #include 包含指令 将一个源文件嵌入到当前源文件中该点处. #include<文件名>  按标准方式搜索,文件位于C++系统目录的include子目录下 #include" ...

  6. angularjs中类似textarea的换行、空格处理

    背景 今天测试人员测试出来一个显示数据的页面,没有换行. 原因剖析 这个页面是从一个<textarea>的页面拿到的数据,存到数据库中后再返回来的. 1. 知道这点之后,就有了调查方向了: ...

  7. JSP基础点滴

    注释:<%-- 注释 --%> JSP中一共有3种Scriptlet代码.支持与HTML的代码混编. 第一种:<%%>  定义局部变量,编写语句. 第二种:<%!%> ...

  8. 4、flask之分页插件的使用、添加后保留原url搜索条件、单例模式

    本篇导航: flask实现分页 添加后保留原url搜索条件 单例模式 一.flask实现分页 1.django项目中写过的分页组件 from urllib.parse import urlencode ...

  9. python3基础入门-知识点简记

    1.基础语法 编码.标识符.保留字.注释.行与缩进... 2.变量类型 (1)Python3有6个标准的数据类型: Numbers(数字)  数字数据类型用于存储数值  不可改变的数据类型 可细分为  ...

  10. CSS布局(一) 盒子模型

    一.盒子模型 标准盒子模型 从下图可以看到标准 w3c 盒子模型的范围包括 content.padding.border.margin,并且 content 部分不包含其他部分. 怪异盒子模型 从下图 ...