|
|
#include <string> #include <iostream> #include <algorithm> #include <iomanip> #include <math.h> using namespace std; int main() { double n, t, s; cin >> n >> t >> s; double opposite[1000]; for (int i = 0; i < n; i++) { cin >> opposite[i]; if (opposite[i] >= s) { cout << fixed << setprecision(6) << ((opposite[i] + (s + t)) / 2) << endl; } else { cout << fixed << setprecision(6) << ((s + (opposite[i] + t)) / 2) << endl; } }
} System.out.printf("%.6f\n",(t+s+ss[i])/2d); It have solution with no arrays, lol) And (t+x+si)/2.0 right too, but some simply) I know, that my English bad( Edited by author 10.01.2016 23:58 #include <iostream> #include <cstdio> using namespace std; int main(int argc, char **argv) { int n, t; double *gandolas, *res; double s; cin >> n >> t >> s; gandolas = new double[n]; res = new double[n]; for(int i=0; i<n; i++)cin >> gandolas[i];
for(int i=0; i<n; i++){ if(i==0) if(gandolas[i] >= s){ res[i] = s + (t-(gandolas[i] - s))/2; s = res[i]; } else{ res[i] = s + (t-(s - gandolas[i]))/2; s = res[i]; } else{ res[i] = s + (gandolas[i] - gandolas[i-1])/2; s = res[i]; } } for(int i=0; i<n; i++)printf("%.6lf\n", res[i]); return 0; } can't imagine a test that make it crash Edited by author 03.07.2013 00:29 #include<iostream> #include<cmath> #include<iomanip> using namespace std; int main() { double *a,*d; int n,t,s,i; float temp; cin>>n; if(n>=1 && n<=100) { cin>>t; if(t>=1 && t<=100) { cin>>s; if(s>= 360 && s<=1200) { a = new double[n]; d = new double[n]; for(i=0;i<n;i++) { cin>>a[i]; if(i==1) { if(a[i] <= a[i-1]) { return 0; } }
}
for(i=0;i<n;i++) { temp = t/n; if(s == a[i]) { d[i] = a[i]+temp; } else if(s < a[i]) { temp = temp/n; d[i] = a[i]+temp; }
} cout.setf(ios::showpoint); for(i=0;i<n;i++) { cout<<d[i]<<0<<0<<0<<endl; } } else { return 0; } return 0;} return 0;}
return 0; } First of all, you don't have to check if the input is correct, so the following lines are useless: if(n>=1 && n<=100) if(t>=1 && t<=100) if(s>= 360 && s<=1200) if(i==1) //this is wrong - I think the that the condition is i>=1 { if(a[i] <= a[i-1]){ return 0; } } Then, n has nothing to do with t. So temp=t/n is not ok. (try: 3 60 600 600 630 631 to see why). Imagine that you have 4 points: A,B,C,D. The distance (in time) between them is as it follows: B-A=s ,C-B=t, D-C=sn. So two gondolas that have the same speed, would meet in the point (A+D)/2. Also, you may want to check http://www.cplusplus.com/reference/ios/ios_base/precision/ to see how you can set the floating-point precision. That is (s+t+sn)/2. |
|
|