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. 遍历二叉树 traversing binary tree 线索二叉树 threaded binary tree 线索链表 线索化

    遍历二叉树   traversing binary tree 线索二叉树 threaded binary tree 线索链表 线索化 1. 二叉树3个基本单元组成:根节点.左子树.右子树 以L.D.R ...

  2. error lnk1158 无法运行rc.exe

    找到C:\Program Files (x86)\Windows Kits\8.0\bin\在运行一下rc.exe和rcdll.dll拷贝到D:\Soft\VS2015\VC\bin目录下.

  3. loj2083 优秀的拆分 [NOI2016] SA

    正解:SA 解题报告: 我永远喜欢loj! 显然$AABB$串相当于是由两个$AA$串拼起来的,所以可以先考虑如果求出来了所有$AA$串怎么求答案? 就假如能统计出$st[i]$表示所有以$i$为开头 ...

  4. 常见MQTT服务器搭建与试用

    常见MQTT服务器搭建与试用   简介 MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)是IBM开发的一个即时通讯协议,它比较适合于在低带宽.不可靠 ...

  5. 基于ROS的分布式机器人远程控制平台

    基于ROS的分布式机器人远程控制平台   1 结构说明 HiBot架构主要使用C/S架构,其中HibotServer为服务器,Muqutte为消息服务器中间件,HiBotClient为运行在机器人上的 ...

  6. python编写shell脚本

    模块 os模块和shutil模块主要用于在python中执行一些Linux相关的操作,其中 os.system(command) 可以直接运行Linux命令,如os.system('ls'). 不过, ...

  7. BeautifulSoup库的使用

    1.简介 BeautifulSoup库也是一个HTML/XML的解析器,其使用起来很简单,但是其实解析网站用xpath和re已经足矣,这个库其实很少用到.因为其占用内存资源还是比xpath更高. '' ...

  8. 【HBase】-NO.140.HBase.1 -【HBase】

    Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...

  9. 60道Python面试题&答案精选!找工作前必看

    需要Word/ PDF版本的同学可以在实验楼微信公众号回复关键词"面试题"获取. 1. Python 的特点和优点是什么? 答案:略. 2. 什么是lambda函数?它有什么好处? ...

  10. mvc自定义分页(加页数的)(转)

    1.引言 在MVC开发中我们经常会对数据进行分页的展示.通过分页我们可以从服务端获取指定的数据来进行展示.这样既节约了数据库查询的时间也节约了网络传输的数据量.在MVC开发中使用的比较多的应该是MVC ...