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 矢量 如果一条线段的端点是有次序之分的话,那么这种线段就称为 有向线段,如果 ...
随机推荐
- 对云信SDK的研究1
1.云信大部分用了jq 2.很多接口 3.是可以文档很健全
- 启用Executor初始化线程池
前言 上文我们介绍了JDK中的线程池框架Executor.我们知道,只要需要创建线程的情况下,即使是在单线程模式下,我们也要尽量使用Executor.即: ExecutorService fixedT ...
- JDK中String类的源码分析(一)
1.String类是final的,不允许被继承 /** The value is used for character storage. */ private final char value[]; ...
- PM项目跟进护航文档模板
护航文档 版本需求列表 需求 开发责任人 MMDrawerController.GCDTimer.Speex_armv7s等11个库迁移 熊文杰 相关人员 职称 开发人员 开发 熊文杰 测试 xxx ...
- centos7 编译问题:aclocal-1.14: command not found
centos7 编译问题:aclocal-1.14: command not found https://blog.csdn.net/vr7jj/article/details/80438663
- js实现两个从input获取到的数字相加引发的问题
从input中获取到的数据是文本类型的,如果不转化类型直接相加会变成字符串的相加. 使用Number()函数可以解决这个问题,如下 var c = Number(a) + Number(b)
- webpack插件之webpack-dev-server
webpack插件之webpack-dev-server webpack插件 自动化 webpack-dev-server 现在只需要使用 npm run build指令就可以自动打包,并自动处理好 ...
- tensorflow源码分析——CTC
CTC是2006年的论文Connectionist Temporal Classification: Labelling Unsegmented Sequence Data with Recurren ...
- 十九、RF接口测试汇总(一)
搭建项目:转自 http://chuansong.me/n/1858477 A.请求方式为get请求 方式一:导入RequestsLibrary库,get request [ alias | ...
- C:\WINDOWS\system32\drivers\etc\hosts文件的作用
在网络上访问网站,要首先通过DNS服务器把网络域名(www.XXXX.com)解析成XXX.XXX.XXX.XXX的IP地址后,我们的计算机才能访问.要是对于每个域名请求我们都要等待域名服务器解析后返 ...