我们随机选取点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. 016:URL命名与反转URL

    为什么需要URL命名? 主要解决蛋疼url变化情况,比如:哪天项目经理或领导过来说,把login改成signin,把register改成signup等蛋疼的需求——因为一旦改了url后,相关视图函数里 ...

  2. VMWare虚拟机启动不了有个叉叉的解决办法

    打开VMWare虚拟机提示有: This virtual machine appears to be in use. If this virtual machine is already in use ...

  3. BZOJ1491 Red is good

    题目链接:Click here Solution: 考虑设\(f(i,j)\)表示当前还有\(i\)张红牌,\(j\)张黑牌时的期望收益 易得状态转移方程:\(f(i,j)=\frac{i}{i+j} ...

  4. EMC存储同时分配空间到两台LINUX服务器路径不一致导致双机盘符大小不一致

    操作系统:Centos linux6.6 当我们从EMC存储上划分空间同时分配给两台或者多台服务器上时,有的时候会出现在服务器上所生成的磁盘路径是不一致的,这样就会导致盘符名称不一致或者是盘符对应的大 ...

  5. mac osx终端批量删除文件

    sudo su cd / find ./ -name "*.html" -exec rm -rf {} \;  注意 {}和\;之间有空格 find [目录名] -name &qu ...

  6. sqlite的系统表sqlite_master

      SQLite数据库中一个特殊的名叫 SQLITE_MASTER 上执行一个SELECT查询以获得所有表的索引.每一个 SQLite 数据库都有一个叫 SQLITE_MASTER 的表, 它定义数据 ...

  7. 在SOUI3中使用预编译XML

    传统的XML文件通常是utf8编码的文本文件.使用文本文件好处在于方便查阅及修改. SOUI使用XML做为布局描述语言,所有的布局资源都是XML.文本文件格式自由,XML解析器需要对文件中的字符逐个解 ...

  8. Vue开发调试神器 vue-devtools

    Vue开发调试神器: vue-devtools 1. 下载Chrome扩展插件GitHub下载地址: https://github.com/vuejs/vue-devtools 建议使用npm淘宝镜像 ...

  9. Jmeter接口测试系列之测试用例变量参数化处理

    在进行接口测试时,一组完整的接口测试用例,存在后一个测试用例使用前一个用例的请求结果中的数据,此时就需要参数化测试用例中值.直接使用变量调用会存在问题,此时就需要用到beanshell去改变. 举例说 ...

  10. 查询oracle中所有用户信息 禁用用户

    ----查询oracle中所有用户信息 ----1.查询数据库中的表空间名称 ----1)查询所有表空间 select tablespace_name from dba_tablespaces; se ...