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 ...
随机推荐
- jsp:和属性相关的方法,请求的转发,重定向
jsp中与属性相关的方法: 方法: void setAttribute(String name, Object o): 设置属性 Object getAttribute(String name):获取 ...
- Communication System(dp)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...
- 多校3-Magician 分类: 比赛 2015-07-31 08:13 4人阅读 评论(0) 收藏
Magician Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- javascript学习(一) 异常处理与简单的事件
一:异常处理 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></ti ...
- Unity安卓上播放视频的问题,暂时无解记录一下
设备联想A7600m,好像是联发科的cpu 先用网上流传很广的这个Unity自带接口试验一下: Handheld.PlayFullScreenMovie(Path.Combine(Applicatio ...
- fg、bg、jobs、&、ctrl + z
原文地址:fg.bg.jobs.&.ctrl + z 作者:china-yuan http://blog.chinaunix.net/uid-22433093-id-1774026.html ...
- 手把手教你修改iOS版QQ的运动步数
手把手教你修改iOS版QQ的运动步数 现在很多软件都加上了运动模块,比如QQ和微信,而且还有排行榜,可以和好友比较谁的运动步数多,任何东西只要添加了比较功能,就变得不一样了.今天教大家用代码去修改QQ ...
- hdu So Easy!
So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- require.js的简单使用
<script src="js/require.js"></script> <script src="js/require.js" ...
- 2015 AlBaath Collegiate Programming Contest B
Description Yaaaay, Haven't you heard the news? Bakaloria results are out! And Reem had very good gr ...