poj3347Kadj Squares
这题其实与几何没太大关系,还不错的题目。
参考吴永辉的算法设计书。
用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的更多相关文章
- [LeetCode] Word Squares 单词平方
Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...
- 卡通图像变形算法(Moving Least Squares)附源码
本文介绍一种利用移动最小二乘法来实现图像变形的方法,该方法由用户指定图像中的控制点,并通过拖拽控制点来驱动图像变形.假设p为原图像中控制点的位置,q为拖拽后控制点的位置,我们利用移动最小二乘法来为原图 ...
- 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 ...
- [LintCode] Perfect Squares 完全平方数
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...
- HDU 1264 Counting Squares(线段树求面积的并)
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- RSS(Residual Sum of Squares)的自由度为什么是n-1呢
[转载请注明出处]http://www.cnblogs.com/mashiqi 在回归问题中,偶尔我们会遇到求方差的估计的情况.举了例子,我们常常通过Gaussian分布${\cal N}(\mu , ...
- poj-3739. Special Squares(二维前缀和)
题目链接: I. Special Squares There are some points and lines parellel to x-axis or y-axis on the plane. ...
- [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 ...
- POJ 2002 Squares
二分.... Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 14530 Accepted: 5488 Descr ...
随机推荐
- JavaEE基础(九)
1.面向对象(多态的概述及其代码体现) A:多态(polymorphic)概述 事物存在的多种形态 B:多态前提 a:要有继承关系. b:要有方法重写. c:要有父类引用指向子类对象. C:案例演示 ...
- thinkphp模板中截取中文字符串的方法分享
前段用thinkphp写了一个系统,感觉thinkphp学起来比较容易,开发起来了比较顺手,其中一个关键的因素就是它的模版引擎相当强大,使用方法跟smarty类似,在模版中还可以用php代码,有模版包 ...
- Codeforces 745C:Hongcow Builds A Nation(并查集)
http://codeforces.com/problemset/problem/744/A 题意:在一个图里面有n个点m条边,还有k个点是受限制的,即不能从一个受限制的点走到另外一个受限制的点(有路 ...
- win7下80端口被(Pid=4)占用的解决方法
首先介绍一种网上普遍的方法,就是查找占据80端口的进程,然后关闭它就行了. 1.运行cmd,然后输入netstat -a -n -o,回车:2.查看开头几行包含0.0.0.0:80的那一行最后的pid ...
- Greenplum的全量恢复之gpdbrestore
gpdbrestore命令是对gp_restore命令的一个包装,提供了更灵活的选项,比如,使用gpcrondump自动备份的文件来恢复.使用gpdbrestore恢复必须具备: 1. 存在gpcro ...
- [c++][语言语法]函数模板和模板函数 及参数类型的运行时判断
参考:http://blog.csdn.net/beyondhaven/article/details/4204345 参考:http://blog.csdn.net/joeblackzqq/arti ...
- python中string.casefold和string.lower区别
string.casefold和string.lower 区别 python 3.3 引入了string.casefold 方法,其效果和 string.lower 非常类似,都可以把字符串变成小写, ...
- interrupt ,interrupted 和 isInterrupted
1.interrupt interrupt方法用于中断线程.调用该方法的线程的状态为将被置为"中断"状态. 注意:线程中断仅仅是置线程的中断状态位,不会停止线程.需要用户自己去监 ...
- norm函数
如果A为向量 norm(A,p) 返回向量A的p范数. norm(A) 返回向量A的2范数,即等价于norm(A,2).
- 乘号在python中的用法,用乘号将元素重复在列表中
#里面:>>> a=['*5] >>> a ['] >>> a=['0,'*5] >>> a ['0,0,0,0,0,'] #外 ...