我们随机选取点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. vue学习-day02(自定义指令,生命周期)

    目录: 1.案例:品牌管理    2.Vue-devtools的两种安装方式    3.过滤器,自定义全局或私有过滤器    4.鼠标按键事件的修饰符    5.自定义全局指令:让文本框获取焦点   ...

  2. string [线段树优化桶排]

    题意大概是给你一个字符串,1e5次修改,每次给一个区间升序排列或降序排列,最后输出这个字符串; 其实是个挺裸的线段树优化题;但是我没有意识去结合桶排,扑该..... 首先 1.40分算法 O(NMlo ...

  3. 【python学习之五】自定义函数实现用 Python 发送电子邮件

    前言 之前论坛里有人发过关于发送邮件的帖子,设计器也有关于发送邮件的控件.我这里再次重复,希望能有帮到大家的地方. 信息准备 发送邮件前必须准备好一些基本信息,例如发件人邮箱地址.发件人邮箱密码.收件 ...

  4. maven 高级玩法

    maven 高级玩法 标签(空格分隔): maven 实用技巧 Maven 提速 多线程 # 用 4 个线程构建,以及根据 CPU 核数每个核分配 1 个线程进行构建 $ mvn -T 4 clean ...

  5. python中类的设计问题(一些高级问题探讨,函数重载,伪私有,工厂模式,类方法等)

    从这里再次体现了python语言强大的灵活性.某些在高级语言中看似不严谨需要尽量避免的地方在python中都是允许的. 比如: (1),异常可以用来处理错误 (2),方法,类也都可以视为对象. (3) ...

  6. 第五周总结 & 实验报告(三)

    第五周总结 一.继承       1.类的继承格式 class 父类{} class 子类 extends 父类{} 2.扩展类的功能 class 父类{ 父类属性: .......... ..... ...

  7. 高级软件测试技术-任务进度-Day02

    任务进度11-14 使用工具 Jira 小组成员 华同学.郭同学.穆同学.沈同学.覃同学.刘同学 任务进度 在经过了昨天的基本任务分配之后,今天大家就开始了各自的内容,以下是大家任务的进度情况汇总. ...

  8. idea中查看一个类的调用用和被调用用关系

  9. LeetCode_509.斐波那契数

    LeetCode-cn_509 509.斐波那契数 斐波那契数,通常用 F(n) 表示,形成的序列称为斐波那契数列.该数列由 0 和 1 开始,后面的每一项数字都是前面两项数字的和.也就是: F(0) ...

  10. linux交叉编译Windows版本的ffmpeg

    主要参考http://www.cnblogs.com/haibindev/archive/2011/12/01/2270126.html 在我的机器上编译libfaac的时候 出现问题了 输出如下 . ...