Title: http://www.lydsy.com/JudgeOnline/problem.php?id=2118
The puzzle: Consider whether X can be achieved in the sense of a certain number of modules. With the smallest number as modulus, so long as the map to run the shortest way can be statistical answer.
Code:
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>Ten#include <queue> One#include <string> A #defineINF 1000000000000LL - #defineMAXN 500000+5 - #defineMAXM 8000000+5 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) at #defineMoD 1000000007 - #defineLCH T[k].l,l,mid - #defineRCH T[k].r,mid+1,r - using namespacestd; - inline ll read () - { inll x=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} to while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} + returnx*F; - } the intn,head[maxn],mx=1000000, TOT,A[MAXN]; * ll L,R,D[MAXN]; $ BOOLV[MAXN];Panax Notoginsengqueue<int>Q; - structedge{intGo,next,w;} E[MAXM]; theInlinevoidAddintXintYintW) + { AE[++tot]= (Edge) {y,head[x],w};head[x]=tot; the } + Inline ll work (ll x,ll y,ll z) - { $ returnX<y?0:(x-y)/z+1; $ } - intMain () - { theFreopen ("Input.txt","R", stdin); -Freopen ("output.txt","W", stdout);WuyiN=read (); L=read (); r=read (); theFor1 (I,n) A[i]=read (), mx=min (mx,a[i]); -For1 (i,n) for0 (j,mx-1) Add (J, (J+a[i])%mx,a[i]); WuFor0 (i,mx-1) d[i]=inf; -d[0]=0; Q.push (0); About while(!q.empty ()) $ { - intX=q.front (); Q.pop (); v[x]=0; -For4 (i,x)if(d[x]+e[i].w<D[y]) - { Ad[y]=d[x]+(ll) e[i].w; + if(!v[y]) {v[y]=1; Q.push (y);} the } - } $ll ans=0; theFor0 (i,mx-1) ans+=work (R,D[I],MX)-work (l1, d[i],mx); thecout<<ans<<Endl; the return 0; the}
View Code
BZOJ2118: Ink and ink equation