problem1 link

$f[u][0],f[u][1]$表示$u$节点表示的子树去掉和不去掉节点$u$的最大权值。

problem2 link

首先预处理计算任意三个蓝点组成的三角形中的蓝点个数以及是否包含红点。凸包可以分割成三角形。首先初始化凸包的三个顶点为$x,y,z$(假设$x,y,z$是逆时针),然后每次增加一个新的点进来,设最后加入凸包的两个点为$p_{1},p_{2}$,新加入的点为$q$,那么$q$需要满足的条件为:

(1)三角形$x,p_{2},q$中没有红点;

(2)$q$在射线$x,p_{2}$的左侧;

(3)$q$在射线$p_{1},p_{2}$的左侧;

(4)$q$在射线$x,y$的左侧.

这样进行动态规划即可。

problem3 link

令$s(i,j)=\sum_{0\leq k <m}count(i,k)[isGood_{j+k}]$,表示某个$bag$中取出的数字为$j$时,$bag$$i$中那些可以与$j$组成$good$的数字的方案数。

那么答案为$answer=\sum_{0\leq t<n}\sum_{0\leq j<m}count(t,j)\left (\sum_{t<i<n}s(i,j)  \right )$

code for problem1

#include <algorithm>
#include <stack>
#include <vector> class FiringEmployees {
public:
int fire(const std::vector<int> &manager, const std::vector<int> &salary,
const std::vector<int> &productivity) {
int n = static_cast<int>(manager.size());
std::vector<std::vector<int>> g(n + 1);
std::vector<int> a(n + 1);
std::vector<int> f0(n + 1);
std::vector<int> f1(n + 1);
for (int i = 0; i < n; ++i) {
g[manager[i]].push_back(i + 1);
}
for (int i = 1; i <= n; ++i) {
f1[i] = a[i] = productivity[i - 1] - salary[i - 1];
}
std::stack<std::pair<int, int>> st;
st.push({0, 0});
while (!st.empty()) {
int u = st.top().first;
int tag = st.top().second;
st.pop();
if (tag == 1) {
for (auto son : g[u]) {
f1[u] += std::max(f0[son], f1[son]);
}
} else {
st.push({u, 1});
for (auto son : g[u]) {
st.push({son, 0});
}
}
}
return f1[0];
}
};

code for problem2

#include <algorithm>
#include <cstring>
#include <queue>
#include <vector> namespace geometry { struct Point {
double x, y; Point(double x = 0.0, double y = 0.0) : x(x), y(y) {} Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); } Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); }
double operator*(const Point &a) const { return x * a.y - y * a.x; } double operator^(const Point &a) const { return x * a.x + y * a.y; }
Point operator*(double t) const { return Point(x * t, y * t); }
Point operator/(double t) const { return Point(x / t, y / t); }
}; int SGN(double x) {
constexpr double kEpslion = 1e-12;
if (x > kEpslion) {
return 1;
}
if (x < -kEpslion) {
return -1;
}
return 0;
} double Cross(const Point &a, const Point &b, const Point &p) {
return (b - a) * (p - a);
} bool Left(const Point &a, const Point &b, const Point &p) {
return ((b - a) * (p - a)) > 0;
} double Area(const Point &a, const Point &b, const Point &c) {
return std::fabs(Cross(a, b, c)) * 0.5;
} bool Inside(const Point &a, const Point &b, const Point &c, const Point &d) {
double s1 = Area(a, b, c);
double s2 = Area(a, b, d) + Area(a, c, d) + Area(b, c, d);
return SGN(s1 - s2) == 0;
} } // namespace geometry const int N = 50;
bool tag[N][N][N];
int f[N][N][N];
bool inque[N][N][N];
int g[N][N][N]; class RedAndBluePoints {
public:
int find(const std::vector<int> &blueX, const std::vector<int> &blueY,
const std::vector<int> &redX, const std::vector<int> &redY) {
int n = static_cast<int>(blueX.size());
if (n <= 2) {
return n;
}
std::vector<geometry::Point> p(n);
for (int i = 0; i < n; ++i) {
p[i] = geometry::Point(blueX[i], blueY[i]);
}
int m = static_cast<int>(redX.size());
std::vector<geometry::Point> q(m);
for (int i = 0; i < m; ++i) {
q[i] = geometry::Point(redX[i], redY[i]);
} auto Cal = [&](const geometry::Point &a, const geometry::Point &b,
const geometry::Point &c) {
for (int i = 0; i < m; ++i) {
if (geometry::Inside(a, b, c, q[i])) {
return true;
}
}
return false;
}; for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
if (i != j && i != k && j != k) {
tag[i][j][k] = Cal(p[i], p[j], p[k]);
for (int t = 0; t < n; ++t) {
if (t != i && t != j && t != k &&
geometry::Inside(p[i], p[j], p[k], p[t])) {
++g[i][j][k];
}
}
}
}
}
} int result = 2;
for (int i = 0; i < n; ++i) {
result = std::max(result, Get(i, p));
}
return result;
} private:
int Get(int x, const std::vector<geometry::Point> &p) {
int n = static_cast<int>(p.size()); struct Node {
int i, j, t, cnt; Node() = default;
Node(int i, int j, int t, int cnt) : i(i), j(j), t(t), cnt(cnt) {}
}; memset(f, 0, sizeof(f));
memset(inque, 0, sizeof(inque)); std::queue<Node> que;
int result = 0; for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != x && i != j && j != x && !tag[x][i][j] &&
geometry::Left(p[x], p[i], p[j])) {
f[i][i][j] = 3 + g[x][i][j];
result = std::max(result, f[i][i][j]);
inque[i][i][j] = true;
que.push(Node(i, j, i, f[i][i][j]));
}
}
}
while (!que.empty()) {
Node node = que.front();
que.pop();
int y = node.t;
int p1 = node.i;
int p2 = node.j;
inque[y][p1][p2] = false; for (int q = 0; q < n; ++q) {
if (q == x || q == y || q == p1 || q == p2 || tag[x][p2][q]) {
continue;
}
if (geometry::Left(p[p1], p[p2], p[q]) &&
geometry::Left(p[x], p[p2], p[q]) &&
geometry::Left(p[x], p[y], p[q])) {
int sum = node.cnt + 1 + g[p2][q][x];
if (f[y][p2][q] < sum) {
f[y][p2][q] = sum;
result = std::max(result, sum);
if (!inque[y][p2][q]) {
inque[y][p2][q] = true;
que.push(Node(p2, q, y, sum));
}
}
}
}
}
return result;
}
};

code for problem3

#include <string>
#include <vector> class BagAndCards {
public:
int getHash(int n, int m, int x, int a, int b, int c,
const std::string &isGood) {
constexpr int kMod = 1000000007;
std::vector<std::vector<int>> f(n, std::vector<int>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
f[i][j] = x;
x = static_cast<int>(((1ll * x * a + b) ^ c) % kMod);
}
}
auto Add = [&](int &x, int y) {
x += y;
if (x >= kMod) {
x -= kMod;
}
};
int result = 0;
for (int j = 0; j < n; ++j) {
std::vector<int> s(m, 0);
for (int i = 0; i < m; ++i) {
for (int t = 0; t < m; ++t) {
if (isGood[i + t] == 'Y') {
Add(s[i], f[j][t]);
}
}
}
for (int i = 0; i < j; ++i) {
int sum = 0;
for (int k = 0; k < m; ++k) {
Add(sum, static_cast<int>(1ll * f[i][k] * s[k] % kMod));
}
result ^= sum;
}
}
return result;
}
};

topcoder srm 679 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. Topcoder SRM 584 DIV1 600

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

  8. TopCoder SRM 605 DIV1

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

  9. topcoder srm 575 div1

    problem1 link 如果$k$是先手必胜那么$f(k)=1$否则$f(k)=0$ 通过对前面小的数字的计算可以发现:(1)$f(2k+1)=0$,(2)$f(2^{2k+1})=0$,(3)其 ...

随机推荐

  1. eclipse设置字体_字符编码_快捷键

    eclipse设置字体.字符编码.快捷键 1.设置字体: preferences->general->appearnce->colors and fonts-->basic-- ...

  2. 136. Single Number(位运算)

    Given a non-empty array of integers, every element appears twice except for one. Find that single on ...

  3. B树,B+树,B*树以及R树的介绍

    https://blog.csdn.net/peterchan88/article/details/52248714 作者:July.weedge.Frankie.编程艺术室出品. 说明:本文从B树开 ...

  4. MySql 查询表中字段的数据类型

    [1]MySQL中查询某表中字段的数据类型 (1)DESC 表名: (2)DESCRIBE 表名: (3)SHOW COLUMNS FROM 表名: 应用示例: DESC cfg_acct_free_ ...

  5. flask 单个表单多个提交按钮

    单个表单多个提交按钮 在某些情况下,可能需要为一个表单添加多个提交按钮.比如在创建文章的表单中添加发布按钮和存草稿的按钮.当用户提交表单时,需要在视图函数中根据按下的按钮来做出不同的处理. 下面例子中 ...

  6. C# 声明隐式类型的局部变量

    在c#中赋值给变量的值必须具有和变量相同的类型.如int值赋给int变量,c#编译器可以迅速判断变量初始化表达式的类型,如果变量类型不符,就会明确告诉你. 提示需要强制转换(例如在char中不允许使用 ...

  7. js多个异步请求

    一,两个(或多个)js异步并发执行,怎么在两个AJax异步操作之后执行一个新的操作 原题来自 ES6 方法 1.Promise 包装异步ajax操作,2.定义async 函数,3.用await等待pr ...

  8. JustOj 1936: 小明A+B

    题目描述 小明今年3岁了, 现在他已经能够认识100以内的非负整数, 并且能够进行100以内的非负整数的加法计算. 对于大于等于100的整数, 小明仅保留该数的最后两位进行计算, 如果计算结果大于等于 ...

  9. json.dumps(),json.loads(),json.dump(),json.load()方法的区别

    1. json.dumps() json.dump()是将字典类型转化成字符串类型. import json dic = {'a':'1111','b':'2222','c':'3333','d':' ...

  10. jumpserver堡垒机安装

    1. 下载jumpserver cd /opt wget https://github.com/jumpserver/jumpserver/archive/master.zip unzip maste ...