srm 539
http://mlz000.github.io/2015/07/15/srm-539/
250
Description:
从若干个盒子中随意选择几个装石头。每一个盒子容量都有上下限,一旦选择使用某个盒子,那么填装的石头数必须在该盒子的上下限容量之间。假设终于填装的石头总数为x。那么符合条件x>9000的x有多少个?
数据规模:盒子总数[1,15], 盒子容量[1,106]
Solution
盒子总数15非常easy想到枚举状态,把每一个的上下限存一下。排个序统计一下答案就可以。
Code
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
const int M = 9000;
vector<pii> a;
class Over9000Rocks {
public:
int countPossibilities(vector <int> lowerBound, vector <int> upperBound) {
int n = lowerBound.size();
for (int i = 0; i < 1 << n; ++i) {
int l = 0, r = 0;
for (int j = 0; j < n; ++j) {
if (i >> j & 1) {
l += lowerBound[j];
r += upperBound[j];
}
}
l = max(l, M + 1);
if (l <= r) a.pb(mp(l, r));
}
sort(a.begin(), a.end());
int R = 0, ans = 0;
for (int i = 0; i < a.size(); ++i) {
if (a[i].F > R) ans += a[i].S - a[i].F + 1;
else if (a[i].S > R) ans += a[i].S - R;
R = max(R, a[i].S);
}
return ans;
}
};
550
Description
目大意:给定一张图。有T个点,如今有 n 个人要从0号点分别走到 1 ~ n 号点,每一个人都是沿着自己最短路径走(有多条最短路径则可随意选一条)。假设在到达终点之前。有个人单独行动,则觉得这个人是处在危急中的(仅仅有一个人经过某条边)。问n个人该怎么走使得处在危急中的人数最少。
Solution
能够想到,假设一个人的是安全的话那么他的最短路径一定能够被还有一个人全然覆盖,这样我们把相互能够覆盖的建个图。求匹配即是答案。
Code
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
const int N = 55;
int d[N][N], f[N][N], l[N];
bool vis[N];
bool find(int u, int n) {
for (int i = 1; i <= n; ++i) {
if (f[u][i] && !vis[i]) {
vis[i] = 1;
if (!l[i] || find(l[i], n)) {
l[i] = u;
return 1;
}
}
}
return 0;
}
class SafeReturn {
public:
int minRisk(int T, vector <string> streets) {
int n = streets.size();
memset(d, 63, sizeof(d));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (streets[i][j] != '-') d[i][j] = streets[i][j] - '0';
for (int i = 0; i < n; ++i) d[i][i] = 0;
for (int k = 0; k < n; ++k)
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
for (int i = 1; i <= T; ++i)
for (int j = 1; j <= T; ++j)
if (i != j && d[0][j] + d[j][i] == d[0][i]) f[i][j] = 1;
int ans = T;
for (int i = 1; i <= T; ++i) {
memset(vis, 0, sizeof(vis));
if (find(i, T)) --ans;
}
return ans;
}
};
srm 539的更多相关文章
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- SRM 513 2 1000CutTheNumbers(状态压缩)
SRM 513 2 1000CutTheNumbers Problem Statement Manao has a board filled with digits represented as St ...
- SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)
SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...
- SRM 657 DIV2
-------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...
- SRM DIV1 500pt DP
SRM 501 DIV1 500pt SRM 502 DIV1 500pt SRM 508 DIV1 500pt SRM 509 DIV1 500pt SRM 511 DIV1 500pt SRM 5 ...
- TC srm 673 300 div1
TC srm.673 300 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 Description 给你n(n<=50)匹马和n个人,一匹马和一个人能 ...
- SRM 584 第一次玩TopCoder。。。只水题一道。。。
第一次topcoder,以前老感觉没有资格去做tc,cf什么的,现在已经慢慢接触了. 感觉还可以,还是有让我们这些蒻菜安慰的水题. tc的确很好玩,用客户端比赛,还有各种规则,而且还是只编写一个类提交 ...
- SRM 616 ColorfulCoins
题意:给定一个从小到大的货币面值,每一个面额都是其前面面额的倍数(倍数大于等于2),每一种货币面值对应一种颜色,目前不清楚面值与颜色的对应关系.要求用最少的查询次数来确定面额与颜色的对应关系.(一次查 ...
- SRM144 - SRM 148(少144-DIV1-LV3,147-DIV2-LV3)
SRM 144 DIV 1 500pt tag:组合 题意:彩票中奖.给定n, m,从1-n中选择m个数组成数列a1, a2, a3...am.对于数列{am}分别满足以下条件的概率: (1)数列所有 ...
随机推荐
- swing jTable排序问题(点击表头排序)
1.JDK6自带排序实现: tableName.setAutoCreateRowSorter(true); 2.其实界面设计中勾选一个属性就搞定了: .
- (转)淘淘商城系列——Redis持久化方案
http://blog.csdn.net/yerenyuan_pku/article/details/72858975 Redis中设置key的过期时间 Redis中的expire命令用于设置key的 ...
- JavaScipt30(第一个案例)(主要知识点:键盘事件以及transitionend)
今天得到一个github练习项目,是30个原生js写成的小例子,麻雀虽小五脏俱全,现在记录一下第一个. 第一个是键盘按键时页面上对应的键高亮,同时播放音频,松开后不再高亮. 我自己实现了一下,然后查看 ...
- 第一节:EasyUI样式,行内编辑,基础知识
一丶常用属性 $('#j_dg_left').datagrid({ url: '/Stu_Areas/Stu/GradeList', fit: true, // 自动适应父容器大小 singleSel ...
- php第二十四节课
三级联动 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...
- Python学习笔记(3)动态类型
is运算符 ==是值相等而is必须是相同的引用才可以 l=[1,2,3] m=[1,2,3] print(l==m) # True print(l is m) # False sys模块 getref ...
- Idea+maven+testng+reportng生成测试报告
TestNG自带的测试报告不是很好用,所以一般结合reportng生成美观的测试报告. 首先,在pom.xml中添加testng和reportng相关依赖 <dependencies> & ...
- type、object、class之间的关系
class Foo: pass print(type(int)) # <class 'type'> print(type(str)) # <class 'type'> prin ...
- buf.writeDoubleBE()函数详解
buf.writeDoubleBE(value, offset[, noAssert]) buf.writeDoubleLE(value, offset[, noAssert]) value {Num ...
- Python基础函数
join()函数的用法 join()函数连接字符串数组.将字符串.元组.列表中的元素以指定的字符(分隔符)连接生成一个新的字符串 语法:'sep'.join(seq) 参数说明sep:分隔符.可以为空 ...