题目
有一座桥,桥的两边有nnn个老人,一共2n2n2n个老人,我们要把所有的老人带到对面,让他们休息xxx分钟后再回来,过桥的时间为ttt,求需要的最少时间
思路
设先把所有老人都对换了。
这时候有两种选择,
第一种是直接在现在这里选择第一个来到这里的老人背回去,需要多消耗的时间是max(x−(2∗n∗t−2∗t),0LL)max(x-(2*n*t-2*t),0LL)max(x−(2∗n∗t−2∗t),0LL)
第二种是过桥到对面去背老人回来,需要多消耗的时间是max(x−2∗n∗t)+t,t)max(x-2*n*t)+t,t)max(x−2∗n∗t)+t,t)
总时间就是min(max(x−(2∗n∗t−2∗t),0LL),max(x−2∗n∗t)+t,t)+4∗n∗tmin(max(x-(2*n*t-2*t),0LL),max(x-2*n*t)+t,t)+4*n*tmin(max(x−(2∗n∗t−2∗t),0LL),max(x−2∗n∗t)+t,t)+4∗n∗t
代码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int n,x,y;
cin>>n>>x>>y;
cout<<min(max((x-(2*n*y-2*y)),0LL),max(x-(2*n)*y)+y,y)+4*n*y<<endl;
}
return 0;
}
480

被折叠的 条评论
为什么被折叠?



