Codeforces 1255F Point Ordering(凸包+叉积)
我们随机选取点1,2作为凸包的一个分割线,那么我们可以直接枚举剩下n-2个点找到他们和向量1-2的叉积大小与正负,然后我们可以根据叉积的正负,先将他们分割出两个区域,在向量1-2的下方还是上方,接下来找到距离向量1-2最高的点id1和最低点id2,接下来在通过向量id1-1再次分割再上方的点,同样最id2-1分割下方的点,这样就可以分割出了四个区域,最后通过叉积所得的值进行排序,因为这四个区域中的高度要么是递增要么是递减,因为题目严格保证是没有三点共线,那么这样就可以还原出来一个凸包。
// ——By DD_BOND #include<bits/stdc++.h> #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"; //#pragma GCC optimize(3)
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef unsigned long long ull; const int seed=;
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>? : -); } ll val[MAXN];
vector<Pll>l,r;
vector<ll>ans,down,up; int main(void)
{
ios::sync_with_stdio(false); cin.tie(); cout.tie();
// freopen("/My_Mac/Resource/Project__C++/testdata.in","r",stdin);
//freopen("/My_Mac/Resource/Project__C++/testdata.out","w",stdout);
int n; cin>>n;
ans.pb(); ans.pb();
ll MAX=,MIN=,id1=,id2=;
for(int i=;i<=n;i++){
ll f=,area=;
cout<<"1 1 2 "<<i<<endl; cout.flush(); cin>>area;
cout<<"2 1 2 "<<i<<endl; cout.flush(); cin>>f;
val[i]=area; area*=f;
if(area>) up.pb(i);
else down.pb(i);
if(area>MAX) MAX=area,id1=i;
if(area<MIN) MIN=area,id2=i;
}
for(auto i:down){
ll f;
if(i==id2) continue;
cout<<<<' '<<id2<<' '<<<<' '<<i<<endl; cout.flush(); cin>>f;
if(f==) l.pb(Pll(val[i],i));
else r.pb(Pll(val[i],i));
}
sort(l.begin(),l.end());
for(auto i:l) ans.pb(i.se);
if(id2!=) ans.pb(id2);
sort(r.begin(),r.end(),greater<Pll>());
for(auto i:r) ans.pb(i.se);
ans.pb();
l.clear(); r.clear(); for(auto i:up){
if(i==id1) continue;
ll f;
cout<<<<' '<<id1<<' '<<<<' '<<i<<endl; cout.flush(); cin>>f;
if(f==) l.pb(Pll(val[i],i));
else r.pb(Pll(val[i],i));
}
sort(l.begin(),l.end());
for(auto i:l) ans.pb(i.se);
if(id1!=) ans.pb(id1);
sort(r.begin(),r.end(),greater<Pll>());
for(auto i:r) ans.pb(i.se);
l.clear(); r.clear();
for(auto i:ans) cout<<i<<' ';
cout.flush();
return ;
}
Codeforces 1255F Point Ordering(凸包+叉积)的更多相关文章
- Codeforces 1254C/1255F Point Ordering (交互题)
题目链接 http://codeforces.com/contest/1254/problem/C 题解 sb题. 第一次,通过\((n-2)\)次询问2确定\(p[2]\),也就是从\(1\)来看& ...
- Codeforces 166B - Polygon (判断凸包位置关系)
Codeforces Round #113 (Div. 2) 题目链接:Polygons You've got another geometrical task. You are given two ...
- [ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积
问有多少个点在多边形内 求一遍叉积 小于零计数就好了~ #include<stdio.h> #include<iostream> #include<algorithm&g ...
- Codeforces 1045F Shady Lady 凸包+数学
题目链接:https://codeforc.es/contest/1045/problem/F 题意:先给出一个系数不确定的二元多项式,Borna可以给这个多项式的每一项填上正的系数,Ani能从这个多 ...
- poj3348 Cows 凸包 叉积求多边形面积
graham扫描法,参考yyb #include <algorithm> #include <iostream> #include <cstdio> #includ ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces Round #437 (Div. 2)[A、B、C、E]
Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...
- codeforces 70D Professor's task(动态二维凸包)
题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...
- 计算几何基础——矢量和叉积 && 叉积、线段相交判断、凸包(转载)
转载自 http://blog.csdn.net/william001zs/article/details/6213485 矢量 如果一条线段的端点是有次序之分的话,那么这种线段就称为 有向线段,如果 ...
随机推荐
- Ubuntu下安装CUDA8.0及nvidia驱动
参考:https://blog.csdn.net/qq_35379989/article/details/80147630 cuda的历史版本下载地址:https://developer.nvidia ...
- Haproxy-4层和7层代理负载实战
目录 HAProxy是什么 HAProxy的核心能力和关键特性 HAProxy的核心功能 HAProxy的关键特性 HAProxy的安装和运行 安装 运行 添加日志 使用HAProxy搭建L7负载均衡 ...
- Linux入门培训教程 linux下拷贝cp删除rm移动mv命令参数以及说明
拷贝移动删除在windows中看起来这么简单,但linux经常使用的文字界面,所以对于linux系统 下拷贝cp删除 rm 移动mv命令参数就不得不需要了解和学习了 cp 该命令的功能是将给出的文件或 ...
- jQery Datatables回调函数中文
Datatables——回调函数 ------------------------------------------------- fnCookieCallback:还没有使用过 $(documen ...
- 举例子说明ubuntu中remove,autoremove,purge区别
转自:慎用 apt-get autoremove ! apt-get 提供了一个用于下载和安装软件包的简易命令行界面.卸载软件包主要有这3个命令 remove – 卸载软件包autoremove ...
- MySQL_DML操作
DML(Data Manipulation Laguage)指对数据库数据的增(Create)删(Delete)改(Update)操作 1.增加操作 (1)先创建一个表,如图所示: 语法:Insert ...
- 2018-2019-2 20165235《网络对抗技术》Exp8 Web基础
2018-2019-2 20165235<网络对抗技术>Exp8 Web基础 实践过程记录: (1).Web前端HTML 能正常安装.启停Apache.理解HTML,理解表单,理解GET与 ...
- CentOS关闭系统不必要的端口
注:以下所有操作均在CentOS 7.2 x86_64位系统下完成. 1)首先查看当前系统开放的端口号: # netstat -tlnup Active Internet connections (o ...
- ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)E Eve
E: 模拟题,一开始有n个人(有男有女),对于子女来说线粒体DNA是继承母亲的.然后有m个操作(按时间顺序),一种就是给了父亲,母亲的ID,生了一个孩子(编号从n+1开始往下):还有一个就是 -x , ...
- linux下插入U盘自动挂载后,用C获取其挂载点(cat /proc/mounts)
现在已经能够通过libudev获取U盘插入时它的节点名(通过函数udev_device_get_devnode()),是/dev/sdb1 我现在的做法是读取/proc/mounts文件,找到有/de ...