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 ...
随机推荐
- 如何通过给MM修电脑培养感情
文章来自网络 在修之前,向MM反复声明,这电脑故障是有硬件和软件之分的,如果是硬件故障,例如显卡风扇不转了,显示器连线老化,显示器分辨率超出显示器指标,等等都会导致黑屏啊,这个我不回家用专门的工具是修 ...
- Wannafly Camp 2020 Day 6N. 合并!
#include <bits/stdc++.h> using namespace std; int n,a[2005]; int main() { long long ans=0; cin ...
- (转) 统计在从1到n的正整数中1出现的次数
1. 题目描述 输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数.例如输入12,从1到12这些整数中包含1的数字有1,10,11和12,1一共出现了5次. 2. 题目来源 第一次看到是在 ...
- 番外:Oracle 中关于 Control File 的备份说明
番外系列说明:该系列所有文章都将作为独立篇章进行知识点讲解,是对其他系列博文进行的补充说明,来自于博客园AskScuti. 主题:关于 Control File 控制文件备份的说明 内容预览:本篇涉及 ...
- Hog实例
1.计算Hog的特征得维度: #include <iostream> #include <opencv2/core/core.hpp> #include <opencv2 ...
- ntpq -p命令详解
ntpq用来监视ntpd操作,ntpq -p查询网络中的NTP服务器,同时显示客户端和每个服务器的关系 [root@localhost ~]# ntpq -p remote ...
- 动态规划(Dynamic Programming, DP)---- 最大连续子序列和
动态规划(Dynamic Programming, DP)是一种用来解决一类最优化问题的算法思想,简单来使,动态规划是将一个复杂的问题分解成若干个子问题,或者说若干个阶段,下一个阶段通过上一个阶段的结 ...
- [HNOI2017] 礼物 - 多项式乘法FFT
题意:给定两个 \(n\) 元环,环上每个点有权值,分别为 \(x_i, y_i\).定义两个环的差值为 \[\sum_{i=0}^{n-1}{(x_i-y_i)^2}\] 可以旋转其中的一个环,或者 ...
- oracle 处理锁表,创建新的数据库实例
select saddr,sid,serial#,paddr,username,status from v$session where username is not null and usernam ...
- Paper: ModelarDB
Problem: how to store and querry massive amounts of high quality sensor data ingested in real-time f ...