Pick-up sticks
Pick-up sticks
Input
Output
The picture to the right below illustrates the first case from input.
Sample Input
5 1 1 4 2 2 3 3 1 1 -2.0 8 4 1 4 8 2 3 3 6 -2.0 3 0 0 1 1 1 0 2 1 2 0 3 1 0
Sample Output
Top sticks: 2, 4, 5. Top sticks: 1, 2, 3.
Hint
题目大意,先后给出n条直线,求最后哪些直线上没有直线.
那么,由于n最大100000,所有肯定不能用普通的来.
其实,我们只要记录最上面的几条直线就行了,并且可以用动态数组来.毕竟只有100000条直线,却有可能有n个集合,也有可能只有1个,所有,用vector代替普通的数组是再好不过的了.
然而,数据实在太强,还是TLE了.然而...暴力加break优化却AC了!!!
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define Vec point
using namespace std;
;
vector <int> que;
int n;
];
struct point{
double x,y;
void read(){scanf("%lf%lf",&x,&y);}
}seg[][];
:x>eps;}
Vec operator + (point u,Vec v){
Vec ret; ret.x=u.x+v.x,ret.y=u.y+v.y;
return ret;
}
Vec operator - (point u,point v){
Vec ret; ret.x=u.x-v.x,ret.y=u.y-v.y;
return ret;
}
Vec operator * (Vec u,double v){
Vec ret; ret.x=u.x*v,ret.y=u.y*v;
return ret;
}
Vec operator / (Vec u,double v){
Vec ret; ret.x=u.x/v,ret.y=u.y/v;
return ret;
}
double cross(Vec u,Vec v){return u.x*v.y-u.y*v.x;}
bool dotonseg(point P,point U,point V){
) ;
) ;
;
}
bool intersect(point P,point Q,point U,point V){
&&fabso(cross(U-P,Q-P)*cross(V-P,Q-P))<) ;
bool g1=dotonseg(P,U,V);
bool g2=dotonseg(Q,U,V);
bool g3=dotonseg(U,P,Q);
bool g4=dotonseg(V,P,Q);
;
;
}
int main(){
for (scanf("%d",&n); n; scanf("%d",&n)){
memset(f,,sizeof f);
; i<=n; i++) seg[i][].read(),seg[i][].read();
; i<=n-; i++)
; j<=n; j++)
],seg[i][],seg[j][],seg[j][])){f[i]=; break;}
printf("Top sticks:");
; i<n; i++) if (f[i]) printf(" %d,",i);
printf(" %d.\n",n);
}
;
}
Pick-up sticks的更多相关文章
- 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 ...
- 2015南阳CCPC D - Pick The Sticks dp
D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...
- CDOJ 1218 Pick The Sticks
Pick The Sticks Time Limit: 15000/10000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others ...
- 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 ...
- UESTC 1218 Pick The Sticks
Time Limit: 15000/10000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Status ...
- hdu 5543 Pick The Sticks(动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:给你一根长为m的长木板和一些小木棒,每一根小木棒有它的长度和价值,这些小木棒要放在长木板上 ...
- DP(01背包) UESTC 1218 Pick The Sticks (15CCPC C)
题目传送门 题意:长度为L的金条,将n根金棍尽可能放上去,要求重心在L上,使得价值最大,最多有两条可以长度折半的放上去. 分析:首先长度可能为奇数,先*2.然后除了两条特殊的金棍就是01背包,所以dp ...
- [HDOJ5543]Pick The Sticks(DP,01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:往长为L的线段上覆盖线段,要求:要么这些线段都在L的线段上,要么有不超过自身长度一半的部分 ...
- uestc oj 1218 Pick The Sticks (01背包变形)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1218 给出n根木棒的长度和价值,最多可以装在一个长 l 的容器中,相邻木棒之间不允许重叠,且两边上的木棒,可 ...
- HDU 5543 Pick The Sticks
背包变形.与普通的背包问题不同的是:允许有两个物品可以花费减半. 因此加一维即可,dp[i][j][k]表示前i个物品,有j个花费减半了,总花费为k的情况下的最优解. #pragma comment( ...
随机推荐
- C# 调用Windows图片查看器
/// <summary> /// 查看原图 /// </summary> /// <param name="image"></param ...
- python 排序 由大到小
import functools class Solution: # @param {integer[]} nums # @return {string} def largestNumber(self ...
- python的json模块的dumps,loads,dump,load方法介绍
dumps和loads方法都在内存中转换, dump和load的方法会多一个步骤,dump是把序列化后的字符串写到一个文件中,而load是从一个文件中读取字符串 将列表转为字符串 >>&g ...
- hashtable详解
hashtable也比称作哈希表,键值对或者关联数组 1. 先引用using System.Collections;命名空间 用于处理和表现key/value的键值对,其中key通常用来快速查找,同时 ...
- AtCoder Regular Contest 100 Equal Cut
Equal Cut 思路: 枚举中间那个分界点,然后两边找使得切割后差值最小的点,这个可以用双指针 代码: #include<bits/stdc++.h> using namespace ...
- Linux下计划任务以及crontab权限问题
在Linux工作环境下,我们有时可能会需要在未来某个时间执行某个命令或脚本,但是我们又不可能定个闹钟,然后到点了再去执行吧,这多麻烦.还好我们的Linux系统这么强大,提供了任务计划这个功能,我们就不 ...
- Java创建WebService
从java 6之后就提供了简单快速的创建WebService的方法,这里将这种简单的方法记录下来方便以后回看.第一步:首先创建一个java Project,然后创建一个类HelloWorldImpl如 ...
- php中文件操作常用函数有哪些
php中文件操作常用函数有哪些 一.总结 一句话总结:读写文件函数 判断文件或者目录是否存在函数 创建目录函数 file_exists() mkdir() file_get_content() fil ...
- learn the python the hard way习题26~30总结
考试试题26错误总结: 漏写字母,括号 写错字母 write(),read()的使用:只能打开使用了 open() 后返回的文件对象(file object),而不能直接使用文件名 if 语句中,条件 ...
- VS2008版本引入第三方dll无强签名
sn.exe 和ilasm.exe 是系统自带程序.如果显示无此命令,可以从“我的电脑”直接搜索. 将dll文件放入目录下,用VS开发人员命令执行以下命令即可.(以Interop.Scripting. ...