Advertisement
adwas33

Untitled

Aug 28th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. long double wariant1(int n,short int pierwszex,short int pierwszey)
  7. {
  8. if(n==0)
  9. {
  10. return sqrt(pierwszex*pierwszex+pierwszey*pierwszey);
  11. }
  12.  
  13. short int x[5];
  14. short int y[5];
  15. x[0]=pierwszex;
  16. y[0]=pierwszey;
  17. short int pluscalkowitax,pluscalkowitay,minuscalkowitax,minuscalkowitay;
  18. if(x[0]>=0)
  19. {
  20. pluscalkowitax+=x[0];
  21. }
  22. else minuscalkowitax+=x[0];
  23. if(y[0]>=0)
  24. {
  25. pluscalkowitay+=y[0];
  26. }
  27. else minuscalkowitay+=y[0];
  28.  
  29. while(n!=0)
  30. {
  31. cin>>x[n];
  32. if(x[n]>=0)
  33. {
  34. pluscalkowitax+=x[n];
  35. }
  36. else minuscalkowitax+=x[n];
  37.  
  38. cin>>y[n];
  39. if(y[n]>=0)
  40. {
  41. pluscalkowitay+=y[n];
  42. }
  43. else minuscalkowitay+=y[n];
  44.  
  45.  
  46. }
  47. if (pluscalkowitax+pluscalkowitay==2)
  48. {
  49. return sqrt(pluscalkowitax*pluscalkowitax+pluscalkowitay*pluscalkowitay);
  50. }
  51. if (minuscalkowitax+minuscalkowitay==-2)
  52. {
  53. return sqrt(minuscalkowitax*minuscalkowitax+minuscalkowitay*minuscalkowitay);
  54. }
  55. if (minuscalkowitax+pluscalkowitay==-1||minuscalkowitay+pluscalkowitay==1)
  56. {
  57. return 1;
  58. }
  59. if(minuscalkowitax==0&&minuscalkowitay==0&&pluscalkowitax==0&&pluscalkowitay==0)
  60. {return 0;}
  61. }
  62. long double wariant2(int n,short int pierwszex,short int pierwszey)
  63. {
  64. long double calkowitax=pierwszex,calkowitay=pierwszey;
  65. short int kolejnex,kolejney;
  66.  
  67. while(n!=0)
  68. {
  69. cin>>kolejnex;
  70. calkowitax+=kolejnex;
  71. cin>>kolejney;
  72. calkowitay+=kolejney;
  73.  
  74.  
  75. n--;
  76. }
  77.  
  78. return sqrt(calkowitax*calkowitax+calkowitay*calkowitay);
  79.  
  80. }
  81. long long wariant3(int n,short int pierwszex,short int pierwszey)
  82. {
  83. long long calkowitax=pierwszex,calkowitay=pierwszey;
  84. short int kolejnex,kolejney;
  85.  
  86. while(n!=0)
  87. {
  88. cin>>kolejnex;
  89. calkowitax+=kolejnex;
  90. cin>>kolejney;
  91. calkowitay+=kolejney;
  92.  
  93.  
  94. n--;
  95.  
  96. }
  97. return sqrt(calkowitax*calkowitax+calkowitay*calkowitay);
  98.  
  99. }
  100. struct ruch{
  101. short int x;
  102. short int y;
  103.  
  104. };
  105.  
  106. int main()
  107. {
  108. int n;
  109. cin>>n;
  110. ruch wektor;
  111.  
  112. cin>>wektor.x;
  113. cin>>wektor.y;
  114. n=n-1;
  115. if(wektor.x==0||wektor.y==0)
  116. {
  117. cout<<wariant1(n,wektor.x,wektor.y)*wariant1(n,wektor.x,wektor.y);
  118.  
  119. }
  120. else if(wektor.x==-1&&wektor.y==-1)
  121. {
  122. cout<<(long long)(wariant2(n,wektor.x,wektor.y)*wariant2(n,wektor.x,wektor.y));
  123.  
  124. }
  125. else
  126. { cout<<(long long)(wariant3(n,wektor.x,wektor.y)*wariant3(n,wektor.x,wektor.y));
  127. return 0;
  128.  
  129. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement