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. java的方法重载

    1丶java的方法重载特性 满足以下条件的两个或多个方法构成“重载”关系:(1)方法名相同 (2)参数类型不同,参数个数不同或者参数类型的顺序不同 像System.out.println一样,就是重载 ...

  2. Coffee and Coursework (Hard Version)

    Coffee and Coursework (Hard Version) time limit per test 2.5 seconds memory limit per test 256 megab ...

  3. 伪分布式hadoop启动后jps查不到namenode的解决办法

    启动过程没有发现错误,但是jps查看进程时,发现少了NameNode,而DataNode却存在: 原因: 是端口9000已经被占用,解决办法有两个, 第一种:查找占用端口的进程,kill掉它. had ...

  4. ubuntu安装mysql-connector-python

    在安装MySQL-python时遇到报错: sudo pip install MySQL-python Traceback (most recent call last): File "&l ...

  5. java学习(二)--- 变量类型

    变量声明 type identifier [ = value][, identifier [= value] ...] ; 局部变量: 1.局部变量声明在方法.构造方法.语句块中 2.局部变量在方法. ...

  6. linux--python虚拟环境篇

    python的虚拟环境 首先我们得知道为什么要要用虚拟环境? 在使用python开发过程中,各种业务需求多了,导致工程任务多了,难免会碰到不同的工程依赖不同版本库的问题,;或者是在开发的时候不想让物理 ...

  7. H/s:哈希率单位转换

    哈系率说明 挖矿能力是通过寻找矿工可以执行的地块的尝试次数来衡量的.每次尝试都包括创建一个唯一的块候选项,并通过SHA-256d(一种加密哈希函数)创建块候选项的摘要.或者,简而言之,哈希.由于这是一 ...

  8. C和C指针小记(十八)-使用结构和指针-双向链表

    1.双链表 1.1 双向链表的声明 在一个双链表中,每个节点都包含两个指针--指向前一个节点的指针和指向后一个节点的指针. 声明 typedef struct NODE { struct NODE * ...

  9. tensorboard使用过程错误记录

    首先代码如下: def word_vis(self,file,txtname):#生成的模型存放的地址:word_vismodel'+file为新建的文件夹名 txtname是通过word2vec生成 ...

  10. 构造方法 this super

    1 构造方法 1.1 构造方法Constructor概述创建对象要明确属性值,此时需要用到构造方法,即对象创建时要执行的方法,用来给对象的属性进行初始化.在new对象时,知道其执行的构造方法是什么,就 ...