problem1 link

判断最后剩下哪些区间没有被其他区间覆盖。

problem2 link

假设$b$的位置固定,那么不同的$a$会使得$[a,b]$有两种情况,第一种,$[a,b]$ is nice;第二种$[a,b]$有一个后缀的连续$G$但是少于$minGreen$个。第一种情况,$[c,d]$可以任意取;第二种情况,假设$[a,b]$的后缀有$m$个‘G’,那么$[c,d]$要么is nice,要么其前缀需要有至少$minGreen-m$个连续‘G’。所以需要维护$b$之后有多少个区间is nice以及有多少区间不是nice但是有$t$个前缀‘G’的区间个数。

problem3 link

一个凸包可以划分成若干个三角形。为了计算的方便性,可以假设凸包划分三角形的方式是凸包最左下角的顶点与其他顶点连线。设$abc$是一个三角形的顶点,其中$a$是凸包左下角的顶点,那么这时候$bc$一定是凸包的一个边。所以$bc$另一测的点必然都不会出现,比$a$还左下的点也都不能出现。另外在线段$bc$上的点也都不能出现(避免重复计算)。

code for problem1

#include <vector>
#include <set> class LittleElephantAndIntervalsDiv1 {
public:
long long getNumber(int M, const std::vector<int> &L,
const std::vector<int> &R) {
std::vector<int> a(M, 0);
int n = static_cast<int>(L.size());
for (int i = 0; i < n; ++i) {
int left = L[i] - 1;
int right = R[i];
for (int j = left; j < right; ++j) {
a[j] = i + 1;
}
}
std::set<int> b;
for (int i = 0; i < M; ++i) {
if (a[i] != 0) {
b.insert(a[i]);
}
}
return 1ll << b.size();
}
};

code for problem2

#include <algorithm>
#include <string>
#include <vector> class LittleElephantAndRGB {
public:
long long getNumber(const std::vector<std::string> &list, int m) {
std::string S;
for (const auto &s : list) {
S += s;
}
int n = static_cast<int>(S.size());
std::reverse(S.begin(), S.end());
auto g = Compute(S, m);
std::reverse(S.begin(), S.end());
auto f = Compute(S, m);
long long result = 0;
std::vector<int> sum(m, 0);
long long num = 0;
for (int c = n - 1; c > 0; --c) {
{
int idx = n - 1 - c;
int p = g[idx].first;
num += g[idx].second;
int start = p >= m ? 1 : (idx - p + 1) - g[idx].second + 1; for (int j = std::min(p, m - 1); j >= 1; --j, ++start) {
sum[j] += start;
}
}
result +=
static_cast<long long>(f[c - 1].second) * (n - c + 1) * (n - c) / 2;
result += num * (c - f[c - 1].second);
if (m > 1) {
for (int j = 1; j < m && j <= f[c - 1].first; ++j) {
if (j < f[c - 1].first) {
result += sum[m - j];
} else {
result += sum[m - j] *
((c - 1 - f[c - 1].first + 1) - f[c - 1].second + 1);
}
}
}
}
return result;
} private:
std::vector<std::pair<int, int>> Compute(const std::string &s, int m) {
int n = static_cast<int>(s.size());
std::vector<std::pair<int, int>> f(n);
f[0].first = s[0] == 'G' ? 1 : 0;
f[0].second = s[0] == 'G' && m == 1 ? 1 : 0;
for (int i = 1; i < n; ++i) {
f[i].first = s[i] == 'G' ? 1 + f[i - 1].first : 0;
f[i].second = 0;
for (int j = i, c = 0; j >= 0; --j) {
c = s[j] == 'G' ? (c + 1) : 0;
if (c >= m) {
f[i].second = j + 1;
break;
}
}
}
return f;
}
};

code for problem3

#include <algorithm>
#include <vector> class Constellation {
public:
double expectation(const std::vector<int> &x, const std::vector<int> &y,
const std::vector<int> &prob) {
const int n = static_cast<int>(x.size());
std::vector<std::vector<std::vector<int>>> area(
n, std::vector<std::vector<int>>(n, std::vector<int>(n, 0)));
std::vector<int> sort_idx(n);
for (int i = 0; i < n; ++i) {
sort_idx[i] = i;
}
std::sort(sort_idx.begin(), sort_idx.end(), [&](int l, int r) {
return x[l] < x[r] || (x[l] == x[r] && y[l] < y[r]);
});
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
int dx1 = x[sort_idx[j]] - x[sort_idx[i]];
int dy1 = y[sort_idx[j]] - y[sort_idx[i]];
int dx2 = x[sort_idx[k]] - x[sort_idx[i]];
int dy2 = y[sort_idx[k]] - y[sort_idx[i]];
area[i][j][k] = dx1 * dy2 - dy1 * dx2;
}
}
}
auto Between = [&](int i, int j, int k) {
return (x[sort_idx[i]] - x[sort_idx[j]]) *
(x[sort_idx[i]] - x[sort_idx[k]]) <=
0 &&
(y[sort_idx[i]] - y[sort_idx[j]]) *
(y[sort_idx[i]] - y[sort_idx[k]]) <=
0;
}; auto Prob = [&](int i) { return prob[sort_idx[i]] / 1000.0; }; auto TotalProb = [&](int a, int b, int c) {
double p = Prob(a) * Prob(b) * Prob(c);
for (int i = 0; i < n; ++i) {
if (i == a || i == b || i == c) {
continue;
}
if (i < a || area[b][c][i] < 0 ||
(area[b][c][i] == 0 && Between(i, b, c))) {
p *= 1.0 - Prob(i);
}
}
return p;
};
double result = 0.0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
for (int k = i + 1; k < n; ++k) {
if (j != k && area[i][j][k] > 0) {
result += area[i][j][k] * 0.5 * TotalProb(i, j, k);
}
}
}
}
return result;
}
};

topcoder srm 595 div1的更多相关文章

  1. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  2. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  3. topcoder srm 714 div1

    problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...

  4. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

    Problem Statement      You are given the ints perimeter and area. Your task is to find a triangle wi ...

  5. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  6. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

    Problem Statement      The Happy Letter game is played as follows: At the beginning, several players ...

  7. SRM 595 DIV1 250

    挺简单的组合把. #include <cstdio> #include <cstring> #include <iostream> #include <vec ...

  8. Topcoder SRM 584 DIV1 600

    思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...

  9. TopCoder SRM 605 DIV1

    604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...

随机推荐

  1. C++ Addon Async 异步机制

    线程队列: libuv,window 可在libuv官网下载相应版本 opencv:  编译的时候opencv的位数要和 node的bit 一致 兼容electron :  node-gyp rebu ...

  2. pandas 基础操作 更新

    创建一个Series,同时让pandas自动生成索引列 创建一个DataFrame数据框 查看数据 数据的简单统计 数据的排序 选择数据(类似于数据库中sql语句) 另外可以使用标签来选择 通过位置获 ...

  3. vi替换字符串

    :%s/vivian/sky/g(等同于 :g/vivian/s//sky/g) 替换每一行中所有 vivian 为 sky

  4. 把项目挂载到composer上

    1.打开composer的安装包列表网站,点击submit 2.把刚才初始化了composer的项目push到github上(至于怎么push,最简单就是用git了) 3.然后把github的网址复制 ...

  5. Educational Codeforces Round 4

    612A - The Text Splitting    20171121 简单字符串处理题 #include<stdlib.h> #include<stdio.h> #inc ...

  6. 用友U8存货分类通过DataTable生成EasyUI Tree JSON

    <%@ WebHandler Language="C#" Class="InventoryClass" %> using System; using ...

  7. ubuntu14.04 LTS 更新国内网易163源

    2015/10/7 更改ubuntu的默认源是linux学习中必须掌握的基础技能.在此记录,以作参考. 在ubuntu14.04 LTS默认使用的是国外源,由于网络的原因,使用apt-get安装包时异 ...

  8. ELK之使用heartbeat监控WEB站点

    简介 无论您要测试同一台主机上的服务,还是要测试开放网络上的服务,Heartbeat 都能轻松生成运行时间数据和响应时间数据 Heartbeat 能够通过 ICMP.TCP 和 HTTP 进行 pin ...

  9. 解决 .net core 中 nuget 包版本冲突问题

    今天在一个 asp.net core 项目中遇到了 nuget 包版本冲突的问题,错误信息如下: Version conflict detected for Microsoft.AspNet.WebA ...

  10. The way to unwind the stack on Linux EABI

    I. probe the stack frame structure The original idea is to unwind the function call stack according ...