Codeforces Round #610 (Div. 2)E(模拟,DFS)
先找到一条多边形的边,然后循环一圈输出多边形上的点。把每个三角形看作一个结点,以两个三角形之间公用边为边建立一张图,DFS输出叶子结点,则得到先切后切的顺序。
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
vector<int>v[];
bool vis[];
void dfs(int x){
vis[x]=;
for(auto it:v[x])
if(!vis[it])
dfs(it);
cout<<x<<" ";//把三角形看作是一个结点,输出叶子结点即为外圈的三角形,它们是可以被先切的,内圈的三角形后输出为后切的
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=;i<=n;++i){
vis[i]=;
v[i].clear();
}
int adj[n+]={};//每次和三角形中另外两个点异或,最终得到的是它相邻的两个点的异或和
map<pair<int,int>,vector<int> >mp;
for(int i=;i<=n-;++i){
int a,b,c;
cin>>a>>b>>c;
adj[a]^=b;
adj[a]^=c;
adj[b]^=a;
adj[b]^=c;
adj[c]^=a;
adj[c]^=b;
if(a>b)
swap(a,b);
if(b>c)
swap(b,c);
if(a>b)
swap(a,b);//为了使abc有序,否则可能因为输入顺序的原因把同对的两个点顺序搞反
mp[{a,b}].push_back(i);
mp[{b,c}].push_back(i);
mp[{a,c}].push_back(i);
}
int x=,y=;
for(auto it:mp){
if(it.second.size()==){//只属于一个三角形的边一定是原本多边形的一条边
x=it.first.first;//x和y一定相邻
y=it.first.second;
break;
}
}
cout<<x<<" "<<y<<" ";
for(int i=;i<=n-;++i){//已知x是y的一个相邻点,又知道y的两个相邻点的异或和adj[y],可以得到另一个相邻点x^adj[y]
adj[y]^=x;
cout<<adj[y]<<" ";
x=y;
y=adj[y];
}
cout<<"\n";
//x=0,y=0;
for(auto it:mp){
if(it.second.size()==){//某条边被两个三角形所共用,就将这两个三角形之间连一条边
x=it.second[];
y=it.second[];
v[x].push_back(y);
v[y].push_back(x);
}
}
dfs();
cout<<"\n";
}
return ;
}
Codeforces Round #610 (Div. 2)E(模拟,DFS)的更多相关文章
- Codeforces Round #610 (Div. 2) A-E简要题解
contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...
- Codeforces Round #222 (Div. 1) A. Maze dfs
A. Maze 题目连接: http://codeforces.com/contest/377/problem/A Description Pavel loves grid mazes. A grid ...
- Codeforces Round #245 (Div. 2) C. Xor-tree DFS
C. Xor-tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem/C ...
- Codeforces Round #459 (Div. 2) D. MADMAX DFS+博弈
D. MADMAX time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #398 (Div. 2) C. Garland —— DFS
题目链接:http://codeforces.com/contest/767/problem/C 题解:类似于提着一串葡萄,用剪刀剪两条藤,葡萄分成了三串.问怎样剪才能使三串葡萄的质量相等. 首先要做 ...
- Codeforces Round #249 (Div. 2) (模拟)
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #321 (Div. 2)C(tree dfs)
题意:给出一棵树,共有n个节点,其中根节点是Kefa的家,叶子是restaurant,a[i]....a[n]表示i节点是否有猫,问:Kefa要去restaurant并且不能连续经过m个有猫的节点有多 ...
- Codeforces Round #366 (Div. 2) C 模拟queue
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #267 (Div. 2)D(DFS+单词hash+简单DP)
D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- centos8 常用软件
防火墙 GUI版 https://blog.csdn.net/qq_36492368/article/details/80432259 dnf install -y firewall-config d ...
- Spring-session+Redis解决Session共享
1. 保证Redis启动 2. 导入依赖 SpringBoot+Spring-Session+Redis <!--spring boot 与re ...
- Ubutu安装oracle jdk1.8
环境: Ubuntu 18.04 LTS x64位 系统用户 hou 工具: jdk-8u171-linux-x64.tar.gz 实验的心 步骤: 第一步: 查看有没有装jdk,按住 ctr+a ...
- 三行代码实现垂直居中和cube
三行代码实现上下居中 position: relative;top: 50%;transform: translateY(-50%); 效果如下: 代码: <!DOCTYPE html> ...
- SSM+layui实现增删改查
前端使用layui框架,后端使用Spring+SpringMVC+Mybatis的集合框架,数据库使用MySQL,完成对一张用户表的增删改查操作. 前后端分离开发,即前端的HTML页面通过ajax技术 ...
- 前端Css学习
CSS 称为层叠样式表 css样式引入方式 第一种 head标签中引入 <style> /* 选择器{css属性名称:属性值;css属性名称:属性值;} */ div{ /* css注释 ...
- MySQL语法规范
不区分大小写(规范:关键字大写,表名列名小写) 每条命令用 :结尾 每条命令可以根据需要进行 缩进或换行. 最标准的模板: 关键字 对象 关键字 对象 注释:用于解释说明,编译器会自动忽略 单行注释: ...
- 模块一:shell 脚本基础
一.shell脚本介绍 (一)脚本案例及介绍: #!/bin/bash LOG_DIR=/var/log ROOT_UID=0 if ["$UID -ne "$ROOT_UID&q ...
- 【Unity|C#】基础篇(3)——类(class)/ 接口(interface)
[学习资料] <C#图解教程>(第4~7章):https://www.cnblogs.com/moonache/p/7687551.html 电子书下载:https://pan.baidu ...
- AcWing 1019. 庆功会 多重背包求max
//多重背包 max #include <iostream> using namespace std; ; int n, m; int f[N]; int main() { cin > ...