• 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 }
  • 相关阅读:
    Lombok Pojo默认初始值问题
    spring boot打包以及centos下部署
    Spring事件监听ApplicationListener源码流程分析
    synchronized是什么,用法及原理
    Spring动态切换数据源及事务
    linux环境中关闭tomcat,通过shutdown.sh无法彻底关闭--线程池
    LVS之DR模式
    LVS之ipvsadm命令
    LVS之NAT模式
    tcpdump抓包命令
  • 原文地址:https://www.cnblogs.com/proverbs/p/2924591.html
Copyright © 2020-2023  润新知