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 ...
随机推荐
- spring boot (三): 热部署
介绍了Spring boot实现热部署的两种方式,这两种方法分别是使用 Spring Loaded和使用spring-boot-devtools进行热部署. 热部署是什么 大家都知道在项目开发过程中, ...
- mysql 5.17 的update失败问题
在使用workbench的时候,写入update语句,会很提现失败,原因是安全模式; 可能是workbench在数据库更新的时候是有限制的,防止错误哦l 更改方法也很简单; Edit - Profer ...
- 20172325 2018-2019-2 《Java程序设计》第五周学习总结
20172325 2018-2019-2 <Java程序设计>第五周学习总结 教材学习内容总结 本次学习第九章内容,主要学习查找和排序. 查找 查找的定义:是一个过程,即在某个项目组中寻找 ...
- 学习C语言以及C语言基础调查
学习声乐的心得 你有什么技能比大多人(超过90%以上)更好? 就我个人而言,在所有的兴趣之中,做得比较好的应该属于声乐. 针对这个技能的获取你有什么成功的经验? 我对于声乐处始于兴趣,成功的经 ...
- 原创:Spring整合junit测试框架(简易教程 基于myeclipse,不需要麻烦的导包)
我用的是myeclipse 10,之前一直想要用junit来测试含有spring注解或动态注入的类方法,可是由于在网上找的相关的jar文件进行测试,老是报这样那样的错误,今天无意中发现myeclips ...
- Vue单页面应用
单页面应用指一个系统只加载一次资源,然后下面的操作交互.数据交互是通过router.ajax来进 行,页面并没有刷新:<1>在vue搭建的环境里面怎么有没有公用的css和js? ...
- Notepad++语言格式设置,自定义扩展名关联文件格式
简单粗暴--直接上图
- 用php把access数据库导入到mysql
<?php header("content-Type: text/html; charset=utf-8"); /// ///把access数据库转换成mysql的SQL语句 ...
- Go环境下,编译运行etcd与goreman集群管理(1)
Go环境下编译运行etcd与goreman管理 近几年了Go在比特币.区块链.云服务等相关重要领域贡献突出,作为IT行业的传承“活到老.学到光头”,保持学习心态. 周末放假,补充一二 主题:在Go环境 ...
- android-如何获得当前正在运行的activity的相关信息
http://blog.csdn.net/centralperk/article/details/7269326 ActivityManager manager = (ActivityManager) ...