114! why me not ac

All about problems in Volume I. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

114! why me not ac

Postby Hobby » Thu Jul 29, 2010 2:39 pm

the code as follows, but the judge tell me Time limit exceeded
Code: Select all
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
   //ifstream cin("114.txt");
   int edges[52][52];
   int costs[52][52];
   int values[52][52];
   int wallCost;
   int m,n,p;
   cin>>m>>n;
   cin>>wallCost;
   cin>>p;
   for(int i=0;i<m;i++){
      edges[i][1]=-1;
      edges[i][n]=-1;
   }
   for(int i=0;i<n;i++){
      edges[1][i]=-1;
      edges[n][i]=-1;
   }//  init the edges

   int x,y,value,cost;
   for(int i=0;i<p;i++){
      scanf("%d%d%d%d",&x,&y,&value,&cost);
      //cin>>x>>y>>value>>cost;
      edges[n-y+1][x]=1;
      values[n-y+1][x]=value;
      costs[n-y+1][x]=cost;
   }
   int zx,zy,dir,leftTime;
   int sumPoint=0;
   while(scanf("%d%d%d%d",&zx,&zy,&dir,&leftTime)!=EOF){//cin>>zx>>zy>>dir>>leftTime
      if(zx==0) break;
      int  totalPoints=0;
      x=n-zy+1;
      y=zx;
      if(cin.eof()) break;
      while(leftTime>0){
         leftTime-=1;
         if(leftTime<1) break;
         
         int xnew,ynew;
         switch(dir){
            case 0:
               xnew=x;ynew=y+1;break;
            case 1:
               xnew=x-1;ynew=y;break;
            case 2:
               xnew=x;ynew=y-1; break;
            case 3:
               xnew=x+1;ynew=y; break;
         }
         if(edges[xnew][ynew]!=0){
            if(edges[xnew][ynew]==1) {totalPoints+=values[xnew][ynew];}
            switch(dir){
               case 0:
                  dir=3;break;
               case 1:
                  dir=0;break;
               case 2:
                  dir=1; break;
               case 3:
                  dir=2; break;
         }
            if(edges[xnew][ynew]==1) leftTime-=costs[xnew][ynew];
            else leftTime-=wallCost;

         }
         else{
            x=xnew;
            y=ynew;

         }
      }
      cout<<totalPoints<<endl;
      sumPoint+=totalPoints;
   }
   cout<<sumPoint<<endl;

}



so, who can help me?
TKS :D
Hobby
New poster
 
Posts: 4
Joined: Thu Jul 29, 2010 2:35 pm

Re: 114! why me not ac

Postby sohel » Thu Jul 29, 2010 5:39 pm

Search the board first. There are already other discussions related to problem #114. Make your post in an existing thread.
User avatar
sohel
Guru
 
Posts: 862
Joined: Thu Jan 30, 2003 5:50 am
Location: University of Texas at San Antonio

Re: 114! why me not ac

Postby Hobby » Fri Jul 30, 2010 2:23 am

thanks,I will search the same disscuss
Hobby
New poster
 
Posts: 4
Joined: Thu Jul 29, 2010 2:35 pm


Return to Volume I

Who is online

Users browsing this forum: No registered users and 1 guest