Advertisement
Guest User

RIO

a guest
Apr 24th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. // Bismillahirrahmanirrahim
  2. // AgriCoder IPB
  3.  
  4.  
  5. #include<bits/stdc++.h>
  6.  
  7. using namespace std;
  8.  
  9. #define FOR(i, agri, coder) for (int i = (int)agri; i <= (int)coder; i++)
  10. #define REP(agri,coder) for (int agri = 0; agri < (int)coder; agri++)
  11. #define FOREACH(i,agricoder) for (typeof((agricoder).end()) i = (agricoder).begin(); i != (agricoder).end(); ++i)
  12. #define RESET(agri,coder) memset(agri, coder, sizeof(agri))
  13. #define pb push_back
  14. #define mp make_pair
  15. #define EPS 1e-9
  16. #define INF 0x3F3F3F3F
  17.  
  18. typedef long long ll;
  19. typedef pair<int,int> ii;
  20. typedef vector<int> vi;
  21.  
  22. #define MAX (int)(1e+5) + 5
  23.  
  24. double d[MAX],d_accu[MAX],t[MAX],v[MAX];
  25. double ans[MAX];
  26. int parent[MAX];
  27.  
  28. int main() {
  29.  
  30. int n,j;
  31.  
  32. d_accu[0]=0;
  33.  
  34. scanf("%d",&n);
  35.  
  36. FOR(i,1,n-1){
  37. scanf("%lf",&d[i]);
  38. d_accu[i]=d[i]+d_accu[i-1];
  39. }
  40.  
  41. FOR(i,1,n-1){
  42. scanf("%lf %lf",&t[i],&v[i]);
  43. }
  44.  
  45. ans[1]=d[1]/v[1]+ t[1];
  46. parent[1]=0;
  47. FOR(i,2,n-1){
  48. ans[i]=t[i]+d_accu[i]/v[i];
  49. j=i-1;
  50.  
  51. double tmp=ans[j]+t[i]+(d_accu[i]-d_accu[j])/v[i];
  52. if(ans[i]>tmp){
  53. parent[i]=j;
  54. ans[i]=tmp;
  55. }
  56.  
  57. for(j=parent[i-1];j>0;j--){
  58. tmp=ans[j]+t[i]+(d_accu[i]-d_accu[j])/v[i];
  59. if(ans[i]>tmp){
  60. parent[i]=j;
  61. ans[i]=tmp;
  62. }
  63. }
  64. }
  65.  
  66. double frac,intpart;
  67.  
  68. FOR(i,1,n-1){
  69. // printf("real: %.5lf, floor: %.5lf, integer: %.0lf\n",ans[i],floor(ans[i]),ans[i]);
  70. /*
  71. frac = modf (ans[i] , &intpart);
  72. if(frac<=0.50000) ans[i]=floor(ans[i]);
  73. else ans[i]=ceil(ans[i]);
  74. */ printf("%.0lf\n",ans[i]);
  75. }
  76.  
  77. return 0;
  78. }
  79.  
  80. // Alhamdulillahirabbilalamin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement