topcoder srm 620 div1
problem1 link
分别计算可以得到(a,b)的有哪些二元组,以及可以得到(c,d)的有哪些二元组。然后在公共的二元组中找到和最大的即可。
problem2 link
设最后的排序为$r=[2,4,1,0,5,3]$.初始时$2=4=1=0=5=3$。从后向前考虑每一个使用的技能。最后一个使用的技能一定是将某些等于符号变成了大于符号。倒数第二次使用的技能一定是将目前的某些等于号变成大于号(或者没有改变)。依次类推直到所有的符号都变成了大于号。假设存在一个正确的序列可以满足要求,将其作为当前答案。如果有一个其他的技能首先被使用也不会冲突的话,那么把它放在当前答案的最前面也无所谓。所以每次选择技能只要使得当前没有冲突即可。
problem3 link
将每个数看做一个变量。对每个出现的质因子建立一个方程,要求这个质因子出现偶数次。另外每一行没一列各建立一个方程,表示出现奇数次。然后进行高斯消元,计算自由元的个数。
code for problem1
#include <algorithm>
#include <set> class PairGame {
public:
int maxSum(int a, int b, int c, int d) {
auto Find = [&](int x, int y, std::set<std::pair<int, int>> *result) {
while (x > 0 && y > 0) {
result->insert({x, y});
if (x == y) break;
if (x > y)
x -= y;
else
y -= x;
}
};
std::set<std::pair<int, int>> result1;
std::set<std::pair<int, int>> result2;
Find(a, b, &result1);
Find(c, d, &result2);
int result = -1;
for (const auto &e : result1) {
if (result2.find(e) != result2.end()) {
result = std::max(result, e.first + e.second);
}
}
return result;
}
};
code for problem2
#include <string>
#include <vector> class CandidatesSelection {
public:
std::string possible(const std::vector<std::string> &s,
const std::vector<int> &v) {
int n = static_cast<int>(s.size());
int m = static_cast<int>(s[0].size()); std::vector<int> rank(n, 0);
long long used_skills = 0; while (true) {
bool find_one = true;
for (int i = 0; i < m; ++i) {
if ((used_skills & (1ll << i)) == 0) {
bool ok = true;
for (int j = 1; j < n && ok; ++j) {
ok &= (rank[j] != rank[j - 1] || s[v[j]][i] >= s[v[j - 1]][i]);
}
if (ok) {
used_skills |= 1ll << i;
find_one = true;
std::vector<int> new_rank(n);
for (int j = 1; j < n; ++j) {
if (rank[j] != rank[j - 1] || s[v[j]][i] != s[v[j - 1]][i]) {
new_rank[j] = new_rank[j - 1] + 1;
} else
new_rank[j] = new_rank[j - 1];
}
rank = new_rank;
}
}
}
if (!find_one) break;
}
for (int i = 1; i < n; ++i) {
if (rank[i] == rank[i - 1] && v[i] < v[i - 1]) {
return "Impossible";
}
}
return "Possible";
}
};
code for problem3
#include <bitset>
#include <cmath>
#include <unordered_map>
#include <vector> constexpr int KMAXCOLUMN = 20 * 20 + 1;
constexpr int KMOD = 1000000007; class PerfectSquare {
public:
int ways(const std::vector<int> &x) {
const int n = static_cast<int>(std::sqrt(x.size()) + 0.1);
std::unordered_map<int, std::vector<int>> mapper;
for (int i = 0; i < n * n; ++i) {
int t = x[i];
for (int j = 2; j * j <= t; ++j) {
int cnt = 0;
while (t % j == 0) {
cnt ^= 1;
t /= j;
}
if (cnt != 0) {
mapper[j].push_back(i);
}
}
if (t > 1) {
mapper[t].push_back(i);
}
} std::vector<std::bitset<KMAXCOLUMN>> matrix;
for (auto it = mapper.begin(); it != mapper.end(); ++it) {
std::bitset<KMAXCOLUMN> row;
for (auto x : it->second) {
row[x] = 1;
}
matrix.push_back(row);
}
for (int i = 0; i < n; ++i) {
std::bitset<KMAXCOLUMN> row1;
std::bitset<KMAXCOLUMN> row2;
for (int j = 0; j < n; ++j) {
row1[i * n + j] = 1;
row2[j * n + i] = 1;
}
row1[n * n] = 1;
row2[n * n] = 1;
matrix.push_back(row1);
matrix.push_back(row2);
}
int free_num = Gauss(&matrix, n * n);
if (free_num == -1) {
return 0;
}
int result = 1;
for (int i = 0; i < free_num; ++i) {
result = result * 2 % KMOD;
}
return result;
} private:
int Gauss(std::vector<std::bitset<KMAXCOLUMN>> *matrix, int m) {
int n = static_cast<int>(matrix->size());
std::vector<bool> visit(n, false);
int not_free_num = 0;
for (int j = 0; j < m; ++j) {
for (int i = 0; i < n; ++i) {
if ((*matrix)[i][j] != 0 && !visit[i]) {
visit[i] = true;
++not_free_num;
for (int k = 0; k < n; ++k) {
if (k != i && (*matrix)[k][j] != 0) {
(*matrix)[k] ^= (*matrix)[i];
}
}
break;
}
}
}
for (int i = 0; i < n; ++i) {
if (!visit[i] && (*matrix)[i][m] != 0) {
return -1;
}
}
return m - not_free_num;
}
};
topcoder srm 620 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 ...
- Topcoder SRM 584 DIV1 600
思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...
- SRM 620 DIV1 L2
题意:有n个等长的string(设string的长度为m),string中的字符从'A'到'Z',容许对m列执行稳定的排序操作,问说是否能通过这m种操作将这n个string调整成对应的顺序. 题解: ...
- TopCoder SRM 605 DIV1
604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...
随机推荐
- logback多环境配置
现在项目基本都是要区分测试开发等等一系列环境的,也因此maven,spring之类的都具有profile这类功能,可以针对不同的环境采用不同的配置.因此日志也可能根据不同的环境需要不同的配置.恰巧手头 ...
- maven配置(myeclipse版)
使用环境说明: OS:windows 7 64位 java version: "jdk1.8.0_66" IDE:myeclipse 2017 1.下载 下载地址:http://m ...
- 2018/04/02 PHP 中的浮点数计算问题
首先抛出一个问题 var_dump((0.1 + 0.2) == 0.3); 这个判断是否正确呢? 它的输出是 false 是否和你想的一样呢? -- 浮点精度运算可以说是每个语言都必有的问题.因为这 ...
- css 计算属性 calc的使用
宽度等于父元素的宽度减去16像素 高度等于父元素的高度减去16像素 注意:100%和16px 与减号之间必须有空格,否则高度会失效!!!! .box{ width:calc(100% - 16px ...
- Redis具体解释与常见问题解决方式
Redis简单介绍 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对很多其它.包含string(字符串).list(链表).set(集合).zset ...
- 解决VMware虚拟机的CentOS无法上网
1)点击 VM->Settings Hardware选项卡下面 2)点击Network Adapter 设置如下图所示,首先我们在虚拟机中将网络配置设置成NAT 在服务中开启: VMware D ...
- 【Python】【亲测好用】安装第三方包报错:AttributeError:'module' object has no attribute 'main'
安装/卸载第三包可能出现如下问题及相应解决办法: 在pycharm编辑中,使用anconda2更新.卸载第三方包时,出现如下错误: AttributeError:'module' object has ...
- 常用python包(依赖)Ubuntu下
amqp==1.4.9anyjson==0.3.3apturl==0.5.2beautifulsoup4==4.4.1billiard==3.3.0.23blinker==1.3Brlapi==0.6 ...
- sql server dba常用概念、操作分析char,varchar,nvarchar,varchar(max)
1.设计表时如何使用char 与 varchar? 请写出你对varchar(max)的理解. 1.设计表时如何使用char 与 varchar? 请写出你对varchar(max)的理解. char ...
- ssh stricthostkeychecking=0
SSH 公钥检查是一个重要的安全机制,可以防范中间人劫持等黑客攻击. 但是在特定情况下,严格的 SSH 公钥检查会破坏一些依赖 SSH 协议的自动化任务,就需要一种手段能够绕过 SSH 的公钥检查. ...