标签:blog io ar for 数据 div sp 代码 log
input: | output:
-----------------------------------
1 1 3 | 2
-----------------------------------
1 2 10 | 5
#include "cstdio"
int a,b,n,i,p,f[60];
bool h[80];
int main(){
freopen("seq2.in","r",stdin);
freopen("seq2.out","w",stdout);
scanf("%d%d%d",&a,&b,&n);
a%=7;
b%=7;
f[1]=f[2]=1;
h[9]=true;
for(i=3;i<52;++i){
f[i]=(a*f[i-1]+b*f[i-2])%7;
if(n==i){
printf("%d\n",f[i]);
return 0;
}
if(h[f[i]*8+f[i-1]]){
p=i-2;
break;
}else{
h[f[i]*8+f[i-1]]=true;
}
}
printf("%d\n", f[(n-1)%p+1]);
return 0;
}
input: | output:
-----------------------------------
2 1 |
1 2 1 | 2
#include <cstdio>
int next[70000],to[70000],hl,head[3000],le[70000];
inline void addEdge(int f,int t,int v){
++hl;
next[hl]=head[f];
to[hl]=t;
le[hl]=v;
head[f]=hl;
}
int i,j,k,l,a,b,c,m,n;
int qh,qt,q[600000],f[3000];
bool iq[3000],vis[3000];
void spfa(){
vis[1]=iq[1]=true;
qt=2;
qh=1;
q[1]=1;
while(qh!=qt){
i=q[qh];
iq[i]=false;
for(j=head[i];j!=0;j=next[j]){
vis[k=to[j]]=true;
l=le[j];
if(f[i]+l>f[k]){
f[k]=f[i]+l;
if(!iq[i]){
iq[i]=true;
q[qt++]=k;
}
}
}
++qh;
}
}
int main(int argc, char const *argv[]){
freopen("path.in","r",stdin);
freopen("path.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=0;i<m;++i){
scanf("%d%d%d",&a,&b,&c);
addEdge(a,b,c);
}
spfa();
if(!vis[n]){
printf("-1\n");
}else{
printf("%d\n", f[n]);
}
return 0;
}
标签:blog io ar for 数据 div sp 代码 log
原文地址:http://www.cnblogs.com/tmzbot/p/3971394.html