SRM479
250pt:
题意:有一排一共44,777,777个人,每个人需要咖啡或者茶,队伍的头部有一台饮料机,有一个空姐负责给所有人送饮料,她一开始在也头部。空姐拿一个水壶,一开始是空的,可以在饮料机的地方加最多7个单位的咖啡或者茶,加一次要47秒。空姐在相邻位置移动需要1秒,空姐给一个人倒茶或者咖啡需要4秒。现在告诉你哪些乘客需要茶(最多50个),问最优策略下,空姐需要多少时间可以给所有乘客倒好饮料并且回到队列头。
思路:直接枚举
500pt:
题意:有n<=477个城市,然后一些城市之间会有航班,每个航班有起飞和到达站、飞行时间,有一个航班开始时间,还有一个周期,从开始时间开始,每隔一个周期有一班飞机起飞。现在有一个人要从1飞到n,保证1到n之间没有直接的航班,于是必须至少要换一次航班。每次换航班都有一个等待时间,所有等待时间中的最小值就是一个保险系数。现在要在t<=1,000,000,000的时间内从1到达n,问可以达到的最大保险系数是多少。
思路:直接二分答案,那么接下来就是一个spfa判定了。
code:
#line 7 "TheAirTripDivOne.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 A[], B[], F[], P[], T[];
vector<int> g[];
bool vis[];
long long d[];
class TheAirTripDivOne
{
public:
string S;
int n, m, limit;
void make_flight(){
m = ;
// cout << S << endl;
int cnt = , tmp = ;
for (int i = ; i < S.size(); ++i){
if (S[i] == ','){
if (cnt == ) A[m] = tmp;
if (cnt == ) B[m] = tmp;
if (cnt == ) F[m] = tmp;
if (cnt == ) T[m] = tmp;
cnt++;
tmp = ;
}
else if (S[i] == ' '){
P[m++] = tmp;
tmp = cnt = ;
} else tmp = tmp * + S[i] - ;
}
if (tmp > ) P[m++] = tmp;
for (int i = ; i <= n; ++i)
g[i].clear();
for (int i = ; i < m; ++i)
g[A[i]].PB(i);
}
bool SPFA(int waitTime){
for (int i = ; i <= n; ++i)
d[i] = (1LL << );
queue<int> q;
d[] = -waitTime;
vis[] = true;
q.push();
long long time, r;
while (!q.empty()){
int u = q.front(), v;
for (int i = ; i < g[u].size(); ++i){
v = B[g[u][i]];
time = d[u] + waitTime;
if (time <= F[g[u][i]]) time = F[g[u][i]];
else {
r = (time - F[g[u][i]] - ) / P[g[u][i]] + ;
time = F[g[u][i]] + P[g[u][i]] * r;
}
if (time + T[g[u][i]] < d[v]){
d[v] = time + T[g[u][i]];
if (!vis[v]) q.push(v), vis[v] = true; }
}
q.pop();
vis[u] = false;
}
return d[n] <= limit;
}
int solve(){
int l = , r = , mid;
int ret = -;
while (l <= r){
mid = (l + r) >> ;
if (SPFA(mid)){
l = mid + ;
ret = mid;
} else r = mid - ;
}
return ret;
} int find(int N, vector <string> flights, int time)
{
S = accumulate(flights.begin(), flights.end(), string(""));
n = N;
limit = time;
make_flight();
return solve();
}
};
SRM479的更多相关文章
- SRM475 - SRM479(1-250pt,500pt)
SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...
随机推荐
- git报“commiter email "root@localhost.localdomain"does not match your user account”
首先检查账户邮箱配置是否正确,检查方法: git config --list 发现邮箱及帐号配置正确,但是git push时仍然报如题错误: 原因:git执行add.commit 时已经记录下了做了该 ...
- [转载]linux中sed的用法
转自:http://www.cnblogs.com/emanlee/archive/2013/09/07/3307642.html sed命令行格式为: sed [-nefri] ‘ ...
- Centos安装配置Postfix邮件服务器--网址
http://www.haiyun.me/archives/centos-install-postfix.html http://blog.csdn.net/liuyunfengheda/articl ...
- python基础之Day4
流程判断 一.if 1.语法一 各条件都执行 if条件1: if条件2: if条件3: 2.语法二 if多分支,自上而下执行,一旦满足条件,后面代码即使满足条件也不会执行 if条件1: elif条件2 ...
- DataTable xml 互相转换
//测试方法 public static DataTable Test() { string savePath = System.AppDomain.CurrentDomain.BaseDirecto ...
- EASYUI DATAGRID 改变行值
在easyui datagrid 中如果要 改变当前选中行的值又不想用编辑状态,或者想从外部改变某一行的值,下面的方法可以做到 function test() { var ro ...
- js值类型与引用类型
JavaScript值类型和引用类型有哪些 (1)值类型:数值.布尔值.null.undefined. (2)引用类型:对象.数组.函数. 三.如何理解值类型和引用类型及举例 我们可以用“连锁店”和“ ...
- servlet 知识点 WebServlet("/")与WebServlet("/*")的区别
(1)一个servlet的请求路径,如果配置成"/",那么它可以拦截除了.jsp之外的所有的请求. (2)一个servlet的请求路径,如果配置成"/*",那么 ...
- 查看tomcat运行日志
1.先到tomcat的logs目录下我这边是:/usr/local/apache-tomcat-7.0.73/logs 2.tail -f catalina.out 3.这样,前端有请求时候,就会输出 ...
- 27 isinstance与issubclass、反射、内置方法
isinstance与issubclass issubclass:判断子类是否属于父类,是则返回True,否则返回False isinstance:判断对象是否属于类,是则返回True,否则返回Fal ...