90分 WA on test1 求助
  • 板块P3403 跳楼机
  • 楼主kradcigam
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/8/21 21:32
  • 上次更新2023/11/4 09:45:06
查看原帖
90分 WA on test1 求助
180242
kradcigam楼主2021/8/21 21:32

zbl

#include<bits/stdc++.h>
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define LL unsigned long long
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define DF(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
inline LL read(){char ch=getchar(); LL w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
const int N=1e6+10;
LL f[N],ans;
bool inque[N];
queue<int>q;
signed main(){
	LL h=read();
	int k=read(),y=read(),z=read();
    if(k>y)swap(k,y);
    if(k>z)swap(k,z);
    F(i,0,k-1)f[i]=h+1;
    // ms(f,0x3f);
	f[1]=1;
	inque[1]=true;
	q.push(1);
	while(q.size()){
		int x=q.front();q.pop();
        inque[x]=false;
        int a=(x+y)%k;
        if(f[x]+y<f[a]){
            f[a]=f[x]+y;
            if(!inque[a]){
                inque[a]=true;
                q.push(a);
            }
        }
        int b=(x+z)%k;
        if(f[x]+z<f[b]){
            f[b]=f[x]+z;
            if(!inque[b]){
                inque[b]=true;
                q.push(b);
            }
        }
	}
    F(i,0,k-1)
        if(f[i]<=h)ans+=(h-f[i])/k+1;
    cout<<ans;
	return 0;
}

大体思路就是同余最短路,跑SPFA。

2021/8/21 21:32
加载中...