Codeforces 1159F Winding polygonal line(叉积)
其实这个几何写起来还是比较方便,只用到了叉积。首先我们贪心的考虑一种情况,对于任意给定的LR串,我们起点的选择肯定是在这些点围成的凸包端点上,对于这样的起点来说,他对于L或者R都是有选择的机会,而且一定可以从剩下n-1个点选出两个点满足要求(可以画图观察),接下来我们对于这个起点出发开始去寻找满足LR的点,对于第二个点来说,我们需要去找到剩下n-1个点中最外侧的点,并且满足剩下n-2个点都在向量point[1]-point[0]的左侧或者右侧,这个可以直接由叉积得到,那么我们便得到了第二个点,显然第二个点也一定是在剩下n-1个点围成的凸包端点上,无论取剩下n-2个点中的任何一个都是满足两个向量满足 point[2]-point[1],point[1]-point[0]的向量转向满足s[0],那么问题就可以看成是一个 n'=n-2 的新问题,那么此时起点是point[1],那么依然通过上述方法找到point[2],反复如此,直到找到 n-1 个点,最后剩下一个点必然满足最后一个s的转向,那么此题也是没有-1的情况。
// ——By DD_BOND //#include<bits/stdc++.h>
#include<functional>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<cstddef>
#include<cstdio>
#include<memory>
#include<vector>
#include<cctype>
#include<string>
#include<cmath>
#include<queue>
#include<deque>
#include<ctime>
#include<stack>
#include<map>
#include<set> #define fi first
#define se second
#define MP make_pair
#define pb push_back
#define INF 0x3f3f3f3f
#define pi 3.1415926535898
#define lowbit(a) (a&(-a))
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define Min(a,b,c) min(a,min(b,c))
#define Max(a,b,c) max(a,max(b,c))
#define debug(x) cerr<<#x<<"="<<x<<"\n"; using namespace std; typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef unsigned long long ull; const ll LLMAX=2e18;
const int MOD=1e9+;
const double eps=1e-;
const int MAXN=1e6+;
const int hmod1=0x48E2DCE7;
const int hmod2=0x60000005; inline ll sqr(ll x){ return x*x; }
inline int sqr(int x){ return x*x; }
inline double sqr(double x){ return x*x; }
ll __gcd(ll a,ll b){ return b==? a: __gcd(b,a%b); }
ll qpow(ll a,ll n){ll sum=;while(n){if(n&)sum=sum*a%MOD;a=a*a%MOD;n>>=;}return sum;}
inline int dcmp(double x){ if(fabs(x)<eps) return ; return (x>? : -); } int use[MAXN];
vector<int>ans; struct Point{
ll x,y,id;
Point(){ x=y=; }
Point(ll a,ll b){ x=a,y=b; }
Point operator -(const Point &n)const{
return Point(x-n.x,y-n.y);
}
bool operator <(const Point &n)const{
if(x==n.x) return y<n.y;
return x<n.x;
}
}point[MAXN]; int dcmp(ll x){
if(x==) return ;
return x>? : -;
} bool cmp(Point a,Point b){
return a.id<b.id;
} ll cross(Point a,Point b){
return a.x*b.y-a.y*b.x;
} int main(void)
{
ios::sync_with_stdio(false); cin.tie(); cout.tie();
int n; cin>>n;
for(int i=;i<=n;i++) cin>>point[i].x>>point[i].y,point[i].id=i;
string s; cin>>s;
sort(point+,point+n+);
ans.pb(point[].id),use[point[].id]=;
sort(point+,point+n+,cmp);
for(int i=;i<s.size();i++){
int k=,flag=(s[i]=='L'? : -);
for(int j=;j<=n;j++){
if(use[j]) continue;
if(!k||dcmp(cross(point[k]-point[ans[i]],point[j]-point[k]))!=flag) k=j;
}
ans.pb(k),use[k]=;
}
for(int i=;i<=n;i++)
if(!use[i])
ans.pb(i);
for(auto i:ans) cout<<i<<' ';
return ;
}
Codeforces 1159F Winding polygonal line(叉积)的更多相关文章
- [codeforces 549]G. Happy Line
[codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...
- codeforces 251A Points on Line(二分or单调队列)
Description Little Petya likes points a lot. Recently his mom has presented him n points lying on th ...
- [ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积
问有多少个点在多边形内 求一遍叉积 小于零计数就好了~ #include<stdio.h> #include<iostream> #include<algorithm&g ...
- codeforces 431 B Shower Line【暴力】
题意:给出五个人的编号,分别为 1 2 3 4 5,他们在排队, 最开始的时候,1和2可以交谈,3和4可以交谈 然后1走了之后,2和3交谈,4和5可以交谈 2走了之后,3和4可以交谈, 3走了之后,4 ...
- @codeforces - 594E@ Cutting the Line
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个字符串 s 与正整数 k.现在你需要进行恰好一次操作: ...
- Codeforces VP/补题小记 (持续填坑)
Codeforces VP/补题小记 1149 C. Tree Generator 给你一棵树的括号序列,每次交换两个括号,维护每次交换之后的直径. 考虑括号序列维护树的路径信息和,是将左括号看做 ...
- Codeforces GYM 100114 B. Island 水题
B. Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description O ...
- CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...
- Codeforces Round #328 (Div. 2) D. Super M 虚树直径
D. Super M Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/D ...
随机推荐
- Vscode窗口被覆盖
用Vscode用的好好的,突然就发现窗口被覆盖了 解决办法如下:1.ctrl+shift+p 快捷键打开如下界面, 2.接着在搜索框中输入settings,点击首先项:打开设置(json) 3.再se ...
- LOJ 6192 城市网络(树上倍增)
LOJ #6192. 「美团 CodeM 复赛」城市网络(链接) 一棵以 $ 1 $ 号节点为根的树,每个点有一个权值,有 $ q $ 个询问,每次从 $ x $ 点开始往某个祖先 $ y $ 走,初 ...
- MySQL简版(一)
第一章 数据库的基本概念 1.1 数据库的英文单词 Database,简称DB. 1.2 什么是数据库? 用于存储和管理数据的仓库. 1.3 数据库的特点 持久化存储数据的.其实数据库就是一个文件系统 ...
- MySQL技巧--伪哈希索引
哈希索引 哈希索引就是通过一个哈希函数计算出某个key的hash值,并以这个hash值去找到目标数据.例如:对于数据库的一行数据,对其主键进行hash运算,得到一个地址,这个地址指向这行记录的存储地址 ...
- Git之仓库管理
介绍以及安装: Git 是一个开源的分布式版本控制软件,用以有效.高速的处理从很小到非常大的项目版本管理. Git 最初是由Linus Torvalds设计开发的,用于管理Linux内核开发.Git ...
- zrender笔记----(数字Number组件)出现的问题和解决办法
1.期望的效果是这样子的(这也是最终结果): 2.开始是用json假数据,开始没考虑null的问题,导致在判断传值处,判断有误. 导致在对接接口时,凌乱了,后来修改了下变成后面图C的逻辑,json数据 ...
- Java——常用类(String)
[常用类] <1>字符串相关类(String.StringBuffer) <2>基本数据类型包装类 <3>Math类 <4>File类 ...
- Leetcode 6. ZigZag Conversion(找规律,水题)
6. ZigZag Conversion Medium The string "PAYPALISHIRING" is written in a zigzag pattern on ...
- Web开发者易犯的五大严重错误
无论你是编程高手,还是技术爱好者,在进行Web开发过程中,总避免不了犯各种各样的错误. 犯了错误,可以改正.但如果犯了某些错误,则会带来重大损失.遗憾.令人惊讶的是,这些错误往往是最普通,最容易避免. ...
- 12 Django组件-form组件
知识预览 forms组件 forms组件 校验字段功能 针对一个实例:注册用户讲解. 模型:models.py class UserInfo(models.Model): name=models.Ch ...