链接

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

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

用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. JavaEE基础(三)

    1.Java语言基础(逻辑运算符的基本用法) A:逻辑运算符有哪些 &,|,^,! &&,|| B:案例演示 逻辑运算符的基本用法 注意事项: a:逻辑运算符一般用于连接boo ...

  2. C语言中使用静态函数的好处

    C语言中使用静态函数的好处: 静态函数会被自动分配在一个一直使用的存储区,直到退出应用程序实例,避免了调用函数时压栈出栈,速度快很多. ???(对这个不是很理解)其实我觉得上面这种说法是错误的,它的主 ...

  3. source insight项目文件列表固定嵌入右侧

    项目文件列表悬浮出来,不是嵌入紧靠右边,先将该窗口最小化,然后往右拖放,就成功固定嵌入到右边了.

  4. 完整学习git三 查看暂存区目录树 git diff

    1显示暂存区中的目录树 git ls-files git ls-tree git diff 魔法 1工作区与暂存区比较 git diff 2工作区与HEAD比较 git diff HEAD 3暂存区与 ...

  5. SQLite详解

    一.新建SQLite操作类(继承SQLiteOpenHelper) public class SQLiteTest extends SQLiteOpenHelper { final static St ...

  6. PHP值mysql操作类

    <?php /** * Created by PhpStorm. * User: Administrator * Date: 2016/6/27 * Time: 18:55 */ Class M ...

  7. js格式化日期 年月日

    /**                     * 格式化日期                     * @param value                     * @param row  ...

  8. 2015-11-04 报表 (asp.net 部分)

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Scrap_p.aspx.cs& ...

  9. js调用MVC3自带js验证

    验证: if ($(this).is("form")) {                        return $(this).validate().checkForm() ...

  10. asp.net MVC webservice 报次错解决方法

    asp.net  MVC  webservice  报次错解决方法: 解决方法: 在 RouteConfig.cs public static void RegisterRoutes(RouteCol ...