Advertisement
a53

Furnica1

a53
Mar 11th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. //Roxana Timplaru
  2. #include <fstream>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("furnica.in");
  8. ofstream fout("furnica.out");
  9.  
  10.  
  11.  
  12. int cerinta;
  13. int t_u=5,t_c=2,t_o=3,n,i;
  14. long long s,x1,y1,x2,y2,t,l,maxi;
  15.  
  16. void timp()
  17. {
  18. fin>>n>>x1>>y1;
  19. s=y1*t_u+x1*t_o;
  20. l=y1+x1;
  21. y2=y1;
  22. maxi=l;
  23. for(i=2;i<=n;i++)
  24. {
  25. fin>>x2>>y2;
  26. if (y2>=y1)
  27. {
  28. s=s+(y2-y1)*t_u;
  29. l=l+y2-y1;
  30. }
  31. else
  32. {
  33. s=s+(y1-y2)*t_c;
  34. if (l>maxi)
  35. maxi=l;
  36. l=0;
  37. }
  38. s=s+x2*t_o;
  39. y1=y2;
  40. l=l+x2;
  41. }
  42. s=s+y2*t_c;
  43. if (l>maxi)
  44. maxi=l;
  45. if (cerinta==1)
  46. fout<<s;
  47. else
  48. fout<<maxi;
  49. }
  50.  
  51. void foaie()
  52. { int ok=0;
  53. fin>>n>>t>>x1>>y1;
  54. s=y1*t_u+x1*t_o;
  55. if (s>=t) fout<<1;
  56. else
  57. {
  58. for(i=2;i<=n;i++)
  59. {
  60. fin>>x2>>y2;
  61. if (y2>y1)
  62. {
  63. s=s+(y2-y1)*t_u;
  64. if (s>=t)
  65. { ok=1;
  66. fout<<i;
  67. break;}
  68. }
  69. else
  70. if (y1>y2)
  71. {
  72. s=s+(y1-y2)*t_c;
  73. if (s>=t)
  74. { ok=1;
  75. fout<<i-1;
  76. break;}
  77.  
  78. }
  79.  
  80. s=s+x2*t_o;
  81. y1=y2;
  82. if (s>=t)
  83. {
  84. fout<<i;
  85. ok=1;break;
  86. }
  87. }
  88. s=s+y2*t_c;
  89. if (ok==0)
  90. fout<<n;
  91. }
  92. }
  93.  
  94. int main()
  95. {
  96.  
  97. fin>>cerinta;
  98. if (cerinta==1 || cerinta==2)
  99. timp();
  100. else
  101. foaie();
  102. return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement