救命啊大神,两个WR,一个AC,七个TLE

P1150 Peter 的烟

xiaoxiaozou886 @ 2021-12-26 08:37:23

#include<bits/stdc++.h>
using namespace std;
int a,b,sum,ssum;
int main(){
    cin>>a>>b;
    for(;;){
        ssum=ssum+a/b;
        a=a/b+a%b;
        if(a<4)
            break;
    }
    cout<<ssum+10;
} 

两个WR,一个AC,七个TLE!!!


by 3a51_ @ 2021-12-26 08:41:08

判断条件应该是a<b吧就是不够换新的烟了


by 3a51_ @ 2021-12-26 08:45:04

你试试这个

#include<bits/stdc++.h>
using namespace std;
int a,b,sum,ssum;
int main(){
    cin>>a>>b;
    ssum=a;//最初的a根烟
    for(;;){
        ssum=ssum+a/b;
        a=a/b+a%b;
        if(a<b)
            break;
    }
    cout<<ssum;
} 

|