# BZOJ2118: 墨墨的等式

 1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000000ll
13 #define maxn 500000+5
14 #define maxm 8000000+5
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=(n);i++)
19 #define for1(i,n) for(int i=1;i<=(n);i++)
20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
23 #define mod 1000000007
24 #define lch t[k].l,l,mid
25 #define rch t[k].r,mid+1,r
26 using namespace std;
28 {
29     ll x=0,f=1;char ch=getchar();
30     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
31     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
32     return x*f;
33 }
35 ll l,r,d[maxn];
36 bool v[maxn];
37 queue<int>q;
38 struct edge{int go,next,w;}e[maxm];
39 inline void add(int x,int y,int w)
40 {
42 }
43 inline ll work(ll x,ll y,ll z)
44 {
45     return x<y?0:(x-y)/z+1;
46 }
47 int main()
48 {
49     freopen("input.txt","r",stdin);
50     freopen("output.txt","w",stdout);
54     for0(i,mx-1)d[i]=inf;
55     d[0]=0;q.push(0);
56     while(!q.empty())
57     {
58         int x=q.front();q.pop();v[x]=0;
59         for4(i,x)if(d[x]+e[i].w<d[y])
60         {
61             d[y]=d[x]+(ll)e[i].w;
62             if(!v[y]){v[y]=1;q.push(y);}
63         }
64     }
65     ll ans=0;
66     for0(i,mx-1)ans+=work(r,d[i],mx)-work(l-1,d[i],mx);
67     cout<<ans<<endl;
68     return 0;
69 }
View Code

posted @ 2015-04-02 16:24 ZYF-ZYF Views(...) Comments(...) Edit 收藏