SRM469
250pt
在一个10^9 * 10^9大的剧院里,有最多47个位子有人,然后有一对couple想找一对左右相邻的位子,问有多少种选择方式。
思路:
总共有 n * (m-1)种方案,然后扣掉有人位置占掉的方案即可。
这里占掉位置我用一个set存储,正好可以去重。。
#line 7 "TheMoviesLevelOneDivOne.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class TheMoviesLevelOneDivOne
{
public:
long long find(int n, int m, vector <int> row, vector <int> seat)
{
long long ans = n;
ans =ans * (m - );
set< PII > S;
for (int i = ; i < row.size(); ++i){
if (seat[i] > ) S.insert(make_pair(row[i], seat[i]));
if (seat[i] + <= m) S.insert(make_pair(row[i], seat[i] + ));
}
ans -= S.size();
return ans;
} };
500pt
题意:一个人看电影,该人有一个scare值,并且没看1min电影scare减1。有很多部恐怖电影,每部电影长度不同(length[i]),且每部都有一个瞬间增加scare(s[i])值的时刻。如果scare值小于0,则这个人就会睡着,不能再看电影。请问他安排一个电影观看顺序,使得他能看尽可能多的电影。如果有多组观看顺序看到的电影数相同,则输出字典序最小的。(电影数量小等于20)
思路:
状态压缩。。
#line 7 "TheMoviesLevelTwoDivOne.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
int dp[ << ]; class TheMoviesLevelTwoDivOne
{
public:
vector <int> find(vector <int> L, vector <int> scary)
{
int n = L.size();
memset(dp, , sizeof(dp));
for (int i = ; i < ( << n); ++i){
int level = ;
for (int j = ; j < n; ++j)
if (!(i & ( << j))) level += - L[j];
for (int j = ; j < n; ++j) if (i & ( << j))
if (level >= scary[j] && level + - L[j] >= )
dp[i] = max(dp[i], dp[i ^ ( << j)] + );
}
vector<int> ans;
int x = , mask = ( << n) - ;
while (mask > ){
for (int i = ; i < n; ++i) if (mask & ( << i))
if (dp[mask] == ||
(x >= scary[i] && x + - L[i] >= && dp[mask ^ ( << i)] == dp[mask] - )){
ans.PB(i);
mask ^= ( << i);
x += - L[i];
break;
}
}
return ans;
}
};
SRM469的更多相关文章
- SRM468 - SRM469(1-250pt, 500pt)
SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...
- Topcoder 好题推荐
SRM SRM147 DIV1 1000pt DP SRM148 DIV1 1100pt 递归 SRM149 DIV1 1000pt math SRM150 DIV1 500pt DP SRM469 ...
随机推荐
- suricata 原文记录
如何在 Linux 系统上安装 Suricata 入侵检测系统 编译自:http://xmodulo.com/install-suricata-intrusion-detection-system-l ...
- BZOJ2730或洛谷3225 [HNOI2012]矿场搭建
BZOJ原题链接 洛谷原题链接 显然在一个点双连通分量里,无论是哪一个挖煤点倒塌,其余挖煤点就可以互相到达,而对于一个点双连通分量来说,与外界的联系全看割点,所以我们先用\(tarjan\)求出点双连 ...
- iOS一段文字设置多种颜色格式
调用 [self fuwenbenLabel:contentLabel FontNumber:[UIFont systemFontOfSize:] AndRange:NSMakeRange(, ) A ...
- c++四舍五入的新方法
将原来的数加上0.5,如果是需要进位的加上0.5就进位了,如果不需要进位的加上0.5也小于1,被int型省略掉.
- shell 报错 /bin/bash^M: bad interpreter: No such file or directory
shell 执行报错: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory 原因:window和linux 的文件格式 ...
- 2019.01.19 codeforces915E.Physical Education Lessons(ODT)
传送门 ODT水题(当然可以上线段树) 支持区间01覆盖,询问全局1的个数. 思路:直接上ODTODTODT. 不会的点这里 代码: #include<bits/stdc++.h> #de ...
- 半透明全屏蒙层+全屏屏蔽+内容居中+css
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- C++中string的使用
概述 这篇博文为了记录C++中string的使用,用到一点补充一点. 预备 使用string之前需要包含头文件 #include<iostream> #include<string& ...
- Tomcat架构解析(三)-----Engine、host、context解析以及web应用加载
上一篇博文介绍了Server的创建,在Server创建完之后,就进入到Engine的创建过程,如下: 一.Engine的创建 1.创建Engine实例 当前次栈顶元素为Service对象,通过Se ...
- 【服务器】Nginx文件配置
nginx.conf文件 #运行用户 user nobody; #启动进程,通常设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 #error_log lo ...