我们随机选取点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(凸包+叉积)的更多相关文章

  1. Codeforces 1254C/1255F Point Ordering (交互题)

    题目链接 http://codeforces.com/contest/1254/problem/C 题解 sb题. 第一次,通过\((n-2)\)次询问2确定\(p[2]\),也就是从\(1\)来看& ...

  2. Codeforces 166B - Polygon (判断凸包位置关系)

    Codeforces Round #113 (Div. 2) 题目链接:Polygons You've got another geometrical task. You are given two ...

  3. [ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积

    问有多少个点在多边形内 求一遍叉积 小于零计数就好了~ #include<stdio.h> #include<iostream> #include<algorithm&g ...

  4. Codeforces 1045F Shady Lady 凸包+数学

    题目链接:https://codeforc.es/contest/1045/problem/F 题意:先给出一个系数不确定的二元多项式,Borna可以给这个多项式的每一项填上正的系数,Ani能从这个多 ...

  5. poj3348 Cows 凸包 叉积求多边形面积

    graham扫描法,参考yyb #include <algorithm> #include <iostream> #include <cstdio> #includ ...

  6. C - Ordering Pizza CodeForces - 867C 贪心 经典

    C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...

  7. Codeforces Round #437 (Div. 2)[A、B、C、E]

    Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...

  8. codeforces 70D Professor's task(动态二维凸包)

    题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...

  9. 计算几何基础——矢量和叉积 && 叉积、线段相交判断、凸包(转载)

    转载自 http://blog.csdn.net/william001zs/article/details/6213485 矢量 如果一条线段的端点是有次序之分的话,那么这种线段就称为 有向线段,如果 ...

随机推荐

  1. 【leetcode】Find K Pairs with Smallest Sums

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...

  2. print和赋值

    赋值 #可同时(并行)给多个变量赋值 x, y, z = 1, 2, 3 #交换多个变量的值 x, y = y, x 序列解包(或可迭代对象解包):将一个序列(或任何可迭代对象)解包,并将得到的值存储 ...

  3. net core 返回404方法

    public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { ...

  4. java大文件上传

    上次遇到这样一个问题,客户上传高清视频(1G以上)的时候上传失败. 一开始以为是session过期或者文件大小受系统限制,导致的错误.查看了系统的配置文件没有看到文件大小限制,web.xml中sees ...

  5. [BZOJ4011][HNOI2015]落忆枫音:拓扑排序+容斥原理

    分析 又是一个有故事的题目背景.作为玩过原作的人,看题目背景都快看哭了ToT.强烈安利本境系列,话说SP-time的新作要咕到什么时候啊. 好像扯远了嘛不管了. 一句话题意就是求一个DAG再加上一条有 ...

  6. arguments详解——函数内命名参数之映射

    首先,arguments对象是所有(非箭头)函数中都可用的局部变量.你可以使用arguments对象在函数中引用函数的参数.此对象包含传递给函数的每个参数,第一个参数在索引0处. arguments对 ...

  7. 手动创建Maven项目并建立两个项目之间的依赖关系

    用命令行快速建立maven项目 -> mvn:archetype:generate -> 直接回车或者自己输入你想生成的 -> groupId ->artifactId -&g ...

  8. android开机引导界面的几种实现

    不少应用在设计的时候都会有几个引导界面,这里总结一下几个典型实现: 之前自己做过仅具有一个引导界面的应用,在welcomeActivity中设置一张图片,更复杂的为该图片设置一个渐入渐出的动画,然后利 ...

  9. HBase调优案例(二)——高并发下bulkload出现超时

    原因分析: 导入数据——>HBase,在客户端会发生非常多的rpc请求到regionServer,从而加大regionServer上的压力,如果regionServer比较忙碌(handle被占 ...

  10. 《Effective Java》读书笔记 - 7.方法

    Chapter 7 Methods Item 38: Check parameters for validity 直接举例吧: /** * ...其他的被我省略了 * @throws Arithmet ...