fork download
  1. #include <iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. #include<utility>
  5. #include<cmath>
  6. using namespace std;
  7.  
  8. typedef long long int lli;
  9.  
  10. int main() {
  11. // your code goes here
  12.  
  13. vector<pair<lli,lli>> snake1(2),snake2(2),unionset(4);
  14. vector <pair<lli,lli>>::iterator it;
  15. float slope=0,inf=10000000000;
  16. int N=0;
  17. bool flag=true,main=false;
  18. lli p1,p2,p3,p4,xaxis=0,yaxis=0;
  19. scanf("%d",&N);
  20. while(N--){
  21. flag=true;
  22. scanf("%lld %lld %lld %lld",&p1,&p2,&p3,&p4);
  23. snake1[0] = make_pair(p1,p2);
  24. snake1[1] = make_pair(p3,p4);
  25. sort(snake1.begin(),snake1.end());
  26. scanf("%lld %lld %lld %lld",&p1,&p2,&p3,&p4);
  27. snake2[0] = make_pair(p1,p2);
  28. snake2[1] = make_pair(p3,p4);
  29. sort(snake2.begin(),snake2.end());
  30. unionset.resize(4);
  31. it = set_intersection(snake1.begin(),snake1.end(),snake2.begin(),snake2.end(),unionset.begin());
  32. unionset.resize(it-unionset.begin());
  33. if(unionset.size()>0){
  34. flag = true;
  35. main=true;
  36. }
  37. else{
  38. unionset.resize(4);
  39. it = set_union(snake1.begin(),snake1.end(),snake2.begin(),snake2.end(),unionset.begin());
  40. unionset.resize(it-unionset.begin());
  41. for(int x=0;x<unionset.size()-1;x++){
  42. xaxis = unionset[x].first - unionset[x+1].first;
  43. if(x==0){
  44. if(xaxis == 0){
  45. slope = inf;
  46. }
  47. else{
  48. slope = (unionset[x].second - unionset[x+1].second)/(unionset[x].first - unionset[x+1].first);
  49. }
  50. }
  51. else{
  52. if(xaxis != 0){
  53. if((slope != (unionset[x].second - unionset[x+1].second)/(unionset[x].first - unionset[x+1].first)) && flag){
  54. flag=false;
  55. }
  56. }
  57. else if(slope != inf){
  58.  
  59. flag= false;
  60. }
  61. }
  62. }
  63.  
  64. }
  65. if(flag){
  66. if(!main){
  67. if((sqrt(pow(snake1[1].first-snake2[0].first,2)+pow(snake1[1].second-snake2[0].second,2))+sqrt(pow(snake1[0].first-snake2[0].first,2)+pow(snake1[0].second-snake2[0].second,2)) > sqrt(pow(snake1[0].first-snake1[1].first,2)+ pow(snake1[0].second-snake1[1].second,2))) && sqrt(pow(snake1[1].first-snake2[1].first,2)+pow(snake1[1].second-snake2[1].second,2))+sqrt(pow(snake1[0].first-snake2[1].first,2)+pow(snake1[0].second-snake2[1].second,2)) > sqrt(pow(snake1[0].first-snake1[1].first,2)+ pow(snake1[0].second-snake1[1].second,2))){
  68. printf("No");
  69. }
  70. else{
  71.  
  72. printf("Yes");
  73. }
  74.  
  75. }
  76. else{
  77. printf("Yes");
  78. }
  79.  
  80. }
  81. else printf("No");
  82. if(N){
  83. printf("\n");
  84. }
  85. }
  86. return 0;
  87. }
Success #stdin #stdout 0s 16056KB
stdin
Standard input is empty
stdout
Standard output is empty