Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:不知道WA了多少次了,求大神

Posted by fengyucan at 2019-07-29 21:55:39 on Problem 1860
In Reply To:不知道WA了多少次了,求大神 Posted by:1265170408 at 2016-05-17 20:22:19
> #include<cstdio>
> #include<cstring>
> using namespace std;
> const int maxn=105;
> int n,m,s;
> double cost[maxn][maxn],dist[maxn],d[maxn][maxn],v;
> int vis[maxn][maxn];
> int main()
> {	scanf("%d %d %d %lf\n",&n,&m,&s,&v);
> 	memset(dist,0,sizeof(dist));
> 	memset(vis,0,sizeof(vis));
> 	for (int i=1; i<=m; ++i)
> 	{
> 		int x,y;
> 		scanf("%d %d",&x,&y); 
> 		scanf("%lf %lf %lf %lf\n",&d[x][y],&cost[x][y],&d[y][x],&cost[y][x]);
> 		vis[x][y]=1; vis[y][x]=1;
> 	}
> 	int vis1[maxn];
> 	int sum[maxn];
> 	memset(sum,0,sizeof(sum));
> 	memset(vis1,0,sizeof(vis1));
>     int head=0,tail=1;
> 	int q[maxn]; 
> 	memset(q,0,sizeof(q));	
> 	q[1]=s; vis1[s]=1; dist[s]=v; 
>     while (head<tail)
>     {
>     	head++;
>     	int x=q[head];
>     	vis1[x]=0;
>     	sum[x]++;
>     	if (sum[x]>n) break;
>     	for (int i=1; i<=n; ++i)
>     	 if (vis[x][i] && dist[i]<(dist[x]-cost[x][i])*d[x][i])
>     	  {
>     	  	dist[i]=(dist[x]-cost[x][i])*d[x][i];
>     	    if (!vis1[i])
>     	    {
>     	    	tail++;
>     	    	q[tail]=i;
>     	    	vis1[i]=1;
> 			}
> 		  }
> 	}
> 	if (dist[s]>v) printf("%s\n","YES");
> 	          else printf("%s\n","NO");
> }
你试一试我的代码:
#include<cstdio>
#include<cstring>
const int N=220;
struct node{
	int x,y;
	double yo,hu;
};
node data[N];
int n,m,s,a,b;
double v,ay,al,by,bl,f[N];
bool f1;
int main(){
	freopen("poj1860.in","r",stdin);
	
	scanf("%d%d%d%lf",&n,&m,&s,&v);
	//printf("%d %d %d %lf\n",n,m,s,v);
	for(int i=1;i<=m;++i){
		scanf("%d%d%lf%lf%lf%lf",&a,&b,&ay,&al,&by,&bl);
		//printf("%d %d %lf %lf %lf %lf\n",a,b,ay,al,by,bl);
		
		data[2*i-1].x=a;data[2*i-1].y=b;data[2*i-1].yo=ay;data[2*i-1].hu=al;
		data[2*i].x=b;data[2*i].y=a;data[2*i].yo=by;data[2*i].hu=bl;
		/*
		printf("%d %d %lf %lf\n",data[2*i-1].x,data[2*i-1].y,data[2*i-1].yo,data[2*i-1].hu);
		printf("%d %d %lf %lf\n",data[2*i].x,data[2*i].y,data[2*i].yo,data[2*i].hu);
		*/
	}
	
	for(int i=1;i<=n;++i) f[i]=0x7fffffff*(-1);
	f[s]=v;
	//printf("%lf %lf",f[2],f[1]);
	for(int i=1;i<n;++i){
		f1=false;
		for(int j=1;j<=2*m;++j){
			if((f[data[j].x]-data[j].hu)*data[j].yo>f[data[j].y] and f[data[j].x]!=0x7fffffff*(-1)){
				f[data[j].y]=(f[data[j].x]-data[j].hu)*data[j].yo;
				f1=true;
			}
		}
		if(!f1) break;
	}
	f1=false;
	for(int j=1;j<=2*m;++j){
		if((f[data[j].x]-data[j].hu)*data[j].yo>f[data[j].y] and f[data[j].x]!=0x7fffffff*(-1)){
			f[data[j].y]=(f[data[j].x]-data[j].hu)*data[j].yo;
			f1=true;
		}
	}
	if(f1) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator