当时开这道题的时候已经只剩最后一个小时了,有bug没找到,结果饮恨
后来补的时候发现的几个小bug。
题目链接(http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4056)
代码:
#include<bits/stdc++.h>
#define LL long long
using namespace std;
vector<LL>v;
int main(){
int T;
scanf("%d",&T);
while(T--){
v.clear();
LL a,b,c,d,V,t;
scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&V,&t);
LL tmp = (a*c)/__gcd(a,c);
LL last = t-(t/tmp)*tmp;
for(int i = 0;i*a<=min(tmp,t);i++){
v.push_back(i*a);
}
for(int i = 0;i*c<=min(tmp,t);i++){
v.push_back(i*c);
}
sort(v.begin(),v.end());
LL tou = 0;
LL tt = 0;
for(int i = 1;i<v.size();i++){
if(2*(v[i]-v[i-1])>2*V+1){
tou ++;
if(tmp < t && v[i] < last){
tt++;
}
}
}
LL ans;
if(tmp<t){
ans = (t/a+1)*b + (t/c+1)*d -tou*(t/tmp)-tt-1;
} else{
ans = (t/a+1)*b + (t/c+1)*d -tou - tt-1;
}
printf("%lld\n",ans);
}
}
另外这几个样例送给大家debug:
/**
100
8 2 5 1 2 18
8 2 5 1 2 40
8 2 5 1 2 58
8 2 5 1 2 80
8 2 5 1 2 98
*/