Korotkodul

ЗОШ выпуклость многоугольника OK

Jan 10th, 2022 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #include <math.h>
  11. #define pii pair <int,int>
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17. for (auto x: v) cout<<x<<' ';
  18. cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22. for (auto x: v) cout<<x<<' ';
  23. cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28. for (auto x: v) cv(x);
  29. cout<<"\n";
  30. }
  31.  
  32. struct ipn{
  33. ll x,y;
  34. };
  35.  
  36. struct rpn{
  37. db x,y;
  38. };
  39.  
  40. rpn rVec(rpn A, rpn B){
  41. rpn ab;
  42. ab.x = A.x - B.x;
  43. ab.y = A.y - B.y;
  44. return ab;
  45. }
  46.  
  47. ipn iVec(ipn A, ipn B){
  48. ipn ab;
  49. ab.x = B.x - A.x;
  50. ab.y = B.y - A.y;
  51. return ab;
  52. }
  53.  
  54.  
  55. rpn div(rpn A, rpn B, db p, db q){
  56. rpn res;
  57. res.x = (q * A.x + p * B.x) / (p + q);
  58. res.y = (q * A.y + p * B.y) / (p+q);
  59. return res;
  60. }
  61.  
  62. db dot(rpn a, rpn b){
  63. return a.x * b.x + a.y * b.y;
  64. }
  65.  
  66. db lgth(rpn a){
  67. return sqrt(a.x * a.x + a.y * a.y);
  68. }
  69.  
  70. db angl(rpn a, rpn b){
  71. db an = acos(dot(a, b) / ( lgth(a) * lgth(b)) );
  72. return an;
  73. }
  74.  
  75. db rCross(rpn a, rpn b){
  76. return a.y * b.x - a.x * b.y;
  77. }
  78.  
  79. ll iCross(ipn a, ipn b){
  80. return a.y * b.x - a.x * b.y;
  81. }
  82.  
  83. int anglTp(rpn A, rpn B, rpn C){ //возвращает тип угла между AB и AC то есть угла BAC
  84. rpn ab = rVec(A, B);
  85. rpn ac = rVec(A, C);
  86. if (dot(ab, ac) > 0){
  87. return 1; //острый
  88. }
  89. if (dot(ab, ac) == 0){
  90. return 1;//прямой
  91. }
  92. return 2; // тупой
  93. }
  94.  
  95.  
  96.  
  97. db rArea(rpn A, rpn B, rpn C){
  98. rpn ab = rVec(A, B);
  99. rpn ac = rVec(A, C);
  100. return fabs( rCross(ab, ac) ); // 2.0
  101. }
  102.  
  103.  
  104. db hgt(rpn A, rpn B, rpn C){ //height
  105. db h;
  106. //cout<<"rArea(B, A, C) = "<<rArea(B, A, C) <<"\n";
  107. //cout<<"AB = "<<lgth(rVec(A, B))<<"\n";
  108. h = rArea(B, A, C) / lgth( rVec(A, B) );
  109. //cout<<"h = "<<h<<"\n";
  110. if ( anglTp(A, B, C) == 2){
  111. //cout<<"one\n";
  112. return lgth( rVec(C, A) );
  113. }
  114. if (anglTp (B, A, C) == 2){
  115. //cout<<"two\n";
  116. return lgth( rVec(C, B) );
  117. }
  118. return h;
  119. }
  120.  
  121. void mk(rpn &x){
  122. cin>>x.x>>x.y;
  123. }
  124.  
  125. void mk(ipn &x){
  126. cin>>x.x>>x.y;
  127. }
  128.  
  129. db eps = 1e-7;
  130.  
  131. /*int sgn(db x){
  132. if (x > 0.0) return 1;
  133. else if (x == 0.0) return 0;
  134. return -1;
  135. }*/
  136.  
  137. int sgn(ll x){
  138. if (x > 0) return 1;
  139. else if (x == 0) return 0;
  140. return -1;
  141. }
  142.  
  143.  
  144.  
  145. bool eq(rpn A, rpn B){
  146. return A.x == B.x && A.y == B.y;
  147. }
  148.  
  149. bool eq(ipn A, ipn B){
  150. return A.x == B.x && A.y == B.y;
  151. }
  152.  
  153. bool rInter(rpn A, rpn B, rpn C, rpn D){
  154. if (eq(A,C) || eq(A,D ) || eq(B, C) || eq(B,D)){
  155. return 1;
  156. }
  157. if (A.x > B.x) swap(A, B);
  158. if (C.x > D.x) swap(C, D);
  159. if (B.x < C.x) {
  160. //cout<<"one\n";
  161. return 0;
  162. }
  163. if (D.x < A.x) {
  164. //cout<<"two\n";
  165. return 0;
  166. }
  167. if (A.y > B.y) swap(A, B);
  168. if (C.y > D.y) swap(C, D);
  169. if (B.y < C.y) return 0;
  170. if (D.y < A.y ) return 0;
  171.  
  172. if ( sgn(rCross(rVec(A,B), rVec(C,D)) == 0) ){
  173. return 1;
  174. }
  175. if (sgn(rCross(rVec(A,B), rVec(A,C))) == sgn(rCross(rVec(A,B), rVec(A,D)))){
  176. /*cout<<"three\n";
  177. //сout<<"sgn(rCross(rVec(A,B), rVec(A,C))) = "<<sgn(rCross(rVec(A,B), rVec(A,C)))<<"\n";
  178. cout<<"sgn(rCross(rVec(A,B), rVec(A,C))) = "<<sgn(rCross(rVec(A,B), rVec(A,C)))<<"\n";
  179. cout<<"sgn(rCross(rVec(A,B), rVec(A,D))) = "<<sgn(rCross(rVec(A,B), rVec(A,D)))<<"\n";*/
  180. return 0;
  181. }
  182. if (sgn(rCross(rVec(C,D), rVec(C, A))) == sgn(rCross(rVec(C, D), rVec(C,B)))){
  183. /*cout<<"four\n";
  184. cout<<"sgn(rCross(rVec(C,D), rVec(C, A))) = "<<sgn(rCross(rVec(C,D), rVec(C, A)))<<"\n";
  185. cout<<"sgn(rCross(rVec(C, D), rVec(C,B))) = "<<sgn(rCross(rVec(C, D), rVec(C,B)))<<"\n";*/
  186.  
  187. return 0;
  188. }
  189. return 1;
  190. }
  191.  
  192.  
  193. bool iInter(ipn A, ipn B, ipn C, ipn D){
  194. if (eq(A,C) || eq(A,D ) || eq(B, C) || eq(B,D)){
  195. return 1;
  196. }
  197. if (A.x > B.x) swap(A, B);
  198. if (C.x > D.x) swap(C, D);
  199. if (B.x < C.x) {
  200. //cout<<"one\n";
  201. return 0;
  202. }
  203. if (D.x < A.x) {
  204. //cout<<"two\n";
  205. return 0;
  206. }
  207. if (A.y > B.y) swap(A, B);
  208. if (C.y > D.y) swap(C, D);
  209. if (B.y < C.y) return 0;
  210. if (D.y < A.y ) return 0;
  211.  
  212. if ( sgn(iCross(iVec(A,B), iVec(C,D)) == 0) ){
  213. return 1;
  214. }
  215. if (sgn(iCross(iVec(A,B), iVec(A,C))) == sgn(iCross(iVec(A,B), iVec(A,D)))){
  216. /*cout<<"three\n";
  217. //сout<<"sgn(rCross(rVec(A,B), rVec(A,C))) = "<<sgn(rCross(rVec(A,B), rVec(A,C)))<<"\n";
  218. cout<<"sgn(rCross(rVec(A,B), rVec(A,C))) = "<<sgn(rCross(rVec(A,B), rVec(A,C)))<<"\n";
  219. cout<<"sgn(rCross(rVec(A,B), rVec(A,D))) = "<<sgn(rCross(rVec(A,B), rVec(A,D)))<<"\n";*/
  220. return 0;
  221. }
  222. if (sgn(iCross(iVec(C,D), iVec(C, A))) == sgn(iCross(iVec(C, D), iVec(C,B)))){
  223. /*cout<<"four\n";
  224. cout<<"sgn(rCross(rVec(C,D), rVec(C, A))) = "<<sgn(rCross(rVec(C,D), rVec(C, A)))<<"\n";
  225. cout<<"sgn(rCross(rVec(C, D), rVec(C,B))) = "<<sgn(rCross(rVec(C, D), rVec(C,B)))<<"\n";*/
  226.  
  227. return 0;
  228. }
  229. return 1;
  230. }
  231.  
  232.  
  233. void sh(ipn x){
  234. cout<<x.x<<' '<<x.y<<"\n";
  235. }
  236.  
  237. void one_sd( ipn C,ipn A, ipn B, ipn D){ //точки C и D лежат по одну сторону от AB
  238. /*cout<<"C A B D\n";
  239. sh(C);
  240. sh(A);
  241. sh(B);
  242. sh(D);*/
  243. if (sgn(iCross(iVec(A,B), iVec(A, C))) != 0 && sgn(iCross(iVec(A,B), iVec(A, D))) != 0){
  244. if (sgn(iCross(iVec(A,B), iVec(A, C))) != sgn(iCross(iVec(A,B), iVec(A, D))) ){
  245. cout<<"No\n";
  246. exit(0);
  247. }
  248. }
  249. if (sgn(iCross(iVec(A,B), iVec(B, C))) != 0 && sgn(iCross(iVec(A,B), iVec(B,D))) != 0){
  250. if (sgn(iCross(iVec(A,B), iVec(B,C))) != sgn(iCross(iVec(A,B), iVec(B,D)))){
  251. cout<<"No\n";
  252. exit(0);
  253. }
  254. }
  255.  
  256. /*
  257. */
  258. /*if (sgn(iCross(iVec(C, D), iVec(C,A))) != sgn(iCross(iVec(C, D), iVec(C, B))) ){
  259. cout<<"No\n";
  260. exit(0);
  261. }*/
  262. //if (sgn(iCross(iVec(A,B), iVec())))
  263. //cout<<"\n\n";
  264. }
  265.  
  266.  
  267. void sh(rpn a){
  268. cout<<a.x<<' '<<a.y<<"\n";
  269. }
  270.  
  271.  
  272. int main()
  273. {
  274. ios::sync_with_stdio(0);
  275. cin.tie(0);
  276. cout.tie(0);
  277. cout.precision(20);
  278. int n; cin>>n;
  279. vector <ipn> v(n);
  280. for (int i = 0; i < n;++i){
  281. mk(v[i]);
  282. }
  283. //if (n == 3){
  284. // cout<<"Yes\n";
  285. // exit(0);
  286. //}
  287. //cout<<"\n\n";
  288. //one_sd(v[n-1], v[0], v[1], v[2]);
  289. for (int i = 0; i < n;++i){
  290. one_sd(v[i], v[(i+1)%n], v[(i+2)%n], v[(i+3)%n]);
  291. }
  292. cout<<"Yes\n";
  293. }
  294.  
  295. /*
  296. 15
  297. 3 5
  298. 3 16
  299. 18 16
  300. 18 3
  301. 7 3
  302. 7 13
  303. 11 11
  304. 14 13
  305. 12 7
  306. 9 10
  307. 9 5
  308. 16 5
  309. 16 15
  310. 5 15
  311. 5 3
  312.  
  313. 5
  314. 2 2
  315. 2 6
  316. 5 9
  317. 8 6
  318. 10 1
  319.  
  320. 5
  321. 2 2
  322. 2 6
  323. 5 4
  324. 8 6
  325. 10 1
  326.  
  327. 4
  328. 1 1
  329. 1 3
  330. 3 3
  331. 3 1
  332.  
  333.  
  334. */
  335.  
Add Comment
Please, Sign In to add comment