传送门

•题意

先给一个白矩阵,再两个黑矩阵

如果两个黑矩阵能把白矩阵包含,则输出NO

否则输出YES

•思路

计算几何题还是思维题呢?

想起了上初中高中做几何求面积的题

这个就类似于那样

包含的话分两种情况讨论,其他的不包含

①白矩形在一个黑矩形内部

  这种情况直接判断边界就可以

②白矩形在两个黑矩形组合的图形内部

  • 首先这个情况的前提是两个黑矩形必须能连接起来
  • 白矩形和两个黑矩形分别会有重合,重合的地方可能会在此重合,

  例如 白矩形(1 1 4 2)   黑1矩形(1 0 3 4)  黑2矩形(2 0 5 3)

    

被黑1黑2矩阵联合包含,与黑1相交面积是粉色区域,与黑2相交面积是绿色区域

但是粉绿色区域的多算的,白矩阵面积=粉色面积+绿色面积-粉绿面积

•代码

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node
{
ll xl,yl,x2,y2;
}a[],p; bool CH(node x,node y )//重合
{
if(x.xl>=y.xl&&x.x2<=y.x2&&x.yl>=y.yl&&x.y2<=y.y2)
return true;
return false;
}
ll XJ(node a,node b)//相交
{
ll cx1=max(a.xl,b.xl);
ll cy1=max(a.yl,b.yl);
ll cx2=min(a.x2,b.x2);
ll cy2=min(a.y2,b.y2);
if(cx1>cx2||cy1>cy2)//不相交 p=node{cx1,cy1,cx2,cy2};//相交矩形
return (cx2-cx1)*(cy2-cy1);//相交面积
} ///包括NO 不包括YES
int main()
{
for(ll i=;i<=;i++)
cin>>a[i].xl>>a[i].yl>>a[i].x2>>a[i].y2; if(CH(a[],a[])||CH(a[],a[]))///重合在内部
{
puts("NO");
return ;
} if(XJ(a[],a[])<) ///2 3不相交
{
puts("YES");
return ;
} if(XJ(a[],a[])>=) ///2 3相交
{
ll s1=XJ(a[],a[]);
node p1=p;
ll s2=XJ(a[],a[]);
node p2=p;
ll s=(a[].y2-a[].yl)*(a[].x2-a[].xl);
s+=max(1ll*,XJ(p1,p2));///重合处会多算 if(s1+s2==s)
{
puts("NO");
return ;
}
else
{
puts("YES");
return ;
}
}
} /**
1 1 4 2
1 0 3 4
2 0 5 3
*/

Codeforces Round #587 C. White Sheet(思维+计算几何)的更多相关文章

  1. Codeforces Round #587 (Div. 3) C. White Sheet

    链接: https://codeforces.com/contest/1216/problem/C 题意: There is a white sheet of paper lying on a rec ...

  2. Codeforces Round #587

    题目链接:Round #587 题目答案:官方Editorial.My Solution A. Prefixes 题意:给一字符串,只含有'a'或'b',需要改变某些位置('a'变'b'或'b'变'a ...

  3. Codeforces Round #587 (Div. 3)

    https://codeforces.com/contest/1216/problem/A A. Prefixes 题意大概就是每个偶数位置前面的ab数目要相等,很水,被自己坑了 1是没看见要输出修改 ...

  4. Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}

    C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle ...

  5. Educational Codeforces Round 40 C. Matrix Walk( 思维)

    Educational Codeforces Round 40 (Rated for Div. 2) C. Matrix Walk time limit per test 1 second memor ...

  6. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

  7. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  8. Codeforces Round #395 (Div. 2)(A.思维,B,水)

    A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  9. Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)

    A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

随机推荐

  1. jsp中的标签使用

    jsp中的变量作用域 表示变量的作用域,一共4种.pageScope:  表示变量只能在本页面使用.requestScope:表示变量能在本次请求中使用.sessionScope:表示变量能在本次会话 ...

  2. 命名实体识别学习笔记——使用Ltp

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/xuewenstudy/article/d ...

  3. HZOJ 集合论

    考场用的set,代码复杂度很低,时间复杂度$O(sum log)$,一发过了大样例,以为1e6的数据很稳了就没再管(然后就挂掉了……) 考后把set化成unordered_set就A了.其实$sum ...

  4. sn图书spider

    # -*- coding: utf-8 -*-import scrapyfrom copy import deepcopy class SnbookSpider(scrapy.Spider): nam ...

  5. iOS runtime整理

    iOS利用Runtime自定义控制器POP手势动画 http://www.cocoachina.com/ios/20150401/11459.html  Objective C运行时(runtime) ...

  6. LeetCode58 Length of Last Word

    题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...

  7. windows 和 linux 安装 tensorflow

    安装 跟往常一样,我们用 Conda 来安装 TensorFlow.你也许已经有了一个 TensorFlow 环境,但要确保你安装了所有必要的包. OS X 或 Linux 运行下列命令来配置开发环境 ...

  8. UISearchDisplayController “No Results“ cancel修改

    Recently I needed to fully customize a UISearchBar, so here are some basic "recipes" on ho ...

  9. saltStack 配置管理(也就是替换文件)

    目录  /srv/salt/base下面新建一个文件dns.sls /opt/resolv.conf_bak:     #这个是文件替换的位置,也就说替换到远程文件的/opt/resolv.conf_ ...

  10. phpstorm IDEA 双击Shift键会弹出 SearchEverywhere 对话框,如何取消这个功能

    https://blog.csdn.net/qq_27598243/article/details/80526352 解决方法:一:Open lib/resources.jar/idea/Platfo ...