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的 ...
随机推荐
- POJ3621或洛谷2868 [USACO07DEC]观光奶牛Sightseeing Cows
一道\(0/1\)分数规划+负环 POJ原题链接 洛谷原题链接 显然是\(0/1\)分数规划问题. 二分答案,设二分值为\(mid\). 然后对二分进行判断,我们建立新图,没有点权,设当前有向边为\( ...
- Permutation Sequence LT60
The set [1,2,3,...,n] contains a total of n! unique permutations. By listing and labeling all of the ...
- jquery单行文字上下循环滚动
html代码: <div class="box"> <div class="t_news"> <b>已关联奖励账号.昵称:& ...
- java 内存, 类加载g
1. java 内存区域 方法区 虚拟机栈 本地方法栈 堆 程序计数器 其中 : 方法区 和 堆 是所有线程共享的 , 其他是线程隔离的 1. 程序计数器 : 可以看做是当前线程所执行的字节码的 ...
- 使用Apache CXF和Spring集成创建Web Service(zz)
使用Apache CXF和Spring集成创建Web Service 您的评价: 还行 收藏该经验 1.创建HelloWorld 接口类 查看源码 打印? 1 package ...
- SpringMVC学习笔记:表单提交 参数的接收
SpringMVC可以接收原生form表单和json格式数据 有一个名为Book的model,其中的属性如下: 字符串类型的name,数字类型的price,数组类型的cover,集合类型的author ...
- 20155312 2016-2017-2 《Java程序设计》第八周学习总结
20155312 2016-2017-2 <Java程序设计>第八周学习总结 课堂内容总结 学习模式 游乐园模式-荒野求生模式 学习方法 以代码为中心->遇到不会的类和方法(参数等) ...
- python学习 day3 (3月4日)---字符串
字符串: 下标(索引) 切片[起始:终止] 步长[起始:终止:1] 或者-1 从后往前 -1 -2 -3 15个专属方法: 1-6 : 格式:大小写 , 居中(6) s.capitalize() s ...
- substr()和substring()函数
区别:主要是两者的参数不同 功能:相似. substr :返回一个从指定位置开始的指定长度的子字符串 substring :返回位于 String 对象中指定位置的子字符串. 用法: stringva ...
- mybatis中文官网
http://www.mybatis.org/mybatis-3/zh/index.html