理论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. 使用CSS里的user-select属性控制用户在页面上选中的内容

    CSS里的user-select属性用来禁止用户用鼠标在页面上选中文字.图片等,也就是,让页面内容不可选.也可以只允许用户选中文字,或者全部都放开,用户可以同时选中文字.还包括文本里的图片.视频等其它 ...

  2. 20190131 经验总结:如何从rst文件编译出自己的sqlalchemy的文档

    20190131 经验总结:如何编译sqlalchemy的文档 起因 www.sqlalchemy.org官网上不去了,不管是直接上,还是用代理都不行. sqlalchemy属于常用工具,看不到官方的 ...

  3. Apache shiro如何实现一个账户同一时刻只有一个人登录

    继承AuthorizingRealm类,重写方法doGetAuthenticationInfo /** * 认证(登录时调用) */ @Override protected Authenticatio ...

  4. 主流CTR预估模型的演化及对比

    https://zhuanlan.zhihu.com/p/35465875 学习和预测用户的反馈对于个性化推荐.信息检索和在线广告等领域都有着极其重要的作用.在这些领域,用户的反馈行为包括点击.收藏. ...

  5. javascript日期时间操作库推荐

    https://github.com/datejs/Datejs 链接: https://pan.baidu.com/s/1QTGhxslarNyW_0kB6gyJYA 提取码: ibab 如果这篇文 ...

  6. C# 程序打包成安装项目

    Xaml设置图标https://blog.csdn.net/u014234260/article/details/73648649 winform程序控制面板中卸载显示图标https://blog.c ...

  7. EAS开发之挂菜单

        一:以管理员账号登录   二:挂菜单     点击菜单栏"系统"——客户化菜单编辑——选中上级目录——点击 新建——命名.键入唯一编码,把ui.java类的全路径,拷贝到 ...

  8. 使用 GeoIP2 获取 IP 的地理位置

    1. 准备工作 数据库 : 解析 IP 地理位置的的数据库来自 GeoLite2 开源数据库:https://dev.maxmind.com/geoip/geoip2/geolite2/ . C 语言 ...

  9. RabbitMQ五种消息队列学习(三)–Work模式

    由于在实际应用中,简单队列模型无法解决很多实际问题,而且生产者和消费者是一对一的关系.模型较为单一.故引入Work模式. 结构图 一个生产者.多个消费者. 一个消息只能被一个消费者获取. 测试实现:  ...

  10. 深入理解linux系统下proc文件系统内容

    深入理解linux系统下proc文件系统内容 内容摘要:Linux系统上的/proc目录是一种文件系统,即proc文件系统. Linux系统上的/proc目录是一种文件系统,即proc文件系统.与其它 ...