d1i2p3a4k5

codevita catch22

Aug 28th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. int main()
  5. {
  6. int F,B,BD,FD,T,N,cpos=0,npos=0,time=0,flag=0,disp=0,i,j;
  7. int tests[100][5];
  8.  
  9. scanf("%d",&N);
  10. for(i=0;i<N;i++)
  11. {
  12. for(j=0;j<5;j++)
  13. {
  14. scanf("%d",&(tests[i][j]));
  15. }
  16. }
  17.  
  18. for(i=0;i<N;i++)
  19. {
  20. F=tests[i][0];
  21. B=tests[i][1];
  22. T=tests[i][2];
  23. FD=tests[i][3];
  24. BD=tests[i][4];
  25. time=0;
  26. disp=0;
  27. cpos=0;
  28. npos=0;
  29. flag=0;
  30. if(F==B)
  31. {
  32. cpos=F;
  33. if(FD<=cpos)
  34. {
  35. time= time+FD*T;
  36. printf("%d F\n",time);
  37. }
  38. else if(BD<=cpos)
  39. {
  40. time=time+BD*T+F*T;
  41. printf("%d B\n",time);
  42. }
  43. else
  44. {
  45. printf("No Ditch\n");
  46. }
  47. }
  48. else
  49. {
  50. while(flag==0)
  51. {
  52. npos=cpos+F;
  53. if(cpos<FD && FD <=npos)
  54. {
  55. disp=FD-cpos;
  56. time=time+disp*T;
  57. printf("%d F\n",time);
  58. flag=1;
  59. }
  60. time=time+F*T;
  61. cpos=npos-B;
  62. if(BD<=abs(cpos) && abs(npos)<BD)
  63. {
  64. disp=BD-abs(npos);
  65. time=time+disp*T;
  66. printf("%d B\n",time);
  67. flag=1;
  68. }
  69. time=time+B*T;
  70. }
  71. }
  72. }
  73. getch();
  74. return -1;
  75. }
Add Comment
Please, Sign In to add comment