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 ...
随机推荐
- java8 数据结构的改变(二) 对ConcurrentHashMap影响
https://www.cnblogs.com/study-everyday/p/6430462.html http://www.importnew.com/22007.html
- [线段树]picture
PICTURE 题目描述 N(N<5000) 张矩形的海报,照片和其他同样形状的图片贴在墙上.它们的边都是垂直的或水平的.每个矩形可以部分或者全部覆盖其他矩形.所有的矩形组成的集合的轮廓称为周长 ...
- 采用JavaMelody监控Tomcat服务——安装手册
#1.获取安装包 .zip mv probe.war <tomcat dir>/webapps #3.设置tomcat用户信息 vi <tomcat dir>/conf/tom ...
- com_pc-mcu
#include <REG52.H> unsigned char UART_buff; bit New_rec = , Send_ed = , Money = ; void main (v ...
- Python之路番外(第二篇):PYTHON基本数据类型和小知识点
一.基础小知识点 1.如果一行代码过长,可以用续行符 \换行书写 例子 if (signal == "red") and \ (car == "moving") ...
- Internet
0x01 URL的解析/反解析/连接 解析 urlparse()--分解URL # -*- coding: UTF-8 -*- from urlparse import urlparse url = ...
- Maximum Subarray LT53
Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...
- openssl 连接 https(nginx)
参考源码路径 demos\ssl #include <stdio.h> #include <string.h> #include <stdlib.h> #incl ...
- jrebel
jrebel 编辑 JRebel是一套JavaEE开发工具.JRebel允许开发团队在有限的时间内完成更多的任务修正更多的问题,发布更高质量的软件产品. JRebel是收费软件,用户可以在JReb ...
- OPNET仿真软件资料合集
1. OPEN中国代理商业 http://www.credit-top.com/page/Default.asp?pageID=105