题目传送门

题意:告诉每个矩形的边长,它们是紧贴着的,问从上往下看,有几个还能看到。

分析:用网上猥琐的方法,将边长看成左端点到中心的距离,这样可以避免精度问题。然后先求出每个矩形的左右端点,然后如果被覆盖那么将端点更新到被覆盖的位置。最后看那些更新后左端点小于右端点,这些是可以看得到的。

/************************************************
* Author :Running_Time
* Created Time :2015/10/28 星期三 11:48:32
* File Name :POJ_3347.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos (-1.0);
struct Square {
int l, r, len;
}s[55]; int main(void) {
int n;
while (scanf ("%d", &n) == 1) {
if (!n) break;
for (int i=1; i<=n; ++i) {
scanf ("%d", &s[i].len);
s[i].l = 0;
for (int j=1; j<i; ++j) {
int tmp;
if (s[i].len <= s[j].len) {
tmp = s[j].l + s[j].len + s[i].len;
}
else {
tmp = s[j].l + s[j].len * 3 - s[i].len;
}
if (tmp > s[i].l) s[i].l = tmp;
}
s[i].r = s[i].l + s[i].len * 2;
}
for (int i=2; i<=n; ++i) {
for (int j=1; j<i; ++j) {
if (s[j].len < s[i].len && s[j].r > s[i].l) {
s[j].r = s[i].l;
}
else if (s[j].len > s[i].len && s[j].r > s[i].l) {
s[i].l = s[j].r;
}
}
}
for (int i=1; i<=n; ++i) {
if (s[i].l < s[i].r) {
printf ("%d ", i);
}
}
puts ("");
} //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0;
}

  

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

  1. POJ 3347 Kadj Squares (线段覆盖)

    题目大意:给你几个正方形的边长,正方一个顶点在x轴上然后边与x轴的夹角为45度,每个正方形都是紧贴的,问从上面看能看的正方形的编号 题目思路:线段覆盖,边长乘上2防止产生小数,求出每个正方形与x轴平行 ...

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

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

  3. POJ 3347 Kadj Squares

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

  4. 简单几何(线段相交) POJ 2653 Pick-up sticks

    题目传送门 题意:就是小时候玩的一种游戏,问有多少线段盖在最上面 分析:简单线段相交,队列维护当前最上的线段 /******************************************** ...

  5. 简单几何(线段相交) POJ 2826 An Easy Problem?!

    题目传送门 题意:两条线段看成两块木板,雨水从上方往下垂直落下,问能接受到的水的体积 分析:恶心的分类讨论题,考虑各种情况,尤其是入口被堵住的情况,我的方法是先判断最高的两个点是否在交点的同一侧,然后 ...

  6. 简单几何(线段相交) POJ 1410 Intersection

    题目传送门 题意:一个矩形和一条线段,问是否有相交 分析:考虑各种情况.坑点:给出的矩形的两个端点是无序的,还有线段完全在矩形内也算相交 /****************************** ...

  7. 简单几何(线段相交) POJ 1066 Treasure Hunt

    题目传送门 题意:从四面任意点出发,有若干障碍门,问最少要轰掉几扇门才能到达终点 分析:枚举入口点,也就是线段的两个端点,然后选取与其他线段相交点数最少的 + 1就是答案.特判一下n == 0的时候 ...

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

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

  9. POJ 3347 Kadj Squares 计算几何

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

随机推荐

  1. Nginx 开启PATHINFO支持ThinkPHP框架实例

    ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置 'URL_MODEL' => 2 即可.在Apache下只需要开启mod_rew ...

  2. cocos2d调度器(定时执行某函数)

    调度器(scheduler) 继承关系 原理介绍 Cocos2d-x调度器为游戏提供定时事件和定时调用服务.所有Node对象都知道如何调度和取消调度事件,使用调度器有几个好处: 每当Node不再可见或 ...

  3. Stanford机器学习---第九讲. 聚类

    原文:http://blog.csdn.net/abcjennifer/article/details/7914952 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...

  4. maven最齐全配置pom.xml

    0001<project xmlns="http://maven.apache.org/POM/4.0.0"0002 0003xmlns:xsi="http://w ...

  5. Bmob用户管理操作

    注册用户 BmobUser bu = new BmobUser(); bu.setUsername("sendi"); bu.setPassword("123456&qu ...

  6. [颓废] 改某人的WebGL light mapping demo并9xSSAA

    渲染图(4k) 链接: http://pan.baidu.com/s/1bnB4Wqz 密码: 8839 2px高斯模糊+立方缩小AA:  链接: http://pan.baidu.com/s/1mg ...

  7. Watering the Fields(irrigation)

    #include <cstdio> #include <algorithm> struct edge{ int f,t,w; } ed[5000000]; int pl,n,c ...

  8. Android 下载文件及写入SD卡

    Android 下载文件及写入SD卡,实例代码 <?xml version="1.0" encoding="utf-8"?> <LinearL ...

  9. LSB 简介

    前 Linux 的发行版非常繁多,为了促进 Linux 不同发行版间的兼容性,LSB(Linux Standards Base)开发了一系列标准,使各种软件可以很好地在兼容 LSB 标准的系统上运行, ...

  10. Linux awk命令详解??????????(研究)

    http://blog.chinaunix.net/uid-25120309-id-3801250.html 一.  AWK 说明  awk是一种编程语言,用于在linux/unix下对文本和数据进行 ...