传送门

文章目录

  • 题意:
  • 思路:

题意:


n≤200n\le200n≤200

思路:

首先关注到rrr从[2,n][2,n][2,n]都出现一次,所以很明显最后一个位置只出现一次,但是这样倒着来不是很好做考虑正着来。
我们可以枚举111位置填什么,让后再将所有qqq数组中的当前位置要填的数去掉,之后如果数组中元素只有一个的时候就说明他是下一位,依次这么加入即可,如果都能加入,再判断一下整个序列是否合法。
每次添加的都是rrr位置的数,所以正确性是可以保证的。
由于n≤200n\le200n≤200,所以随便乱搞搞就过啦。

// Problem: F. Restore the Permutation by Sorted Segments
// Contest: Codeforces - Codeforces Round #636 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1343/F
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=210,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n;
set<int>s[N],ps[N];
int ans[N],pos[N];bool check() {for(int i=1;i<=n;i++) {for(int j=1;j<=n;j++) if(ans[j]==i) { pos[i]=j; break; }}vector<int>v;for(int i=1;i<=n-1;i++) {v.clear();for(auto x:s[i]) v.pb(pos[x]);sort(v.begin(),v.end());for(int i=1;i<v.size();i++) if(v[i]-v[i-1]!=1) return false;}return true;
}bool check(int ed) {int pos=n;for(int i=1;i<=n-1;i++) ps[i]=s[i];ans[pos--]=ed;for(int i=1;i<=n-1;i++) if(ps[i].count(ed)!=0) ps[i].erase(ed); while(pos>=1) {int id=-1;for(int i=1;i<=n-1;i++) if(ps[i].size()==1) {if(id==-1) id=i;else return false;}//cout<<id<<' '<<ps[id].size()<<endl;if(id==-1) return false;int val=*ps[id].begin();ans[pos--]=*ps[id].begin();for(int i=1;i<=n-1;i++) if(ps[i].count(val)!=0) ps[i].erase(val);}if(!check()) return false;for(int i=n;i>=1;i--) printf("%d ",ans[i]);puts("");return true;
}int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);int _; scanf("%d",&_);while(_--) {scanf("%d",&n);for(int i=1;i<=n-1;i++) {int k; scanf("%d",&k);while(k--) {int x; scanf("%d",&x);s[i].insert(x);}}for(int i=1;i<=n;i++) if(check(i)) break;for(int i=1;i<=n;i++) s[i].clear();}return 0;
}
/**/

Codeforces Round #636 (Div. 3) F. Restore the Permutation by Sorted Segments 思维 + 暴力相关推荐

  1. CodeForces - 1343F Restore the Permutation by Sorted Segments(思维)

    题目链接:点击查看 题目大意:现在有一个长度为 n 的排列 p ,但排列 p 暂时对我们保密,每个样例将会给出 n - 1 个排好序后的子段,换句话说,对于 r ∈ [ 2 , n ] ,存在一个 l ...

  2. Codeforces Round #636 (Div. 3)

    Codeforces Round #636 (Div. 3)(2020.4.21) A.Candies 因为题目保证了有解,所以我们枚举一下 k k k就行了. #include <bits/s ...

  3. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

  4. Codeforces Round #636 (Div. 3) E. Weights Distributing 思维 + bfs

    传送门 文章目录 题意: 思路: 题意: n≤2e5,m≤2e5n\le2e5,m\le2e5n≤2e5,m≤2e5 思路: 怎么感觉每场div3div3div3都有一个巧妙的图论题. 首先如果只有两 ...

  5. Codeforces Round #636 (Div. 3) D. Constant Palindrome Sum 思维 + 差分

    传送门 文章目录 题意: 思路: 题意: 思路: 首先有一个显然的性质就是每组操作最多不会超过两次. 很容易想到一个很暴力的思路,就是枚举x∈[1,2∗k]x \in [1,2*k]x∈[1,2∗k] ...

  6. Codeforces Round #644 (Div. 3) F.Spy-string

    Codeforces Round #644 (Div. 3) F.Spy-string 题目链接 You are given n strings a1,a2,-,an: all of them hav ...

  7. Codeforces Round #636 (Div. 3)部分题解

    链接:Codeforces Round #636 (Div. 3) A - Candies 题意:求出一个x满足x+2∗x+4∗x+⋯+2k−1∗x=n且k>1 思路:提出x得x∗(1+2+4+ ...

  8. Codeforces Round #849 (Div. 4) F. Range Update Point Query

    Codeforces Round #849 (Div. 4) F. Range Update Point Query 题目大意: 给一串数字,有两个操作: 操作1:将 l − r l-r l−r 的数 ...

  9. Codeforces Round #636 (Div. 3) D.Constant Palindrome Sum

    Codeforces Round #636 (Div. 3) D.Constant Palindrome Sum 题目链接 You are given an array a consisting of ...

最新文章

  1. day 03 selenium与Beautifulsoup4的原理与使用
  2. 2020 前端开源领域技术展望
  3. 启动之OS_CPU_C
  4. 为啥国人偏爱 Mybatis,而老外喜欢 Hibernate/JPA 呢?
  5. layui列表筛选列_Shopify搜索产品并筛选产品列表功能介绍
  6. 轻触开源(一)-Java泛型Type类型的应用和实践
  7. 递归 求一个数的阶乘
  8. 95-190-442-源码-window-Trigger-ProcessingTimeTrigger
  9. 思科模拟器叫什么_宇宙无敌上帝视角无所不能之星球生成模拟器。
  10. 有盘和无盘服务器,网吧系统的终极解决之道:无盘系统+有盘(转)
  11. 原神角色展示(HTML+CSS)
  12. 奖学金评审系统java_奖学金评定系统 - WEB源码|源代码 - 源码中国
  13. 百度小米滴滴躬身入局,新能源造车如此多娇,引无数大厂竟折腰?
  14. Google基本查询语法
  15. 《数学建模简明教程--基于python》学习笔记-第四章-微分方程-课后习题解答
  16. 20201125今日学习
  17. qq拼音纯净版下载QQPinyin_Setup_1.3.1265.400
  18. 免费可练习接口测试的开放接口
  19. 正在配置计算机好久了,准备配置windows请勿关闭计算机要多久_准备配置请勿关机很久...
  20. 免费下载各种json包的网址

热门文章

  1. 计算机专业技能考核方案,计算机专业技能课教学目标考核方案教程.doc
  2. 清华姚班毕业生不配自信?张昆玮在豆瓣征女友,却被网友群嘲......
  3. 它是世界上最轻的固体!1000℃下不会熔化,上过火星,还能进你家......
  4. 史上最会抄的数学家!把阿拉伯数字直接抄进自己的书里,连中国几千年前的名著都惨遭毒手.........
  5. 清华教授转述:读博6年未毕业被认定为自控力不够,或将影响个人贷款额度
  6. 你爱我吗? | 今日最佳
  7. 中科大量子计算机科学家,中国科学院量子信息重点实验室
  8. java中可以用浮点作为循环变量吗_Java千问:Java循环语句的几个冷门知识点你都知道吗?...
  9. python数组的切片操作_对Python 数组的切片操作
  10. linux cache fs,新闻|Linux 上将出现一个新的文件系统:bcachefs