链接

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

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

用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. Windows下打包Python的exe可执行文件

    参考:http://www.cnblogs.com/Lands-ljk/p/5447723.html

  2. Meisell-Lehmer算法(统计较大数据里的素数)

    http://acm.hdu.edu.cn/showproblem.php?pid=5901 1e11的数据量,这道题用这个算法花了202ms. #include<bits/stdc++.h&g ...

  3. 20150625_Andriod_01_ListView1_条目选中

    android listview 参考地址: http://www.cnblogs.com/zhengbeibei/archive/2013/05/14/3078805.html  http://xy ...

  4. Codeforces Round #336 Zuma

    D. Zuma time limit per test:  2 seconds memory limit per test:  512 megabytes input:  standard input ...

  5. Unity GUI内绘制贝塞尔曲线

    用Handles可以直接在GUI下绘制贝塞尔 using UnityEditor; using UnityEngine; using System.Collections; public class ...

  6. 2015 AlBaath Collegiate Programming Contest B

    Description Yaaaay, Haven't you heard the news? Bakaloria results are out! And Reem had very good gr ...

  7. linux系统中如何查看日志 (常用命令2)

    cat tail -f 日 志 文 件 说 明 /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一 /var/log/secure 与安全相关 ...

  8. 编译android源码官方教程(2)建立编译环境「linux & mac osx」

    https://source.android.com/source/initializing.html Establishing a Build Environment IN THIS DOCUMEN ...

  9. Spring.Net 技术简介 IOC and DI

    一 简单介绍            IOC 控制转移,就是将创建放到容器里,从而达到接耦合的目的,DI是 在容器创建对象的时候,DI读取配置文件,然后给对象赋默认值,两者一般结合使用,实现注入.   ...

  10. strip_tags,htmlspecialchars,htmlentities,stripslashes,addslashes学习小结

    一.strip_tags 从字符串中去除 HTML 和 PHP 标记 string strip_tags ( string $str [, string $allowable_tags ] ) str ...