gym 101657 D
理论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的更多相关文章
- 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 ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
随机推荐
- HTML5 学习03——内联 SVG
什么是SVG? SVG 指可伸缩矢量图形 (Scalable Vector Graphics) SVG 用于定义用于网络的基于矢量的图形 SVG 使用 XML 格式定义图形 SVG 图像在放大或改变尺 ...
- CentOS下双网卡双IP不同IP段配置
环境: eth0:10.0.7.2 gw :10.0.7.254 netmask:255.255.255.0 eth1:168.6.101.2 gw :168.6.101.254 net ...
- 控制WinForm中Tab键的跳转
一,需求 在Winform中,默认情况下,按下Tab键,光标会按照我们设定的TabIndex值从小到大进行跳转. 但如果用户要求按下Tab键跳转到特定的控件,这种要求还是很合理的,比如用户只想输入几个 ...
- Java知识回顾 (7) 继承、多态与接口、封装
一.继承 1.1 继承的特性 子类拥有父类非 private 的属性.方法. 子类可以拥有自己的属性和方法,即子类可以对父类进行扩展. 子类可以用自己的方式实现父类的方法. Java 的继承是单继承, ...
- 记录使用yum安装nginx之后的目录问题
一般来说我们安装nginx的目录都是/usr/local/nginx的,但是用yum安装的目录跟手动安装的不一样,下面是整理的使用yum安装的一些对应目录. nginx执行文件目录:/usr/sbin ...
- Pandas 使用笔记
创建空的数据框: import pandas as pd df = pd.DataFrame(columns = ["ebayno", "p_sku", &qu ...
- VirtualBox虚拟机磁盘瘦身
操作系统 : windows7_x64 VirtualBox 版本 : 4.3.28 原理: 使用0填充虚拟系统磁盘,然后删除填充文件,再使用VBoxManage进行压缩. Linux系统磁盘瘦身 一 ...
- “2014年CityEngine三维建模与设计精英培训班”——全国巡回举办
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYXJjZ2lzX2FsbA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Python 获得最近一个月的每天的日期
直接上代码: #coding:utf-8 # from common.contest import * import datetime import time begin_date = (dateti ...
- Cmake find_package 需要指定具体的so
需要使用cmake的find_package将boost库添加到项目中,通过cmake --help-module FindBoost 可以查看cmake引入Boost的帮助信息: 可以看到,Boot ...