• 题意:给你5个\(A,B,C,D,E\)大小关系式,升序输出它们,如果所给的大小矛盾,输出\(impossible\).

  • 题意:当时第一眼想到的就是连边然后排序,很明显是拓扑排序(然而我不会qwq,之后再补),但貌似可以直接暴力来写,用二维数组来记录两个数之间的大小关系,如果一维\(>\)二维就记录true,然后我们要对题目所给的关系进行合并,将所有大小关系弄清楚,三个for就可以搞定了,之后判断一下是否有矛盾存在,最后再统计一下大小然后再按顺序输出即可(这题的输出其实没怎么看懂,之前写的桶排输出不知道为什么不给过qaq).

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<long,long> PLL; string s;
    int v[100][100];
    int cnt[N];
    map<int,int> mp;
    vector<int> rest;
    int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    for(int i=1;i<=5;++i){
    cin>>s;
    //初始化记录
    for(int j=0;j<s.size();++j){
    if(s[1]=='>') v[s[0]-'A'][s[2]-'A']=1;
    else v[s[2]-'A'][s[0]-'A']=1;
    }
    }
    //合并
    for(int k=0;k<5;++k){
    for(int i=0;i<5;++i){
    for(int j=0;j<5;++j){
    if(v[i][k] && v[k][j]) v[i][j]=1;
    }
    }
    } for(int i=0;i<5;++i){
    for(int j=0;j<5;++j){
    if(v[i][j] && v[j][i]){
    puts("impossible");
    return 0;
    }
    }
    }
    //统计大小
    for(int i=0;i<5;++i){
    for(int j=0;j<5;++j){
    if(v[i][j]) cnt[i]++;
    }
    }
    for(int len=0;len<5;++len){
    for(int num=0;num<5;++num){
    if(cnt[num]==len) printf("%c",num+'A');
    }
    } return 0;
    }
  • :拓扑排序的裸题,直接写就行了

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<ll,ll> PLL; string s;
    vector<char> v;
    vector<char> out[N];
    int in[N]; int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    for(int i=1;i<=5;++i){
    cin>>s;
    if(s[1]=='>'){
    in[s[0]]++;
    out[s[2]].pb(s[0]);
    }
    else{
    in[s[2]]++;
    out[s[0]].pb(s[2]);
    }
    }
    queue<char> q;
    for(char i='A';i<='E';++i){
    if(in[i]==0) q.push(i);
    }
    while(!q.empty()){
    char tmp=q.front();
    q.pop();
    v.pb(tmp);
    for(auto w:out[tmp]){
    if(w!=-1){
    in[w]--;
    if(in[w]==0) q.push(w);
    }
    w=-1;
    }
    }
    if(v.size()!=5) puts("impossible");
    else{
    for(auto w:v) printf("%c",w);
    }
    return 0;
    }

Codeforces Gym-102219 2019 ICPC Malaysia National J. Kitchen Plates (暴力,拓扑排序)的更多相关文章

  1. Codeforces Gym-102219 2019 ICPC Malaysia National E. Optimal Slots(01背包+输出路径)

    题意:给你一个体积为\(T\)的背包,有\(n\)个物品,每个物品的价值和体积都是是\(a_{i}\),求放哪几个物品使得总价值最大,输出它们,并且输出价值的最大值. 题解:其实就是一个01背包输出路 ...

  2. codeforces Gym 100500H H. ICPC Quest 水题

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  3. codeforces Gym 100500C C. ICPC Giveaways 排序

    Problem C. ICPC GiveawaysTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1005 ...

  4. Codeforces Gym 101190 NEERC 16 G. Game on Graph(博弈+拓扑)

    Gennady and Georgiy are playing interesting game on a directed graph. The graph has n vertices and m ...

  5. Codeforces Round #532 (Div. 2) E. Andrew and Taxi(二分+拓扑排序)

    题目链接:https://codeforces.com/contest/1100/problem/E 题意:给出 n 个点 m 条边的有向图,要翻转一些边,使得有向图中不存在环,问翻转的边中最大权值最 ...

  6. ACM/ICPC 之 数据结构-邻接表+DP+队列+拓扑排序(TSH OJ-旅行商TSP)

    做这道题感觉异常激动,因为在下第一次接触拓扑排序啊= =,而且看了看解释,猛然发现此题可以用DP优化,然后一次A掉所有样例,整个人激动坏了,哇咔咔咔咔咔咔咔~ 咔咔~哎呀,笑岔了- -|| 旅行商(T ...

  7. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  8. Codeforces GYM 100876 J - Buying roads 题解

    Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...

  9. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

随机推荐

  1. 基于 MPI 的快速排序算法的实现

    完整代码: #include <iostream> #include <cstdlib> #include <ctime> #include <algorit ...

  2. SQL Server解惑——查询条件IN中能否使用变量

    在SQL Server的查询条件中,能否在IN里面使用变量呢? 如果可以的话,有没有需要注意的地方或一些限制呢?在回答这个问题前,我们先来看看这个例子: IF EXISTS (SELECT 1 FRO ...

  3. Spring框架之事务源码完全解析

    Spring框架之事务源码完全解析   事务的定义及特性: 事务是并发控制的单元,是用户定义的一个操作序列.这些操作要么都做,要么都不做,是一个不可分割的工作单位.通过事务将逻辑相关的一组操作绑定在一 ...

  4. 利用iptables防火墙保护web服务器

    实例:利用iptables防火墙保护web服务器 防火墙--->路由器-->交换机-->pc机 配置之前,清空下已有的规则,放在规则冲突不生效 工作中,先放行端口写完规则,再DROP ...

  5. SAP中数据库表长度的界定

    SAP中,如何查看表和关键字的长度?通过SE11菜单栏Extras->table width 可以看到.然而SAP在系统也会将表分类,特别是在可扩展的表维护视图中,分为如下几类      ult ...

  6. (数据科学学习手札104)Python+Dash快速web应用开发——回调交互篇(上)

    本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 这是我的系列教程Python+Dash快速web ...

  7. Python设计模式面向对象编程

    前言   本篇文章是基于极客时间王争的<设计模式之美>做的总结和自己的理解.  说到面向对象编程,作为一个合格的Pythoner,可以说信手拈来.毕竟在Python里"万物都是对 ...

  8. 不支持的字符集 (在类路径中添加 orai18n.jar): ZHS16GBK

    不支持的字符集 (在类路径中添加 orai18n.jar): ZHS16GBK 报错图示: 报错内容: Exception in thread "main" java.sql.SQ ...

  9. (Oracle)看懂Oracle执行计划(转载)

    最近一直在跟Oracle打交道,从最初的一脸懵逼到现在的略有所知,也来总结一下自己最近所学,不定时更新ing- 一:什么是Oracle执行计划? 执行计划是一条查询语句在Oracle中的执行过程或访问 ...

  10. CF1416D 做题心得

    CF1416D 做题心得 上次在某trick中提到了这个题,一开始觉得太毒瘤没有写,现在把它补上了. 感觉实现这个东西,比单纯收获一个trick,收获的东西多太多了. 主要思路 它的主要trick是& ...