topcoder srm 595 div1
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的更多相关文章
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- topcoder srm 714 div1
problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...
- topcoder srm 738 div1 FindThePerfectTriangle(枚举)
Problem Statement You are given the ints perimeter and area. Your task is to find a triangle wi ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串
Problem Statement The Happy Letter game is played as follows: At the beginning, several players ...
- SRM 595 DIV1 250
挺简单的组合把. #include <cstdio> #include <cstring> #include <iostream> #include <vec ...
- Topcoder SRM 584 DIV1 600
思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...
- TopCoder SRM 605 DIV1
604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...
随机推荐
- 创建多线程Thread
创建一个线程: # 方式一from threading import Thread import time def func(n): time.sleep(1) print(n) t = Thread ...
- K - Popular Cows
来源poj2186 Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N ...
- Java课程课堂测试05
大致要求:将十道计算题输出至TXT文件,再读取文件至控制台,然后在控制台中输入答案并评判对错 我在大致的要求当中已经将我的设计思路体现了出来 首先,实现计算题的设计,第二步要对计算题循环,将答案存到一 ...
- Web 端自动化测试
一.环境搭建 准备工具如下:下载 python[python 开发环境](http://python.org/getit/) 下载setuptools: [python 的基础包工具](http:// ...
- arch 相关软件及脚本
安装 arch 脚本 sudo pacman -S arch-install-scripts 安装 ssh 并开启服务 sudo pacman -S open-ssh vim /etc/ssh/ss ...
- C#压缩图片时保留原始的Exif信息
啥是Exif信息,有啥用,百度百科有解释: Exif百科 总之,这东西对摄影爱好者来说是不可或缺的,通常使用Photoshop来压缩只要不是保存为Web格式都会保留Exif信息. 而我们写代码来压缩图 ...
- python全栈开发 * 26知识点汇总 * 180709
26 logging collections random 模块 一.logging低配:日志不能写入文件与显示同时进行 import logging logging.basicConfig(leve ...
- GC垃圾回收器
java与C++之间有一堵由内存动态分配和垃圾收集技术所围成的“高墙”.jvm解决的两个问题:给对象分配内存以及回收分配给对象的内存.GC:将内存中不再被使用的对象进行回收.GC的作用域是JVM运行时 ...
- Centos Linux 下Pycharm 安装
原文链接 :https://www.cnblogs.com/shaosks/p/9173806.html 可以通过浏览器访问http://www.jetbrains.com/pycharm/,选择需要 ...
- C# 让String.Contains忽略大小写
在C#里,String.Contains是大小写敏感的,所以如果要在C#里用String.Contains来判断一个string里是否包含一个某个关键字keyword,需要把这个string和这个ke ...