题解:每放一根棍子,都判断一下它与它前面的且在顶端的棍子是否相交,相交的话则将相应的棍子从解空间中除去。

#include <cstdio>
const double eps=1e-14;
const int maxn=1e5+10;
struct node{double x1,y1,x2,y2;int w;}e[maxn],f[maxn];
double cross(double x1,double y1,double x2,double y2){return x1*y2-x2*y1;}
int find(node a,node b){
double c[4];
c[0]=cross(a.x2-a.x1,a.y2-a.y1,b.x1-a.x1,b.y1-a.y1);
c[1]=cross(a.x2-a.x1,a.y2-a.y1,b.x2-a.x1,b.y2-a.y1);
c[2]=cross(b.x2-b.x1,b.y2-b.y1,a.x1-b.x1,a.y1-b.y1);
c[3]=cross(b.x2-b.x1,b.y2-b.y1,a.x2-b.x1,a.y2-b.y1);
if(c[0]*c[1]<=0&&c[2]*c[3]<=0)return 1;
return 0;
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n==0)break;
int i,j,k,p,q;
for(i=0;i<n;i++){
scanf("%lf%lf%lf%lf",&e[i].x1,&e[i].y1,&e[i].x2,&e[i].y2);
e[i].w=i+1;
}p=0;
for(i=0;i<n;i++){
q=0;
for(j=0;j<p;j++)
if(!find(e[i],f[j]))f[q++]=f[j];
f[q++]=e[i];
p=q;
}
printf("Top sticks: %d",f[0].w);
for(i=1;i<p;i++)printf(", %d",f[i].w);
printf(".\n");
}
return 0;
}

HDU 1147 Pick-up sticks的更多相关文章

  1. hdu 5543 Pick The Sticks(动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:给你一根长为m的长木板和一些小木棒,每一根小木棒有它的长度和价值,这些小木棒要放在长木板上 ...

  2. HDU 5543 Pick The Sticks:01背包变种

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意: 给你N个金条和一张长度为L的桌子.每个金条长度为a[i],价值为w[i].金条只能在桌子 ...

  3. HDU 5543 Pick The Sticks

    背包变形.与普通的背包问题不同的是:允许有两个物品可以花费减半. 因此加一维即可,dp[i][j][k]表示前i个物品,有j个花费减半了,总花费为k的情况下的最优解. #pragma comment( ...

  4. The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543

    Pick The Sticks Time Limit: 15000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  5. 2015南阳CCPC D - Pick The Sticks dp

    D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...

  6. CDOJ 1218 Pick The Sticks

    Pick The Sticks Time Limit: 15000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

  7. 2015南阳CCPC D - Pick The Sticks 背包DP.

    D - Pick The Sticks Description The story happened long long ago. One day, Cao Cao made a special or ...

  8. hdu 1147:Pick-up sticks(基本题,判断两线段相交)

    Pick-up sticks Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  9. [HDOJ5543]Pick The Sticks(DP,01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:往长为L的线段上覆盖线段,要求:要么这些线段都在L的线段上,要么有不超过自身长度一半的部分 ...

随机推荐

  1. MATLAB中求矩阵非零元的坐标

    MATLAB中求矩阵非零元的坐标: 方法1: index=find(a); [i,j]=ind2sub(size(a),index); disp([i,j]) 方法2: [i,j]=find(a> ...

  2. openwrt看IP流量

    可以利用iptable来实现的,看附件的脚本. 把他放到路由器里面,然后运行. #!/bin/sh echo "Collecting data..." echo "&qu ...

  3. window.external.JavaScriptCallCpp

    方案2: 1.编写html <html> <head> </head> <body> <script language="javascr ...

  4. 开源libusb驱动的libwdi驱动安装API库和zadig.exe安装UI应用程序的编译和调试

    一.目的 二.编译环境 系统:Win7 ~ Win10 编译工具:Visual Studio 2008 或 Visual Studio 2010 或Visual Studio 2015 libwdi编 ...

  5. 【LeetCode题意分析&解答】40. Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  6. oracle 两表数据对比---minus

        1 引言 在程序设计的过程中,往往会遇到两个记录集的比较.如华东电网PMS接口中实现传递一天中变更(新增.修改.删除)的数据.实现的方式有多种,如编程存储过程返回游标,在存储过程中对两批数据进 ...

  7. CF# 260 A. Laptops

    One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the m ...

  8. SharePoint 2007 (MOSS/WSS) - how to remove "Download a Copy" context menu from a Document Library

    One of my friend and colleague asked me this question. I found it tricky and a good post for my blog ...

  9. Jquery ajax调用后台aspx后台文件方法(不是ashx)

    在asp.net webForm开发中,用Jquery ajax调用aspx页面的方法常用的有两种:下面我来简单介绍一下. (1)通过aspx.cs的静态方法+WebMethod进行处理 简单的介绍下 ...

  10. untiy 播放视频

    利用 MovieTexture 类 放入视频 视频不能使flv的 建立一个平面 作为屏幕,利用Material 播放动画,剩下的就是将平面放大和屏幕一样/ public MovieTexture My ...