【POJ】1819.Disks
博客园的话插链接链接都是凉的= =
题解
我理解成能不能看到这个圆,除了最后几个圆特殊以外都是等价的,然而我凉了,因为我把圆当成线段来处理,但是,有可能一个圆完全被遮住了,还有一个缝隙,就WA了
计算几何题这点最不好,WA了会想的第一件事就是垃圾OJ卡我精度,反复WA上几次才会知道,自己算法错了
那么首先每个圆的位置取决于能被左边的圆最远推到哪里,这个就是以两圆圆心距和竖直两条半径(是个梯形)算出来就行,能被推说明圆心距必然是半径之和,不断取max并同时记录是哪个圆推的它
最后取最后一个碰到某个圆的圆,并删除他们之间所有点,特判一下第一个碰到最远距离的圆pos[i] + r[i]的最大值所在的i并删除之后的圆
为什么我叙述那么混乱可能我太久没上语文课吧(手动再见)
代码
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstring>
#include <ctime>
#include <map>
#include <algorithm>
#include <cmath>
#define MAXN 1005
#define eps 1e-8
//#define ivorysi
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long int64;
typedef double db;
int N,tot,ans[MAXN],touch[MAXN];
db R[MAXN],pos[MAXN];
bool dcmp(db a,db b) {
return fabs(a - b) < eps;
}
struct Point {
db x,y;
Point(){}
Point(db _x,db _y) {
x = _x;y = _y;
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
friend Point operator * (const Point &a,db d) {
return Point(a.x * d,a.y * d);
}
friend Point operator / (const Point &a,db d) {
return Point(a.x / d,a.y / d);
}
friend db operator * (const Point &a,const Point &b) {
return a.x * b.y - a.y * b.x;
}
friend db dot(const Point &a,const Point &b) {
return a.x * b.x + a.y * b.y;
}
db norm() {
return sqrt(x * x + y * y);
}
}P[MAXN];
struct Seg {
Point a,b;
db d;
Seg(){}
Seg(Point _a,Point _b) {
a = _a;b = _b;d = atan2(b.y - a.y,b.x - a.x);
}
friend Point Cross_Point(const Seg &s,const Seg &t) {
db S1 = (s.a - t.a) * (t.b - t.a);
db S2 = (s.b - t.b) * (t.a - t.b);
return s.a + (s.b - s.a) * (S1 / (S1 + S2));
}
friend bool operator < (const Seg &s,const Seg &t) {
return s.d < t.d;
}
}S[MAXN];
inline db o(db x) {return x * x;}
void Solve() {
//scanf("%d",&N);
tot = 0;
for(int i = 1 ; i <= N ; ++i) scanf("%lf",&R[i]);
db L = 0.0;
for(int i = 1 ; i <= N ; ++i) {
pos[i] = R[i];
touch[i] = 0;
for(int j = 1 ; j < i ; ++j) {
db x = pos[j] + sqrt(R[i] * R[j]) * 2;
if(x > pos[i] + eps) {
pos[i] = x;
touch[i] = j;
}
}
L = max(L,pos[i] + R[i]);
}
int last = 0;
while(1) {
if(dcmp(pos[last] + R[last],L)) {
for(int i = last + 1 ; i <= N ; ++i) ans[++tot] = i;
break;
}
int v = 0;
for(int i = last + 1 ; i <= N ; ++i) {
if(touch[i] == last) v = i;
}
for(int i = last + 1 ; i < v ; ++i) ans[++tot] = i;
last = v;
}
printf("%d\n",tot);
for(int i = 1 ; i <= tot ; ++i) {
printf("%d\n",ans[i]);
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
while(scanf("%d",&N) != EOF && N) {
Solve();
}
return 0;
}
【POJ】1819.Disks的更多相关文章
- 【POJ】1704 Georgia and Bob(Staircase Nim)
Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...
- 【POJ】1067 取石子游戏(博弈论)
Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...
- 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉
DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $ 当然这里的$i$和$k$都是偶数啦~ ...
- 【POJ】【2104】区间第K大
可持久化线段树 可持久化线段树是一种神奇的数据结构,它跟我们原来常用的线段树不同,它每次更新是不更改原来数据的,而是新开节点,维护它的历史版本,实现“可持久化”.(当然视情况也会有需要修改的时候) 可 ...
- 【POJ】1222 EXTENDED LIGHTS OUT
[算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...
- 【POJ】2892 Tunnel Warfare
[算法]平衡树(treap) [题解]treap知识见数据结构 在POJ把语言从G++换成C++就过了……??? #include<cstdio> #include<algorith ...
- 【POJ】【1637】Sightseeing tour
网络流/最大流 愚人节快乐XD 这题是给一个混合图(既有有向边又有无向边),让你判断是否有欧拉回路…… 我们知道如果一个[连通]图中每个节点都满足[入度=出度]那么就一定有欧拉回路…… 那么每条边都可 ...
- 【poj】1001
[题目] ExponentiationTime Limit: 500MS Memory Limit: 10000KTotal Submissions: 123707 Accepted: 30202De ...
- 【POJ】3070 Fibonacci
[算法]矩阵快速幂 [题解] 根据f[n]=f[n-1]+f[n-2],可以构造递推矩阵: $$\begin{vmatrix}1 & 1\\ 1 & 0\end{vmatrix} \t ...
随机推荐
- Java基础-IO流对象之序列化(ObjectOutputStream)与反序列化(ObjectInputStream)
Java基础-IO流对象之序列化(ObjectOutputStream)与反序列化(ObjectInputStream) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.对象的序 ...
- Linux 下搭建 Svn+Apache
一.安装apache 1.检查apache是否安装 rpm -qa|grep httpd 2.使用yum安装apache yum -y install httpd 3.记住安装的版本号 httpd.x ...
- android edittext 获取焦点并弹出软键盘
editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); activi ...
- Linux命令练习.ziw
2017年1月10日, 星期二 Linux命令练习 1.统计/usr/bin/目录下的文件个数: # ls /usr/bin | wc -l 判断 /home/goldin目录是否有文件 2.取出当前 ...
- nodejs使用记录
安装 下载64or32的安装程序,狂点下一步,无脑安装.然后检查一下: npm 使用npm -v命令检查npm是否可用 然后我们就可以使用npm了,npm语法如下: npm install <M ...
- 来自一个Backbone的Hello,World!
MVC写这种程序真是够大材小用的了,可没想到居然这么抽象! // 这是一个管理者视图/控制/模型 的全局类 var App = { Models: {}, Views: {}, Controllers ...
- spfa+floyed+最长路+差分约束系统(F - XYZZY POJ - 1932)(题目起这么长感觉有点慌--)
题目链接:https://cn.vjudge.net/contest/276233#problem/F 题目大意:给你n个房子能到达的地方,然后每进入一个房子,会消耗一定的生命值(有可能是负),问你一 ...
- 免費域名申請.me .im .in .co .la .do .ms .kz .tk .ru .mu .pn .tt
免費申請域名 .la .la 域名 – 原先是ICANN分配給老撾的國家頂級域名,不過後來被同時作為了美國洛杉矶市的域名後綴. 免費申請地址: http://www.idv.la http://www ...
- windows 下安装mysqlclient 包
正常情况下是可以直接用 pip install mysqlclient 进行安装的.如果你的机器上安装的既有python3 又有python2.7 的话,建议使用python -m pip insta ...
- 图片压缩之 PNG
作者:程志达链接:https://zhuanlan.zhihu.com/p/19570424来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. PNG(Portable N ...