链接

这题其实与几何没太大关系,还不错的题目。

参考吴永辉的算法设计书。

用lefi、rigi分别表示正方形在x轴上的投影。

为了避免用小数,把边长都扩大sqrt(2)倍,这样lef1 = 0,rig1 = 2*a1;

lefi = max{rigj-abs(ai-aj)}

rigi = lefi+2*ai;

求出各个正方形的投影之后,这题就好做了。用le和re表示正方形的可见区间。

le = max(rigj,lefi) j <i

re = min(lefj,rigi) j>i

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 55
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int o[N],a[N],lef[N],rig[N]; int main()
{
int i,j,n;
while(scanf("%d",&n)&&n)
{
memset(o,,sizeof(o));
for(i = ; i <= n ;i++)
{
scanf("%d",&a[i]);
}
lef[] = ;
rig[] = *a[];
for(i = ; i <= n ;i++)
{
lef[i] = ;
for(j = ; j < i ; j++)
lef[i] = max(lef[i],rig[j]-abs(a[i]-a[j]));
rig[i] = lef[i]+*a[i];
//cout<<lef[i]<<" "<<rig[i]<<endl;
}
int g = ;
for(i = ; i <= n ;i++)
{
int le = lef[i],re = rig[i];
for(j = ; j < i ; j++)
{
le = max(le,rig[j]);
}
for(j = i+ ; j <= n; j++)
re = min(re,lef[j]);
//cout<<le<<" "<<re<<endl;
if(re>le)
o[++g] = i;
}
for(i = ; i < g ; i++)
printf("%d ",o[i]);
printf("%d\n",o[g]);
}
return ;
}

poj3347Kadj Squares的更多相关文章

  1. [LeetCode] Word Squares 单词平方

    Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...

  2. 卡通图像变形算法(Moving Least Squares)附源码

    本文介绍一种利用移动最小二乘法来实现图像变形的方法,该方法由用户指定图像中的控制点,并通过拖拽控制点来驱动图像变形.假设p为原图像中控制点的位置,q为拖拽后控制点的位置,我们利用移动最小二乘法来为原图 ...

  3. Leetcode: Word Squares && Summary: Another Important Implementation of Trie(Retrieve all the words with a given Prefix)

    Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...

  4. [LintCode] Perfect Squares 完全平方数

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  5. HDU 1264 Counting Squares(线段树求面积的并)

    Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. RSS(Residual Sum of Squares)的自由度为什么是n-1呢

    [转载请注明出处]http://www.cnblogs.com/mashiqi 在回归问题中,偶尔我们会遇到求方差的估计的情况.举了例子,我们常常通过Gaussian分布${\cal N}(\mu , ...

  7. poj-3739. Special Squares(二维前缀和)

    题目链接: I. Special Squares There are some points and lines parellel to x-axis or y-axis on the plane. ...

  8. [CareerCup] 7.5 A Line Cut Two Squares in Half 平均分割两个正方形的直线

    7.5 Given two squares on a two-dimensional plane, find a line that would cut these two squares in ha ...

  9. POJ 2002 Squares

    二分.... Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 14530 Accepted: 5488 Descr ...

随机推荐

  1. 修改ECSHOP系统红包序列号规律

    ECSHOP系统线下发放红包时系统生成的红包序列号是在10000的基础上增加四位随机数字.如果当我们要发放大额度红包的时候,这样的序列号规则难免给人不安全的感觉,万一真的有哪个无聊的人,用一天时间来蒙 ...

  2. postgresql 热备与恢复

    一. PostgreSQL热备份的过程一般为: 数据库中执行:pg_start_backup() ; 然后使用操作系统的tar或 cp命令拷贝 PostgreSQL数据文件. 数据库中执行:pg_st ...

  3. window下appserv组合包配置asp标记风格与简短风格

    php一共有四种编码风格 分别为 :XML风格,脚本分铬,简短风格,ASP风格 如果要配置asp标记风格与简短风格,需要在php.ini文件中配置. 打开文件的位置C:\ window\php.ini ...

  4. SQL Server 索引和表体系结构(三)

    转自:http://www.cnblogs.com/chenmh/p/3785285.html 包含列索引 概述 包含列索引也是非聚集索引,索引结构跟聚集索引结构是一样,有一点不同的地方就是包含列索引 ...

  5. c#游戏 剪刀石头

    电脑using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace sh ...

  6. 【C++】智能指针

    auto_ptr auto_ptr是当前C++标准库中提供的一种智能指针. auto_ptr在构造时获取某个对象的所有去(ownership),在析构时释放该对象.我们可以这样使用auto_ptr来提 ...

  7. Linux/Unix里,ln -s

    这是硬/软链接的命令ln -s 是创建软链接ln 是创建硬链接 你可以理解为:相当于windows下创建快捷方式一样,所以就不用太多解释了吧. ln -s /usr/lib/libX11.3 libX ...

  8. STM32/GD32上内存堆栈溢出探测研究

    无数次遭受堆栈溢出折磨,随着系统变得复杂,故障点越来越难以查找!主要溢出情况如下:1,一般RAM最后两块空间是堆Heap和栈Stack,堆从下往上用,栈从上往下用,任意一个用完,都会进入对方的空间2, ...

  9. 提高开发效率的 Eclipse 实用操作

    工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个“器”.本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行编程开发,避免鼠标分 ...

  10. apahce

    基本的操作方法:本文假设你的apahce安装目录为/usr/local/apache2,这些方法适合任何情况 apahce启动命令:推荐/usr/local/apache2/bin/apachectl ...