https://codeforc.es/gym/102219/problem/J

思路:连边,拓扑排序;

#include<algorithm>
#include<set>
#include<cmath>
#include<cstring>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdio>
#include<map>
#include<stack>
#include<bits/stdc++.h>
using namespace std;#define sfi(i) scanf("%d",&i)
#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-8
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)const int maxn=1e6+9;
const int mod=1e9+7;inline ll read()
{ll f=1,x=0;char ss=getchar();while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}    return f*x;
}ll power(ll x,ll n)
{ll ans=1;while(n){if(n&1) ans=ans*x;x=x*x;n>>=1;}return ans;
}queue<int>q;
vector<int>g[maxn],ans;
int d[maxn];
int main()
{//FAST_IO;mem(d,0);for(int i=0;i<5;i++){string s;cin>>s;if(s[1]=='>'){int u=s[0]-'A';int v=s[2]-'A';g[u].pb(v);d[v]++;}else{int u=s[0]-'A';int v=s[2]-'A';g[v].pb(u);d[u]++;}}for(int i=0;i<5;i++) if(d[i]==0) q.push(i);while(!q.empty()){int u=q.front();q.pop();ans.pb(u);for(int i=0;i<g[u].size();i++){int v=g[u][i];d[v]--;if(d[v]==0) q.push(v);}}if(ans.size()!=5) cout<<"impossible"<<endl;else{for(int i=4;i>=0;i--) printf("%c",ans[i]+'A');cout<<endl;}return 0;
}

J. Kitchen Plates相关推荐

  1. 2019 ICPC Malaysia National J.Kitchen Plates

    题目: https://codeforc.es/gym/102219/problem/J 题意:给ABCDE 5个盘子的5组比较大小,输出完整大小. 这个题应该蛮经典的,题解清一色都是说拓扑排序,可怜 ...

  2. 拓扑排序--Kitchen Plates

    J. Kitchen Plates 找入度为0的点,使与其连接的点都入度-1. #include<iostream> #include<cstdio> #include< ...

  3. CodeForces - Kitchen Plates(拓扑排序)

    题目链接:http://codeforces.com/gym/102219/problem/J Time limit per test 1.0 s Memory limit per test 256 ...

  4. Codeforces Kitchen Plates

    题意:有5个未知量,给五个不等式,要求你按照大小给出一个排序,如果自相矛盾的话就输出impossible. 分析:拓扑排序即可,如果成环的话,输出队列里的元素个数会小于五. 暴力便利所有排列然后根据给 ...

  5. Kitchen Plates (拓扑排序)

    原题链接 题意 给五个关系像"A<B"这种,问根据这些关系,问这些关系是否有矛盾,有矛盾的话就输出"impossible",没有的话尽量从小到大输出这些东 ...

  6. Gym - 102219J Kitchen Plates(暴力或拓扑序列)

    题意:略 题记: 做法一:拓扑排序.五个盘子相当于一个有五个点的有向图,A<B相当于A有一条边指向B.那么建图后做一遍基于BFS的拓扑排序即可. 时间复杂度O(5+5) #include< ...

  7. Kitchen Plates(暴力写法和学习拓扑排序)

    太暴力了!!!!!!! ! 关于next_permutation 的用法:头文件#include https://blog.csdn.net/sgsyacm/article/details/80139 ...

  8. [Kick Start 2020] Round A 2.Plates

    [Kick Start 2020] Round A 2.Plates 1. 题目 Problem Dr. Patel has N stacks of plates. Each stack contai ...

  9. Putting Plates 摆盘

    Putting Plates 摆盘 来源codeforses #1530B 1200 链接: [link](链接: link. time limit per test: 2 seconds 每次测试的 ...

最新文章

  1. UIBezierPath和CAShapeLayer创建不规则View(Swift 3.0)
  2. 大数据处理平台与案例
  3. 比较全的 POM.xml
  4. python raw_input为什么不能用_热门问题 | 为什么发票不能用订书器只能用胶水?...
  5. Kettle使用_10 存储过程与命名参数
  6. html5 canvas 画的简易时钟
  7. 黑客宣言_情感设计宣言
  8. java udp简单聊天程序_Java基于UDP协议实现简单的聊天室程序
  9. 常用编码软件简单使用记录 1 : 自主编码器
  10. mysql数据库双机备份_MySQL数据库本地备份和双机相互备份
  11. uva 436(floyd变形)
  12. Bootstrap validation
  13. 数据库性能指标 2005-04-06 19:36:14(转载)
  14. 7月30日PMP考试注意事项
  15. 什么是实体关系图(ERD)?
  16. 短信网关在短信信息服务中的作用(转)
  17. 鲁大师从服务器获取信息失败怎么办,云服务器 鲁大师
  18. Windows组策略应用全攻略
  19. 【教程】如何优雅地使用vs code代替keil开发51单片机/STC单片机
  20. linux下网络播放器,月亮播放器:Linux无广告看片神器

热门文章

  1. 四个翅膀的飞机Simulink与轨迹跟踪仿真
  2. Git是什么?Git常用的命令是什么?
  3. Blog - List 推荐博客链接
  4. 文章、状态中的PS是什么意思?postscript(后记)
  5. madplay命令使用(Linux音乐播放器)
  6. 黑色画布上的灿烂小花
  7. CSS描边动画,后端直呼哇塞
  8. 学成在线 第7天 讲义-课程管理实战
  9. Redis实现feed流
  10. 新浪微博 分享 功能的实现