UVALive 4954 Lawn mower (简单模拟题)
来源:互联网 发布:枪林弹雨开挂软件 编辑:程序博客网 时间:2024/06/08 01:16
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=16406
题目大意:
给定一块75*100的区域,用一个宽度为w的割草机去割。给定一些横着的中间位置,竖着的中间位置。问这些操作是否能够横着覆盖整块区域,并且竖着覆盖整个区域。可以的话,输出"YES",不能的话输出“NO”。
解题:
先将这些中间位置排序,看能否连上,不能连上直接break。同时最后看起始位置是否小于等于0,最后的位置是否大于等于75/100。
代码:
#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <cstring>#include <cstdlib>#include <string>#include <cmath>#include <set>#define eps 1e-9using namespace std;int main(){int x,y;double w,hen[1010],shu[1010],maxh,maxs,tmp;bool flag;while(scanf("%d%d%lf",&x,&y,&w)){if(x==0&&y==0)break; for(int i=0;i<x;i++)scanf("%lf",&shu[i]);for(int i=0;i<y;i++)scanf("%lf",&hen[i]);sort(hen,hen+y);sort(shu,shu+x);maxs=shu[0]+w/2;maxh=hen[0]+w/2; if(hen[0]-w/2<=0.0)flag=true;else flag=false;if(flag&&(shu[0]-w/2)<=0.0)flag=true;else flag=false;if(flag){ if(x>1) { for(int i=1;i<x;i++) { tmp=shu[i]-w/2; if(tmp-maxs<=0.0) maxs=shu[i]+w/2; else { flag=false; break; } } } if(flag&&y>1) { for(int i=1;i<y;i++) { tmp=hen[i]-w/2; if(tmp-maxh<=0.0) maxh=hen[i]+w/2; else { flag=false; break; } } } if(flag) { if((maxs-75.0>=0.0)&&(maxh-100.0>=0.0)) flag=true; else flag=false; }}if(flag)printf("YES\n");else printf("NO\n");}return 0;}
0 0
- UVALive 4954 Lawn mower (简单模拟题)
- Uvalive 4954 Lawn mower
- CSU1840-Lawn mower-简单模拟
- 2017湖南多校第三场A(1025): Lawn mower
- UVALive 2052 Number Steps【简单模拟】水题
- UVALive 6833Miscalculation (模拟)
- uvalive 4254(二分+模拟)
- UVALive 7139 Rotation(模拟)
- UVALive 4264 Message (模拟)
- UVALive - 4264 Message (模拟)
- UVALive 3667 Ruler (模拟)
- UVALive 4222 Dance(模拟)
- Appearance Analysis UVALive(模拟)
- UVALive 6089 Nine (暴力模拟)
- UVaLive/LA 6805 Pantun Grader(模拟)
- UVALive 6832Bit String Reordering (模拟)
- UVALive 7146 Defeat the Enemy(模拟)
- UVALive-7470-Easy Problemset(模拟)
- Linux网络编程--IO模型基础
- 一段代码 完全解读 SharedPreferedces。
- 主成分分析(Principal components analysis)-最大方差解释
- javascript运算符
- spring mvc+hibernate 实现事务管理(配置文件版)
- UVALive 4954 Lawn mower (简单模拟题)
- 【深度学习】研究Fast rcnn代码
- Shell编程中的“局部变量”和“导出变量”
- Email附件下载流程分析
- HTTP/2 常见问题回答
- 堆与栈的区别
- 异构网络
- HTTP协议详解
- wireshark分析包中关于三次握手和四次终止标识