2018 ACM-ICPC 亚洲青岛区域赛 J题 Press the Button

当时开这道题的时候已经只剩最后一个小时了,有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
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值