-
Notifications
You must be signed in to change notification settings - Fork 0
/
2802.cpp
67 lines (67 loc) · 946 Bytes
/
2802.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
using namespace std;
int b[100000],l,s,t,m,stone[200],num=-1,mins=300,wei[100000];
int jishu(int k)
{
if(stone[wei[k]]==2)
num++;
k=b[k];
if(k>1)
jishu(k);
}
void bfs()
{
int head=0,tail=1;
wei[1]=0;
do
{
head++;
int pan=0;
if(wei[head]==l)
head=tail;
else
{
for(int i=s;i<=t;i++)
{
if(stone[wei[head]+i]==0)
{
pan=1;
tail++;
b[tail]=head;
wei[tail]=wei[head]+i;
if(stone[wei[tail]]==0)
stone[wei[tail]]=1;
}
if(wei[tail]==l)
{
num=0;
jishu(tail);
}
if(num<mins&&num!=-1)
mins=num;
}
if(pan==0)
{
tail++;
wei[tail]=wei[head]+t;
b[tail]=head;
if(stone[wei[tail]]==0)
stone[wei[tail]]=1;
}
}
}
while(head<tail);
}
int main()
{
int a;
cin>>l>>s>>t>>m;
for(int i=1;i<=m;i++)
{
cin>>a;
stone[a]=2;
}
bfs();
cout<<mins;
return 0;
}