比赛 |
NOIP模拟赛by mzx Day1 |
评测结果 |
AAAAWAWTTT |
题目名称 |
零食店 |
最终得分 |
50 |
用户昵称 |
_Itachi |
运行时间 |
4.323 s |
代码语言 |
C++ |
内存使用 |
2.82 MiB |
提交时间 |
2016-10-19 21:48:03 |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<queue>
using namespace std;
int _read(){int ret,neg;char ch;ret=neg=0;while(!isdigit(ch=getchar())&&ch!='-');if(ch=='-')neg=1,ch=getchar();while(ret=ret*10+ch-'0',isdigit(ch=getchar()));if(neg)ret=-ret;return ret;}
const int maxn=105,maxm=10005,INF=0x3f3f3f3f;
int _max(int a,int b){return a>b?a:b;}
int _min(int a,int b){return a<b?a:b;}
int n,m,qt,dis[maxn][maxn][maxn],h[maxn],len=1,head[maxn];
struct _c{int c,num;}c[maxn];
bool _compc(_c a,_c b){return a.c<b.c;}
bool _compn(_c a,_c b){return a.num<b.num;}
void _in(){
//scanf("%d%d%d",&n,&m,&qt);
n=_read(),m=_read(),qt=_read();
int i,x,y,z,tmp;
for(i=1;i<=n;i++)c[i].c=_read(),c[i].num=i;
sort(c+1,c+n+1,_compc);
memset(dis,0x3f,sizeof(dis));
for(i=1;i<=n;i++)h[i]=c[i].c,c[i].c=i,dis[i][i][0]=0;
sort(c+1,c+n+1,_compn);
while(m--){
x=_read(),y=_read(),z=_read();
dis[x][y][0]=dis[y][x][0]=_min(dis[x][y][0],z);
}
}
void _run(){
int s,i,j,k,mix,miy;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)if(i^k)
for(j=1;j<=n;j++)if(i^j&&j^k){
mix=INF,miy=INF;
for(s=0;s<=n;s++){
mix=_min(dis[i][k][s],mix),miy=_min(dis[k][j][s],miy);
if(s>=c[k].c)dis[i][j][s]=_min(dis[i][j][s],mix+miy);
}
}
for(s=1;s<=n;s++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
dis[s][i][j]=_min(dis[s][i][j],dis[s][i][j-1]);
}
void _out(){
int l,r,mid,x,d,v,cnt,rt,k,i;
while(qt--){
rt=_read(),v=_read(),d=_read();
l=0,r=n;cnt=0;
while(l^r){
mid=(l+r)>>1;
if(h[mid]<=v)l=mid+1;
else r=mid;
}
k=l-1;
for(i=1;i<=n;i++)
if(dis[rt][i][k]<=d)cnt++;
printf("%d\n",cnt-1);
}
}
void _work(){
memset(dis,0x3f,sizeof(dis));
_in();
_run();_out();
}
bool _Rabit(),_RABIT=_Rabit();int main(){;}
bool _Rabit(){
#define _Rabit _RABIT
#ifdef _Rabit
freopen("snackstore.in","r",stdin);
freopen("snackstore.out","w",stdout);
#endif
_work();
#ifndef _Rabit
getchar(),getchar();
#endif
fclose(stdin);fclose(stdout);
}