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 ...
随机推荐
- Python三次握手和四次挥手
先要了解什么是传输层 博客中网络协议基础编有详细介绍 https://www.cnblogs.com/toby-yu/p/12357598.html TCP三次握手和四次挥手 1.三次握手 首先Cli ...
- 1.什么是 Docker
官网地址:https://www.docker.com/ Docker 最初是 dotCloud 公司创始人 Solomon Hykes 在法国期间发起的一个公司内部项目,它是基于 dotCloud ...
- numpy小结(一)
1.np.zero(10) 创建一个包含10个元素的一维数组 np.ones((10,10)) 创建一个包含10*10个元素1的二维数组 2.np.arange(10,50) ...
- while与do while
一:循环结构 循环的概念:重复得做某一件事情 举例: 打印50份试卷 沿操场跑10圈 做100道编程题 循环结构的特点: 循环条件 (50,10,100) 循环操作 (打印试卷,沿操场跑圈,做编程题) ...
- HTML span标签
span:行内标签,不会换行用于:组合文档中的行内元素.元素和文档的组合
- 少年的u
发现了我提取DNa的过程存在问题,能够跑出action 但是不能克隆出基因.老师给我解释了为什么,说是我的DNA质量不是很高.但是在接下来的时间我会解决这个问题. 和师姐一起去上面的实验室,看了定量P ...
- Paper: A Novel Time Series Forecasting Method Based on Fuzzy Visibility Graph
Problem define a fuzzy visibility graph (undirected weighted graph), then give a new similarity meas ...
- django 搭建一个投票类网站(一)
写在最前,之前零零散散的看过django,但是由于比较杂,学的云里雾里的,所以就停了一段落,但是我最近找到了一个django的书,是李建编著的django入门与实践,于是,打算照着书上的步骤来写好一个 ...
- java 发送简单邮件(不带附件)
引入依赖 邮件实体类 可用邮件服务器地址(网易为例) 邮件工具类 import com.me.beans.Mail; import lombok.extern.slf4j.Slf4j; import ...
- util之Stack
定义 Stack<Integer>s = new Stack<>(); boolean isEmpty() 测试堆栈是否为空. Object peek( ) 查看堆栈顶部的对 ...