POJ 2653 Pick-up sticks(几何)
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 13377 | Accepted: 5039 |
Description
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
Source
题解:
几何模板题目
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long LL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define eps 0.0001
const LL INF = 0x7fffffff;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+;
const int maxn = +;
int n, cnt;
struct POINT
{
double x, y, z;
POINT():x(), y(), z(){};
POINT(double _x_, double _y_, double _z_ = ):x(_x_), y(_y_), z(_z_) {};
};
struct SEG
{
POINT a;
POINT b;
SEG(){};
SEG(POINT _a_, POINT _b_):a(_a_),b(_b_) {};
};
double Cross(const POINT &a, const POINT & b, const POINT &o)//叉乘
{
return (a.x - o.x)*(b.y - o.y) - (b.x - o.x)*(a.y - o.y);
}
bool IsIntersect(const SEG &u, const SEG &v)
{
return (Cross(v.a, u.b, u.a)*Cross(u.b, v.b, u.a)>=)&&
(Cross(u.a, v.b, v.a)*Cross(v.b, u.b, v.a)>=)&&
(max(u.a.x, u.b.x) >= min(v.a.x, v.b.x))&&
(max(v.a.x, v.b.x) >= min(u.a.x, u.b.x))&&
(max(u.a.y, u.b.y) >= min(v.a.y, v.b.y))&&
(max(v.a.y, v.b.y) >= min(u.a.y, u.b.y));
}
int ans[maxn];
SEG stick[maxn];
void init()
{
cnt = ;
}
void solve() {
double a, b, c, d;
for(int i = ;i<=n;i++){
scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
stick[i].a.x=a;stick[i].a.y=b;
stick[i].b.x=c;stick[i].b.y=d;
}
for(int i = n;i>;i--){
bool flag = ;
for(int j = i+;j<=n;j++){
if(IsIntersect(stick[i], stick[j])){
flag = ;
break;
}
}
if(flag){
ans[cnt++] = i;
}
if(cnt>=){
break;
}
}
printf("Top sticks:");
for(int i = cnt-;i>=;i--){
if(i==) printf(" %d.",ans[i]);
else printf(" %d,",ans[i]);
}
printf("\n");
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
while(~scanf("%d", &n)&&n){
init();
solve();
}
return ;
}
POJ 2653 Pick-up sticks(几何)的更多相关文章
- 【POJ 2653】Pick-up sticks 判断线段相交
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...
- 线段相交 POJ 2653
// 线段相交 POJ 2653 // 思路:数据比较水,据说n^2也可以过 // 我是每次枚举线段,和最上面的线段比较 // O(n*m) // #include <bits/stdc++.h ...
- poj 2653 线段与线段相交
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11884 Accepted: 4499 D ...
- 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 ...
- POJ 2653 Pick-up sticks --队列,几何
题意: 按顺序扔木棒,求出最上层的木棒是哪些. 解法: 由于最上层的木棒不超过1000个,所以用一个队列存储最上层的木棒,每次扔出一个木棒后,都与队列中的木棒一一判断,看此木棒是否在某一最上层的木棒的 ...
- 简单几何(线段相交) POJ 2653 Pick-up sticks
题目传送门 题意:就是小时候玩的一种游戏,问有多少线段盖在最上面 分析:简单线段相交,队列维护当前最上的线段 /******************************************** ...
随机推荐
- 浅谈数学上的矩阵——矩阵的乘法运算的概念及C++上的实现模板
首先让我们来谈一谈数学意义上的矩阵(在座各位也可以简单地将它理解为一个二维数组) 这样可以帮助我们理解矩阵加速及其运用的原理(矩阵加速是一个及其玄学的东西,所以请重点理解矩阵乘法) 这里给出一段严格 ...
- SpringBoot中FreeMarker创建
1.创建SpringBoot项目时,勾选freemarker依赖(web,dev) 2.Controller中向model中存放数据 package com.ziv.springbootbygrald ...
- WPF资源字典的使用
1.在解决方案中添加资源字典:鼠标右键——添加——资源字典 2.在资源字典中写入你需要的样式,我这里简单的写了一个窗体的边框样式 3.在App.xaml中加入刚刚新建的资源字典就好了
- oracle--优化思路
- [Web 前端] 001 html 常用块级标签
目录 1. html "总体框架" 2. 常用的 HTML 块级标签(块元素) 2.1 知识点 2.2 以下 code 均写在 body 体中 2.2.1 标题标签,只有 h1-h ...
- Yarn 工作机制
1.工作机制详述 (1)MR程序提交到客户端所在的节点. (2)YarnRunner向ResourceManager申请一个Application. (3)RM将该应用程序的资源路径返回给YarnRu ...
- Redis基础都不会,好意思出去面试?
作者:张君鸿 juejin.im/post/5d078cd6f265da1b8466e62c Redis的数据结构 Redis支持多种不同的数据结构,包括5种基础数据结构和几种比较复杂的数据,这些数据 ...
- c++ const 修饰变量位置含义
c++ const 修饰变量位置含义 const 修饰成员变量 const修饰指针变量时: 只有一个const,如果const位于*左侧,表示指针所指数据是常量,也就是指向常量的指针,不能通过解引用修 ...
- Django:django-debug-toolbar模块
简介: Django的django-debug-toolbar 模块是一组可配置的面板,可显示有关当前请求/响应的各种调试信息,并在单击时显示有关面板内容的更多详细信息. GitHub源文件下载地址 ...
- 【JAVA】input.next().charAt(0);的含义
接收键盘输入的字符串,并且取出它的第一个字符. 分析: Scanner scan=new Scanner(System.in); String s=scan.next(); //返回一个String ...