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的更多相关文章

  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. SRM 620 DIV1 L2

    题意:有n个等长的string(设string的长度为m),string中的字符从'A'到'Z',容许对m列执行稳定的排序操作,问说是否能通过这m种操作将这n个string调整成对应的顺序. 题解: ...

  9. TopCoder SRM 605 DIV1

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

随机推荐

  1. 网站优化(SEO)的10大误区

    前段时间大前端也有关于SEO的文章贡献给广大读者,今日,再发一文,网站优化(SEO)的10大误区.很多新手站长初次接触SEO,感受到SEO 的无穷魅力,想要做一位优秀的SEOer,然而新手朋友在进行S ...

  2. 去掉UITableView多余的分割线

    UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; [_tableView setTableFooterView:v];

  3. java-JProfiler(五)-监控性能

    原文地址:http://blog.csdn.net/chendc201/article/details/22897999 一.基础认识 1. 在Live Memory视图里右击相关类,选中Mark C ...

  4. Lodash入门介绍

    原文额地址  http://www.w3cplus.com/javascript/lodash-intro.html 有多年开发经验的工程师,往往都会有自己的一套工具库,称为 utils.helper ...

  5. POJ:2049Finding Nemo(bfs+优先队列)

    http://poj.org/problem?id=2049 Description Nemo is a naughty boy. One day he went into the deep sea ...

  6. [LeetCode] 285. Inorder Successor in BST_Medium tag: Inorder Traversal

    Given a binary search tree and a node in it, find the in-order successor of that node in the BST. No ...

  7. 批量生成反色图片,用PHOTOSHOP批处理功能。

    http://zhidao.baidu.com/link?url=Iz46PDPnEITummTEwo2GtUrK6AeAjlidJ7HtCPJ6NYZJbbllRwNg2iBAcNwF2TYjccP ...

  8. iOS UI基础-4.2应用程序管理 Xib文件使用

    Xib调整使用 1.新建xib文件 New File-->User Interface-->Empty 2.打开新建的xib文件,出现可视化窗口 (1)拖入一个UIView (不是UIVi ...

  9. EditPlus 4.3.2583 中文版已经发布

    新的版本提升了括号匹配的性能.请点击页面左上角连接下载.

  10. 20155213 2016-2017-2 《Java程序设计》第九周学习总结

    20155213 2016-2017-2 <Java程序设计>第九周学习总结 教材学习内容总结 第十六章 JDBC(Java DataBase Connectivity)即java数据库连 ...