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

你做复杂了

Posted by xfxyjwf at 2006-03-26 10:28:43
In Reply To:2674 做得我都没有信心了,那个牛人帮看一下 Posted by:fjctlzy at 2006-03-26 09:44:31
//直接贴CODE了:)

#include<iostream>
#include<string>
#include<iomanip>

using namespace std;
struct mode{
	string name;
	float pos;
	char direct;
};

mode a[32001];
int main(){
	int num;
	int i;
	string lastOne;
	float lastTime=0;
	float l,v;
	float maxTime=0;
	float s,t;
	char direct;

  while(cin>>num&&num!=0){
	cin>>l>>v;
	//input the data
    for (int k=1;k<=num;k++){
     cin>>a[k].direct>>a[k].pos>>a[k].name;  
	 if (a[k].direct=='P') a[k].direct='p';
	 if (a[k].direct=='N') a[k].direct='n';
	}
	maxTime= - 1.0;	
	//caltulate the s
	for (i=1;i<=num;i++) {
		if (a[i].direct=='p'){
		   s=l-a[i].pos;
		}
		else s=a[i].pos;
		 
		t=s/v;
		if (maxTime<t) {
			maxTime=t;
			direct=a[i].direct;
		}
		//to see the maxtime
		//and the final direct
	}    
    int c=0,b=0;
	//work out the total towards right and towards left
	//which b stands for right and c stands for left
	for (i=1;i<=num;i++)
		if (a[i].direct=='p') b++;
	c=num-b;
	if (direct=='p'){
		lastOne = a[c+1].name;
	}
	else {
		lastOne = a[c].name;
	}
/*
    lastTime=0;
	for (i=1;i<=num;i++){
		if (a[i].finalDirect==direct)
			if (lastTime<a[i].time){
				lastTime=a[i].time;
				lastOne=a[i].name;
			}
	}
	*/
	//to truncated the time 
	// take 987.568 for example 
	maxTime = (int)(maxTime * 100) / 100.0;
	cout<<setiosflags(ios::fixed)<<setprecision(2)<<setw(13)<<maxTime;
	cout<<" "<<lastOne<<endl;
  }
	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