| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
2674 做得我都没有信心了,那个牛人帮看一下#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
struct mode{
string name;
float pos;
int left,right;
char direct;
char finalDirect;
float time;
};
int main(){
int num;
string lastOne;
float lastTime=0;
mode a[32001];
float l,v;
int i;
int 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=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;
int suml=0;
int sumr=0;
// to caltulate the num of the left and the num of the right
//of the ith number
for (i=1;i<=num;i++){
a[i].right=c-suml;
a[i].left=sumr;
if (a[i].direct=='n') a[i].right--;
if (a[i].direct=='n') suml++;
else sumr++;
// to see the final direct of
//each element
if (a[i].direct=='p'){
if (a[i].left<a[i].right) a[i].finalDirect='n';
else a[i].finalDirect=a[i].direct;
}
else if (a[i].direct=='n'){
if (a[i].left>a[i].right) a[i].finalDirect='p';
else a[i].finalDirect=a[i].direct;
}
// if (a[i].finalDirect=='p') a[i].time=(l-a[i].pos)/v;
// else if (a[i].finalDirect=='n') a[i].time=a[i].pos/v;
}
float lastPos=0;
// to find the last person 's name
if (direct=='p'){
for (i=1;i<=num;i++){
if (a[i].finalDirect=='p')
if (lastPos<(l-a[i].pos)){
lastPos=l-a[i].pos;
lastOne=a[i].name;
}
}
}
else for (i=1;i<=num;i++){
if (a[i].finalDirect=='n')
if (lastPos<(a[i].pos)){
lastPos=a[i].pos;
lastOne=a[i].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
long tempTime=long(maxTime*100);// stands for 98756
int tempTime1=tempTime%10;//stands for 6
tempTime=tempTime/10;//stands for 9875
int tempTime2=tempTime%10;//stands for 5
cout<<setw(13)<<long(maxTime)<<"."<<tempTime2<<tempTime1;
cout<<" "<<lastOne<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator