Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 2448 | Accepted: 564 |
Description
Input
Output
Sample Input
1 13.5 2 p 3.5 Smarty 4 10 1 p 1 Helga n 3 Joanna p 5 Venus n 7 Clever 0
Sample Output
5.00 Smarty 9.00 Venus
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 7 using namespace std; 8 9 #define MAX_N 33000 10 11 struct ant { 12 char dir; 13 double pos; 14 string name; 15 }; 16 int N; 17 double L,V; 18 ant s[MAX_N]; 19 double p[MAX_N]; 20 21 void solve() { 22 double t = 0; 23 for(int i = 0; i < N; ++i) { 24 double e; 25 e = (s[i].dir == ‘p‘ || 26 s[i].dir == ‘P‘) ? L : 0.0; 27 t = max(t,fabs(e - s[i].pos)); 28 } 29 30 for(int i = 0; i < N; ++i) { 31 if(s[i].dir == ‘p‘ 32 || s[i].dir == ‘P‘) { 33 p[i] = s[i].pos + t; 34 } else { 35 p[i] = s[i].pos - t; 36 } 37 } 38 39 sort(p,p + N); 40 int pos; 41 for(int i = 0; i < N; ++i) { 42 if(p[i] == 0.0 || p[i] == L) { 43 pos = i; 44 break; 45 } 46 } 47 int t1 = (t / V) * 100; 48 printf("%13.2f ",(double)t1 / 100.0); 49 cout << s[pos].name << endl; 50 51 52 } 53 54 int main() 55 { 56 //freopen("sw.in","r",stdin); 57 58 while(~scanf("%d",&N) && N) { 59 scanf("%lf%lf",&L,&V); 60 for(int i = 0; i < N; ++i) { 61 scanf(" %c%lf",&s[i].dir,&s[i].pos); 62 cin >> s[i].name; 63 64 } 65 66 //printf("%d\n",(int)); 67 68 /*for(int i = 0; i < N; ++i) cout << s[i].dir << " " 69 << s[i].pos << " " 70 << s[i].name << endl;*/ 71 72 solve(); 73 } 74 //cout << "Hello world!" << endl; 75 return 0; 76 }
原文:http://www.cnblogs.com/hyxsolitude/p/3653053.html