题目大意:给你几个正方形的边长,正方一个顶点在x轴上然后边与x轴的夹角为45度,每个正方形都是紧贴的,问从上面看能看的正方形的编号

题目思路:线段覆盖,边长乘上2防止产生小数,求出每个正方形与x轴平行的对角线的起始x坐标,剩下的就是线段了。

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
#define MAX 100005 using namespace std; struct node
{
int sx,y,ex,dist;
} point[MAX]; int vis[MAX],n; void Find(int sx,int ex,int pos)
{
for(int i=; i<n; i++)
{
if(i==pos || (point[pos].y >= point[i].y))
continue;
if((sx>=point[i].sx && ex<=point[i].ex) || sx>=ex)
{
vis[pos]=;
return;
}
else if(sx<=point[i].ex && sx>=point[i].sx)
{
sx=point[i].ex;
}
else if(ex<=point[i].ex && ex>=point[i].sx)
{
ex=point[i].sx;
}
}
} int main()
{
int d,sx,ex;
int op;
while(scanf("%d",&n),n)
{
op=;
memset(vis,,sizeof(vis));
for(int i=; i<n; i++)
{
scanf("%d",&d);
point[i].dist=d;
point[i].y=d;
point[i].sx=;
for(int j=; j<i; j++)
{
point[i].sx=max(point[i].sx,point[j].ex-abs(point[i].dist-point[j].dist));
}
point[i].ex=point[i].sx+*d;
}
for(int i=; i<n; i++)
{
ex=point[i].ex;
sx=point[i].sx;
Find(sx,ex,i);
}
for(int i=; i<n; i++)
{
if(!vis[i])
{
if(!op)
{
op=;
printf("%d",i+);
}
else
printf(" %d",i+);
}
}
printf("\n");
}
return ;
}

POJ 3347 Kadj Squares (线段覆盖)的更多相关文章

  1. POJ 3347 Kadj Squares (计算几何+线段相交)

    题意:从左至右给你n个正方形的边长,接着这些正方形都按照旋转45度以一角为底放置坐标轴上,最左边的正方形左端点抵住y轴,后面的正方形依次紧贴前面所有正方形放置,问从上方向下看去,有哪些正方形是可以被看 ...

  2. POJ 3347 Kadj Squares

    Kadj Squares Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2132   Accepted: 843 Descr ...

  3. 简单几何(线段覆盖) POJ 3347 Kadj Squares

    题目传送门 题意:告诉每个矩形的边长,它们是紧贴着的,问从上往下看,有几个还能看到. 分析:用网上猥琐的方法,将边长看成左端点到中心的距离,这样可以避免精度问题.然后先求出每个矩形的左右端点,然后如果 ...

  4. POJ 3347 Kadj Squares (计算几何)

    题目: Description In this problem, you are given a sequence S1, S2, ..., Sn of squares of different si ...

  5. POJ 3347 Kadj Squares 计算几何

    求出正方形的左右端点,再判断是否覆盖 #include <iostream> #include <cstdio> #include <cstring> #inclu ...

  6. [poj] 3347 Kadj Square || 计算几何的“线段覆盖”

    原题 多组数据,给出n个正方形的边长,使他们以45度角倾斜的情况下最靠左(在第一象限内),如图.求从上看能看到哪几个完整的正方形. 借鉴于https://www.cnblogs.com/Ritchie ...

  7. HDU 1828 / POJ 1177 Picture (线段树扫描线,求矩阵并的周长,经典题)

    做这道题之前,建议先做POJ 1151  Atlantis,经典的扫描线求矩阵的面积并 参考连接: http://www.cnblogs.com/scau20110726/archive/2013/0 ...

  8. Poj 2528-Mayor's posters 线段切割

      题目:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total ...

  9. CODEVS3037 线段覆盖 5[序列DP 二分]

    3037 线段覆盖 5   时间限制: 3 s   空间限制: 256000 KB   题目等级 : 钻石 Diamond 题解       题目描述 Description 数轴上有n条线段,线段的 ...

随机推荐

  1. C# 语言规范_版本5.0 (第9章 命名空间)

    1. 命名空间 C# 程序是利用命名空间组织起来的.命名空间既用作程序的“内部”组织系统,也用作“外部”组织系统(一种向其他程序公开自己拥有的程序元素的方法). using 指令(第 9.4 节)用来 ...

  2. NTFS 读写高手进阶 - Windows 格式硬盘 Mac存文件

    常识:硬盘格式:FAT32 - WIndows 硬盘分区格式, 有点通用性高, 缺点不支持单个大于 4G 的文件. exFAT - Windows 硬盘分区格式, 兼容性低. 稳定性不如 FAT32. ...

  3. 微信小程序文档解读(一)--api提供支持有哪些

    本文重点在于小程序API提供的微信功能支持及获取用户信息的解读,具体的用法和调用不在本文讨论范围之内,文章基于20161222版文档解读 API官方文档原文链接 小程序API官方定义: 框架提供丰富的 ...

  4. web.xml Attribute "xmlns" was already specified for element "web-app"

    报错信息:Attribute "xmlns" was already specified for element "web-app" 由于项目的重命名,出现了x ...

  5. LWP::UserAgent介绍2

    #这个LWP::UserAgent一般要配合其他模块使用 #比如: #HTTP::Request #HTTP::Cookie #HTTP::Respose #HTTP::Status #LWP::Us ...

  6. php登录利用$token验证

    <?php $module = $_GET['module']; $action = $_GET['action']; $token = md5sum($module.date('Y-m-d', ...

  7. 理解委托(delegate)及为什么要使用委托

    理解委托(delegate)及为什么要使用委托 委托:是一种定义方法签名的类型. 当实例化委托时,您可以将其实例与任何具有兼容签名的方法相关联. 您可以通过委托实例调用方法. 上述为官方说法,理解起来 ...

  8. ZZNU 1163: 在线判题(指针专题)

    题目描述 Ignatius is building an Online Judge, now he has worked out all the problems except the Judge S ...

  9. SDCC 2016中国软件开发者大会十三大主题

    SDCC中国软件开发者嘉年华(Software Developer Carnival China),是由全球最大中文IT社区CSDN于2007年创办的软件技术领域顶级盛会,将如约于2016年11月18 ...

  10. html5权威指南:html全局属性

    html全局属性:http://www.w3school.com.cn/tags/html_ref_standardattributes.asp 辅助记忆:(ail1,s2,c3,t3,d4)(acd ...