社区讨论
为什么样例1过不了AC了
P3403跳楼机参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @loc2zhn9
- 此快照首次捕获于
- 2023/10/30 07:07 2 年前
- 此快照最后确认于
- 2023/11/04 13:08 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
#define rep(l,a,b) for(int l=a;l<=b;l++)
#define repp(l,a,b) for(int l=a;l>=b;l--)
#define mem(x) memset(x,0,sizeof(x))
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define mp make_pair
#define ll long long
const int N = 5e5 + 5;
const int M = 5e6 + 5;
const ll MOD = 100003;
const ll INF = 1e9;
inline ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
void read(ll& x) {
ll f = 1; x = 0; char s = getchar();
while (s < '0' || s>'9') { if (s == '-')f = -1; s = getchar(); }
while (s >= '0' && s <= '9') { x = x * 10 + s - '0'; s = getchar(); }
x *= f;
}
ll t, h, a[10];
ll cnt, head[N], dis[N], vis[N];
struct no
{
ll to, next, w;
}e[M];
void add(int u, int v, int w)
{
cnt++;
e[cnt].to = v;
e[cnt].w = w;
e[cnt].next = head[u];
head[u] = cnt;
}
struct node
{
ll num;
ll dis;
bool operator <(const node& no) const
{
return dis > no.dis;
}
};
void dij(int k)
{
mem(vis);
priority_queue<node>pq;
memset(dis, 0x3f, sizeof(dis));
dis[k] = 1;
pq.push(node{ k,0 });
while (!pq.empty())
{
node tmp = pq.top();
pq.pop();
ll u = tmp.num;
if (vis[u])
continue;
vis[u] = 1;
for (int i = head[u]; i; i = e[i].next)
{
ll v = e[i].to;
if (dis[v] > dis[u] + e[i].w)
{
dis[v] = dis[u] + e[i].w;
if (!vis[v])
pq.push(node{ v,dis[v] });
}
}
}
return;
}
int main()
{
cin >> h;
rep(i, 1, 3)
cin >> a[i];
rep(i, 1, 3)
if (a[i] == 1)
{
cout << h << endl;
return 0;
}
for (int i = 0; i < a[1]; i++)
for (int j = 2; j <= 3; j++)
add(i, (i + a[j]) % a[1], a[j]);
dij(1);
ll ans = 0;
for (int i = 0; i < a[1]; i++)
if (h > dis[i])
ans += (h - dis[i]) / a[1] + 1;
cout << ans << endl;
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...