zoukankan      html  css  js  c++  java
  • Codeforces Gym 100431D Bubble Sort 水题乱搞

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-andrew-stankevich-contest-37-asc-37-en.pdf

    题意

    神奇的电路可以通过比较器来实现冒泡。

    题解

    倒着往回考虑,搞搞就好。

    代码

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define MAX_N 222
    using namespace std;
    
    int n;
    
    int a[MAX_N][MAX_N];
    int x[MAX_N];
    
    int tim[MAX_N][MAX_N];
    
    int main() {
        freopen("bubble.in", "r", stdin);
        freopen("bubble.out", "w", stdout);
        tim[0][0] = 0;
        scanf("%d", &n);
        for (int i = 0; i < n; i++)x[i] = i;
        for (int i = 0; i < n - 1; i++)
            for (int j = 0; j <= i; j++)
                scanf("%d", &a[i][j]);
        for (int i = 0; i < n - 2; i++)
            for (int j = 0; j <= i; j++)
                tim[i + 1][j] = tim[i][j] + 1, tim[i + 1][j + 1] = tim[i][j] - 1;
        for (int now = tim[n - 2][n - 2]; now <= tim[n - 2][0]; now++) {
            for (int i = 0; i < n - 1; i++)
                for (int j = 0; j <= i; j++)
                    if (tim[i][j] == now) {
                        int u = i, v = i + 1;
                        if (x[u] > x[v]) {
                            printf("NO
    ");
                            return 0;
                        }
                        if (a[i][j])swap(x[u], x[v]);
                    }
        }
        printf("YES
    ");
        for (int i = 0; i < n; i++)
            printf("%d ", x[i] + 1);
        return 0;
    }
  • 相关阅读:
    SVN 使用学习记录
    jQuery 获取 URL信息
    JS扩展方法
    .Net 加密 哈希
    SQL Serverf 索引
    SQL Server索引
    SQL Server索引
    insert into select 多个表
    Mysql数据库自带四个数据库的解析
    转: MySQL5.7 ERROR 1142 (42000)问题
  • 原文地址:https://www.cnblogs.com/HarryGuo2012/p/4737591.html
Copyright © 2011-2022 走看看