比赛 防止浮躁的小练习v0.7 评测结果 AAAAAAAAAA
题目名称 零食店 最终得分 100
用户昵称 _Itachi 运行时间 2.538 s
代码语言 C++ 内存使用 3.80 MiB
提交时间 2016-10-27 14:27:30
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=101,INF=(int)1e9;
char chh,ch[10];int xxx;
int _read(){
    while(chh=getchar(),chh<'!');xxx=chh-48;
    while(chh=getchar(),chh>'!')xxx=xxx*10+chh-48;
    return xxx;
}
void _write(int x){
	xxx=0;
	while(ch[++xxx]=x%10+48,x/=10);
	while(putchar(ch[xxx]),--xxx);
	putchar('\n');
}
int n,m,qcot,th[maxn],f[maxn][maxn][maxn];
struct Rabit_th{int num,v;}c[maxn];
bool Rabit_comp(Rabit_th a,Rabit_th b){return a.v<b.v;}
int Rabit_min(int x,int y){return x<y?x:y;}
void Rabit_in(){
	//scanf("%d%d%d",&n,&m,&qcot);
	n=_read(),m=_read(),qcot=_read();
	int i,x,y,z;
	for(i=1;i<=n;i++)//scanf("%d",&c[i].v),
	c[i].v=_read(),c[i].num=i;
	sort(c+1,c+n+1,Rabit_comp);
	memset(f,0x3f,sizeof(f));
	for(i=1;i<=n;i++)th[i]=c[i].num,f[0][i][i]=0;
	while(m--)
		//scanf("%d%d%d",&x,&y,&z),
		x=_read(),y=_read(),z=_read(),
		f[0][x][y]=f[0][y][x]=Rabit_min(f[0][x][y],z);
}
void Rabit_run(){
	int i,j,k;
	for(k=1;k<=n;k++)
	for(i=1;i<=n;i++)
	for(j=1;j<=n;j++)
		f[k][i][j]=Rabit_min(f[k-1][i][j],f[k-1][i][th[k]]+f[k-1][th[k]][j]);
	for(k=0;k<=n;k++)
	for(i=1;i<=n;i++)
		sort(f[k][i]+1,f[k][i]+n+1);
/*	
	for(k=0;k<=n;k++){
		printf("k=%d\n",k);
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++)printf("%d ",f[k][i][j]);
			putchar('\n');
		}
		putchar('\n');	
	}
*/
}
int Rabit_get(int x){
	int l=0,r=n+1,mid;
	while(l^r){
		mid=(l+r)>>1;
		if(c[mid].v<=x)l=mid+1;
		else r=mid;	
	}
	return l-1;
}
void Rabit_out(){
	int s,v,d,k,l,r,mid;
	while(qcot--){
		s=_read(),v=_read(),d=_read();
		if(d>INF){
			//printf("%d\n",n-1);
			_write(n-1);
			continue;
		}
		//scanf("%d%d%d",&s,&v,&d);
		k=Rabit_get(v);//printf("k=%d\n",k);
		l=1,r=n+1;
		while(l^r){
			mid=(l+r)>>1;
			if(f[k][s][mid]<=d)l=mid+1;
			else r=mid;	
		}
		_write(l-2);
		//printf("%d\n",l-2);
	}	
}
void Rabit_main(){
	Rabit_in();Rabit_run();Rabit_out();
}
int main(){
#define _Rabit _RABIT
#ifdef _Rabit
	freopen("snackstore.in","r",stdin);
	freopen("snackstore.out","w",stdout);
#endif
	Rabit_main();
#ifndef _Rabit
	getchar(),getchar();
#endif
	fclose(stdin);fclose(stdout);
	return 0;
}