理论1A。  //没删debug的文件读入。。

傻逼题。

先求出来每条边两侧的三角形,然后枚举边,根据叉积判断三角形位置,建图,拓扑排序。

 #include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
typedef double db;
const int N = 1e6+;
const db eps = 1e-;
const db pi = acos(-);
int sign(db k){
if (k>eps) return ; else if (k<-eps) return -; return ;
}
int cmp(db k1,db k2){return sign(k1-k2);}
struct point{
db x,y;
point operator+(const point &k1)const { return point{k1.x+x,k1.y+y};}
point operator-(const point &k1)const { return point{x-k1.x,y-k1.y};}
point operator*(const db k1)const { return point{x*k1,y*k1};}
point operator / (db k1) const{return (point){x/k1,y/k1};}
db abs(){return sqrt(x*x+y*y);}
bool operator<(const point k1)const {
int a = cmp(x,k1.x);
if (a==-) return ; else if (a==) return ; else return cmp(y,k1.y)==-;
}
bool operator== (const point k1)const {
return x==k1.x&&y==k1.y;
}
};
db cross(point k1,point k2){ return k1.x*k2.y-k1.y*k2.x;}
db dot(point k1,point k2){ return k1.x*k2.x+k1.y*k2.y;}
struct line{
point p[];//x小的是p[0]
line(point k1,point k2){
if(k1<k2)
p[]=k1,p[]=k2;
else
p[]=k2,p[]=k1;
}
point &operator[](int k){ return p[k];}
bool operator <(const line &k1)const {
if(p[]==k1.p[])
return p[]<k1.p[];
return p[]<k1.p[];
}
};
struct Tri{
point p[],o;
point &operator[](int k){ return p[k];}
}tri[N];
map<line,int> mp;
vector<line> L;
int cnt = ;
vector<int> g[N*],f[N];
int deg[N];
int t,n;
int main(){
//freopen("awsl.in","r",stdin);
scanf("%d",&t);
while (t--){
scanf("%d",&n);
for(int i=;i<n;i++){
tri[i].o.x=,tri[i].o.y=;
for(int j=;j<;j++){
scanf("%lf%lf",&tri[i][j].x,&tri[i][j].y);
tri[i].o.x+=tri[i][j].x;
tri[i].o.y+=tri[i][j].y;
}
tri[i].o.x/=,tri[i].o.y/=;
for(int j=;j<;j++){
line tmp = line(tri[i][j],tri[i][(j+)%]);
if(mp.count(tmp)){
g[mp[tmp]].push_back(i);
} else{
mp[tmp]=cnt;
L.push_back(tmp);
g[cnt].push_back(i);
cnt++;
}
}
}
for(int i=;i<cnt;i++){
if(g[i].size()<)continue;
int s1 = g[i][],s2 = g[i][];
line tmp = L[i];
db t = cross(tmp[]-tmp[],tri[s1].o-tmp[]);
if(sign(t)>){//s1在上面
f[s1].push_back(s2);
deg[s2]++;
} else{
f[s2].push_back(s1);
deg[s1]++;
}
}
queue<int> q;
for(int i=;i<n;i++){
if(deg[i]==)
q.push(i);
}
vector<int> ans;
while (!q.empty()){
int t = q.front();
q.pop();
ans.push_back(t+);
for(int i=;i<f[t].size();i++){
deg[f[t][i]]--;
if(deg[f[t][i]]==)
q.push(f[t][i]);
}
}
reverse(ans.begin(),ans.end());
for(auto tmp:ans){
printf("%d ",tmp);
}
printf("\n");
for(int i=;i<n;i++){
deg[i]=;
f[i].clear();
}
for(int i=;i<cnt;i++)
g[i].clear();
L.clear();mp.clear();
cnt=;
}
}

gym 101657 D的更多相关文章

  1. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  2. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  5. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  6. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  7. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  8. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

  9. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

随机推荐

  1. springboot获取properties文件的配置内容(转载)

    1.使用@Value注解读取读取properties配置文件时,默认读取的是application.properties. application.properties: demo.name=Name ...

  2. ConditionalOnProperty

    配置Spring Boot通过@ConditionalOnProperty来控制Configuration是否生效 1.matchIfMissing属性:从application.properties ...

  3. AXI总线介绍

    原帖地址:https://wenku.baidu.com/view/7c424c17e3bd960590c69ec3d5bbfd0a7956d5b9.html   1.AXI简介 AXI(Advanc ...

  4. List集合序列排序的两种方法

    首先讲一下Comparable接口和Comparator接口,以及他们之间的差异.有助于Collections.sort()方法的使用.请参考 1.Comparable自然规则排序//在自定义类Stu ...

  5. linux apache2部署php

    apache2 doc http://blog.csdn.net/actor1999/article/details/44802519 #apache sudo apt-get install apa ...

  6. yarn upgrade

    更新一个依赖 yarn upgrade 用于更新包到基于规范范围的最新版本 yarn upgrade --latest # 忽略版本规则,升级到最新版本,并且更新 package.json .

  7. iOS - 统计代码行数

    终端 -> 进入文件夹 查看每一行的行数 find . -name "*.m" -or -name "*.h" -or -name "*.xib ...

  8. Docker Mongo数据库主主同步配置方法

    一.背景 不多说,请看第一篇<Docker Mongo数据库主从同步配置方法> 二.具体操作方法 1.创建目录,如创建~/test/mongo_sr1和-/test/mongo_sr2两个 ...

  9. C#7.2——编写安全高效的C#代码 c# 中模拟一个模式匹配及匹配值抽取 走进 LINQ 的世界 移除Excel工作表密码保护小工具含C#源代码 腾讯QQ会员中心g_tk32算法【C#版】

    C#7.2——编写安全高效的C#代码 2018-11-07 18:59 by 沉睡的木木夕, 123 阅读, 0 评论, 收藏, 编辑 原文地址:https://docs.microsoft.com/ ...

  10. cx_Oracle读写clob

    cx_Oracle读写clob 读 读到相应字段后,使用read()方法即可:例如读取到clob对象a,想要查看其内容,使用下列代码即可: a.read() 写 参考下列代码: id='123' cl ...