zoukankan      html  css  js  c++  java
  • 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门

     1 /*
     2     题意:删除若干行,使得n行字符串成递增排序
     3     暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小
     4 */
     5 /************************************************
     6 Author        :Running_Time
     7 Created Time  :2015-8-3 10:49:53
     8 File Name     :C.cpp
     9  *************************************************/
    10 
    11 #include <cstdio>
    12 #include <algorithm>
    13 #include <iostream>
    14 #include <sstream>
    15 #include <cstring>
    16 #include <cmath>
    17 #include <string>
    18 #include <vector>
    19 #include <queue>
    20 #include <deque>
    21 #include <stack>
    22 #include <list>
    23 #include <map>
    24 #include <set>
    25 #include <bitset>
    26 #include <cstdlib>
    27 #include <ctime>
    28 using namespace std;
    29 
    30 #define lson l, mid, rt << 1
    31 #define rson mid + 1, r, rt << 1 | 1
    32 typedef long long ll;
    33 const int MAXN = 1e2 + 10;
    34 const int INF = 0x3f3f3f3f;
    35 const int MOD = 1e9 + 7;
    36 char s[MAXN][MAXN];
    37 int n, m;
    38 bool ok[MAXN][MAXN];
    39 
    40 int main(void)    {       //Codeforces Round #283 (Div. 2) C. Removing Columns
    41     while (scanf ("%d%d", &n, &m) == 2) {
    42         for (int i=1; i<=n; ++i)    {
    43             scanf ("%s", s[i] + 1);
    44         }
    45         int ans = 0;    memset (ok, false, sizeof (ok));
    46         bool flag = true;
    47         for (int j=1; j<=m; ++j)    {
    48             flag = true;
    49             for (int i=2; i<=n; ++i)    {
    50                 if (ok[i][i-1]) continue;
    51                 if (s[i][j] < s[i-1][j])    {
    52                     ans++;  flag = false;   break;
    53                 }
    54             }
    55             if (flag)   {
    56                 for (int k=2; k<=n; ++k)    {
    57                     if (s[k][j] > s[k-1][j])    ok[k][k-1] = true;
    58                 }
    59             }
    60         }
    61         printf ("%d
    ", ans);
    62     }
    63 
    64     return 0;
    65 }
    编译人生,运行世界!
  • 相关阅读:
    python文件句柄只能用一次的误解
    字符编码后续...记事本"联通"小插曲
    字符编码
    python problem
    vue-cli3 vue-config.js配置 概况
    ssh-keygen 不是内部或外部命令
    好的文章的链接收藏
    urlArgs 请require 缓存
    js 类型判断
    阻止冒泡和取消默认事件(默认行为)
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4699107.html
Copyright © 2011-2022 走看看