POJ 1380 坐标旋转
生活随笔
收集整理的這篇文章主要介紹了
POJ 1380 坐标旋转
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:
問第二個矩形能不能放進第一個矩形中。
?
題解:
暴力旋轉第二個矩形,判斷左右、上下是否同時小于第一個矩形
當然,數學推導也可以,挺簡單的相似神馬的胡搞就行~
?
View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #include <cmath> 7 8 #define PI 3.141592653589793 9 #define EPS 1e-7 10 11 using namespace std; 12 13 struct PO 14 { 15 double x,y; 16 }sma,big; 17 18 inline int doublecmp(double x) 19 { 20 if(x>EPS) return 1; 21 else if(x<-EPS) return -1; 22 return 0; 23 } 24 25 inline PO rotate(PO &a,double hd) 26 { 27 PO c; 28 c.x=a.x*sin(hd)-a.y*cos(hd); 29 c.y=a.x*cos(hd)+a.y*sin(hd); 30 return c; 31 } 32 33 inline bool go() 34 { 35 scanf("%lf%lf%lf%lf",&big.x,&big.y,&sma.x,&sma.y); 36 double du=0.0;PO c; 37 while(du*2<PI) 38 { 39 c=rotate(sma,du); 40 c.x+=2.0*sma.y*cos(du); 41 if(doublecmp(big.x-c.x)>=0&&doublecmp(big.y-c.y)>=0) return true; 42 if(doublecmp(big.y-c.x)>=0&&doublecmp(big.x-c.y)>=0) return true; 43 du+=0.002; 44 } 45 return false; 46 } 47 48 int main() 49 { 50 int cas; scanf("%d",&cas); 51 while(cas--) 52 { 53 if(go()) printf("Escape is possible.\n"); 54 else printf("Box cannot be dropped.\n"); 55 } 56 return 0; 57 }?
?
轉載于:https://www.cnblogs.com/proverbs/archive/2013/02/24/2924591.html
總結
以上是生活随笔為你收集整理的POJ 1380 坐标旋转的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 静态与非静态(转改)
- 下一篇: SOAP 1.1 - 学习