题目大意:

给定n 为n个点

给定n个点的坐标

两个点(xi,yi) (xj,yj)之间的花费是 xi*yj-yi*xj (可能为负数)

要求从点1经过若干个点到点n最小花费的路径 且路径要按x轴方向(即x递增)

输出路径顺序经过的点的编号

使花费最小 而花费又可能为负数 那么就尽量使得花费为负数

所以点的方向一直为顺时针的话就能使得花费最小 也就是一个上凸包

题解:https://www.cnblogs.com/mountaink/p/9591414.html

BTW 这题似乎没有考虑精度误差 加上精度误差的判断反而会WA

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define LL long long
#define mem(i,j) memset(i,j,sizeof(i))
using namespace std;
const int N=2e5+;
const int MOD=1e9+;
const double EPS=1e-; struct P {
double x,y; int id=;
P(){} P(double x,double y):x(x),y(y){}
P operator -(P p) { return P(x-p.x,y-p.y); }
P operator +(P p) { return P(x+p.x,y+p.y); }
double dot(P p) { return x*p.x+y*p.y; }
double det(P p) { return x*p.y-y*p.x; }
bool operator <(const P& p)const {
if(x!=p.x) return x<p.x;
if(y!=p.y) return y<p.y;
return id<p.id;
}
bool operator ==(const P& p)const {
return x==p.x && y==p.y;
}
void scf() { scanf("%lf%lf",&x,&y); }
}p[N], ans[N];
int n;
int andrew() {
sort(p+,p++n);
int c=;
for(int i=;i<=n;i++) {
if(i> && p[i]==ans[c-]) continue;
while(c> && (p[i]-ans[c-]).det(ans[c-]-ans[c-])>=) {
if((p[i]-ans[c-]).det(ans[c-]-ans[c-])>) c--;
else if(ans[c-].id>p[i].id) c--;
else break;
}
ans[c++]=p[i];
}
return c;
} int main()
{
int t; scanf("%d",&t);
while(t--) {
scanf("%d",&n);
for(int i=;i<=n;i++) p[i].scf(), p[i].id=i;
int c=andrew();
for(int i=;i<c-;i++)
printf("%d ",ans[i].id);
printf("%d\n",ans[c-].id);
} return ;
}

hdu6325 /// 上凸包的更多相关文章

  1. hdu6325 Interstellar Travel 凸包变形

    题目传送门 题目大意: 给出n个平面坐标,保证第一个点和第n个点y值为0,其余点的x坐标都在中间,要从 i 点走到 j 点的要求是 i 点的横坐标严格小于 j 的横坐标,并且消耗的能量是(xi * y ...

  2. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  3. 【BZOJ 2300】 2300: [HAOI2011]防线修建 (动态凸包+set)

    2300: [HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上 ...

  4. hdu 1348 Wall(凸包模板题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. HDU ACM 1392 Surround the Trees-&gt;凸包

    分析:直接求出凸包.再算边长就可以. 另外仅仅有一个点时为0.00单独处理,两个点直接为距离也单独处理. #include<iostream> #include<cmath> ...

  6. poj 1228 凸包

    题目链接:http://poj.org/problem?id=1228 #include<cstdio> #include<cstring> #include<cmath ...

  7. poj 3608 旋转卡壳求不相交凸包最近距离;

    题目链接:http://poj.org/problem?id=3608 #include<cstdio> #include<cstring> #include<cmath ...

  8. UVa1453或La4728 凸包+枚举(或旋转卡壳)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. poj 2187 凸包加旋转卡壳算法

    题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...

随机推荐

  1. 获取项目根目录(非tomact)

    String path; public void main(String[] args) { File file=new File(""); path=file.getAbsolu ...

  2. SQL必知必会——思维导图

    Xmind实在太坑了,竟然不能导出高清图片,我回来折腾个PS整一下!

  3. 【Java】 java判断字符串是否为空的方法总结

    以下是java 判断字符串是否为空的四种方法: 方法一: 最多人使用的一个方法, 直观, 方便, 但效率很低: if(s == null ||"".equals(s));方法二: ...

  4. 实现一个EventEmitter类,这个类包含以下方法: on/ once/fire/off

    实现一个EventEmitter类,这个类包含以下方法: on(监听事件,该事件可以被触发多次)- once(也是监听事件,但只能被触发一次)- fire(触发指定的事件)- off(移除指定事件的某 ...

  5. 学习记录:@Transactional 事务不生效

    测试时使用spring boot2.2.0,在主类中调用,@Transactional 不起作用,原代码如下: @SpringBootApplication @Slf4j @Component pub ...

  6. C# System.Windows.Forms.Panel

    UserControl 定义的界面 输出到panel 实现界面切换

  7. memcache常用操作

    Command Description Example get 读取键值 get mykey set 设置新键值 set mykey 0 60 5 add 新增键值 add newkey 0 60 5 ...

  8. Delphi如何获取一个字符串再另一个字符串中最后一次出现的位置

    uses StrUtils;   function ReversePos(SubStr, S: String): Integer; var   i : Integer; begin   i := Po ...

  9. Buffering Data

    We keep telling you that you always need to close your files after you're done writing to them. Here ...

  10. shell脚本每五分钟执行一次可执行程序(nohup)

    两种解决方案:个人推荐第二种,使用crontab来定时执行任务   1.shell代码如下: nohup command &. 解释: 后台永久运行command命令. (nohup表示后台永 ...