problem1 link

对于数字$x$,检验每个满足$x=y*2^{t}$的$y$能否变成$x$即可。

problem2 link

如果起点到终点有一条长度为$L$的路径,那么就存在长度为$L+kR$的路径。其中$R$为从路径上某点转一圈再回到这一点的环的长度。

为了保证总是存在这个环,可以令这个环为从起点出发再回到起点。所以如果有一条长度为$d$的边$0\rightarrow t$,那么可以令$R=2d$,即$0\rightarrow t \rightarrow 0$.

只需要记录起点到达某个点长度模$R$的最短路即可。即用$f[m][u]$表示从0到$u$的最小的满足$m+kR$的路径长度。

只要$f[T$%$R][N-1] \leq T$即可。

problem3 link

红色和绿色需要配对出现。所以可以将一个红色一个绿色看作一个整体。那么就是$M$组中每组要出现$D$个配对的整体。

从前向后进行动态规划,只统计出现了多少个配对的整体以及还有多少个只配对了一半的。

这里有个问题是每一组中的$D$个整体不能交叉出现。为了做到这一点,只需要配对了一半的个数不超过$M$即可.

code for problem1

#include <set>
#include <vector> class AmebaDiv1 {
public:
int count(const std::vector<int> &X) {
auto Get = [&](int t) {
for (auto e : X) {
if (e == t) {
t *= 2;
}
}
return t;
}; std::set<int> all(X.begin(), X.end());
int result = 0;
for (auto e : all) {
bool tag = (Get(1) != e);
int t = e;
while (t > 1) {
if (Get(t) == e) {
tag = false;
break;
}
t /= 2;
}
if (tag) {
++result;
}
} return result;
}
};

code for problem2

#include <cstring>
#include <set>
#include <string>
#include <vector> constexpr int MAXD = 20000;
constexpr int MAXN = 50; long long dist[MAXD][MAXN]; class LongLongTripDiv1 {
public:
std::string isAble(int N, const std::vector<int> &A,
const std::vector<int> &B, const std::vector<int> &D,
long long T) {
int n = static_cast<int>(A.size());
int d = MAXD + 1;
for (int i = 0; i < n; ++i) {
if (A[i] == 0 || B[i] == 0) {
d = std::min(d, D[i]);
}
} if (d == MAXD + 1) {
return "Impossible";
} std::set<std::pair<long long, std::pair<int, int>>> que;
memset(dist, -1, sizeof(dist));
auto Insert = [&](long long dis, int u, int v) {
auto iter = que.find({dist[u][v], {u, v}});
if (iter != que.end()) {
que.erase(iter);
}
que.insert({dis, {u, v}});
dist[u][v] = dis;
};
Insert(0, 0, 0);
while (!que.empty()) {
auto node = que.begin()->second;
que.erase(que.begin());
int u = node.second;
for (int i = 0; i < n; ++i) {
if (A[i] != u && B[i] != u) {
continue;
}
int v = A[i] + B[i] - u;
int t = (node.first + D[i]) % (2 * d);
long long new_dist = dist[node.first][u] + D[i];
if (dist[t][v] == -1 || new_dist < dist[t][v]) {
Insert(new_dist, t, v);
}
}
}
auto min_dist = dist[T % (d * 2)][N - 1];
return (min_dist != -1 && min_dist <= T) ? "Possible" : "Impossible";
}
};

code for problem3

#include <string>

constexpr int MOD = 1000000007;

int f[5005][50][51];

class AlternativePiles {
public:
int count(const std::string &C, int M) {
if (Red(C[0])) {
f[0][0][1] += 1;
}
if (Blud(C[0])) {
f[0][0][0] += 1;
}
for (size_t idx = 1; idx < C.size(); ++idx) {
char c = C[idx];
for (int x = 0; x < M; ++x) {
for (int y = 0; y <= M; ++y) {
int t = f[idx - 1][x][y];
if (t == 0) {
continue;
}
if (Red(c) && y + 1 <= M) {
(f[idx][x][y + 1] += t) %= MOD;
}
if (Blud(c)) {
(f[idx][x][y] += t) %= MOD;
}
if (Green(c) && y > 0) {
(f[idx][(x + 1) % M][y - 1] += t) %= MOD;
}
}
}
}
return f[C.size() - 1][0][0];
} private:
bool Red(char c) { return c == 'R' || c == 'W'; } bool Green(char c) { return c == 'G' || c == 'W'; } bool Blud(char c) { return c == 'B' || c == 'W'; }
};

topcoder srm 615 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. SRM 615 DIV1 500

    TC 都615了...时间过的真快啊. 第一次做出500分,心情还是很激动的,虽然看了很久的题解,TC官网上的题解,很详细,但是英语的...我搜了搜,发现一份日语的...好吧,我还是看看英语的吧... ...

  4. topcoder srm 714 div1

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

  5. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

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

  6. Topcoder SRM 602 div1题解

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

  7. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

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

  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. 使用vue实现tab栏的点击切换样式

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  2. treesoft,couchDB,

    下载 docker 镜像:docker pull docker.io/lu566/treesoft:1.0启动容器:docker run -d -p 127.0.0.1:18080:8080 dock ...

  3. VMware+CentOS7学习记录

    CentOS命令记录 1.su root 进入最高权限 2.cd  /位置       即进入该文件 3.中文与英文之间的切换:win+空格 添加中文的步骤:https://blog.csdn.net ...

  4. js基础--数据类型

    1,数据类型 Number:包括小数与整数,负数,NaN ,Infinity无限大String字符串:‘abc’Boolean布尔值:true or falsenull 空undefined 未定义 ...

  5. Spring Boot 国际化及点击链接跳转国家语言

    一.国际化 在SpringBoot中已经自动帮我们配置管理国际化资源的组件,所以我们只需要编写代码就可. @Bean @ConfigurationProperties(prefix = "s ...

  6. Vue 读取Excel数据

    参考:https://my.oschina.net/u/3720342/blog/1838063 参考2:https://www.cnblogs.com/liguiwang/p/8430672.htm ...

  7. docker容器的实践——综合项目一

                    Docker 综合实验   实验拓扑:   [调度器] Keepalived + nginx 一.Keepalived服务的安装配置: 关闭LVS服务器的ipv4代理和 ...

  8. Android -- Glide框架详解(一)

    1,使用这个框架快两年了,今天去github上去看了一下,貌似已经从3.X升级到4.X了,想着自己还没有对这个框架在博客上做过总结,所以这里打算出三篇博客来介绍,内容有基本使用.3.X与4.X的不通. ...

  9. git之push

    git push :将本地的哪个分支推送到哪个远程主机上的哪个分支.因此明确主机.本地分支名.远程分支名这三个要素. git push命令用于将本地分支的更新,推送到远程主机.它的格式与git pul ...

  10. [virtualbox] win10与centos共享目录下,nginx访问问题

    原文,http://blog.csdn.net/zhezhebie/article/details/73554872 virtualbox自动挂载之后,默认是挂载在/media/sf_WWW下面的: ...