zoukankan      html  css  js  c++  java
  • codeforces 472C.Make It Nondeterministic 解题报告

    题目链接:http://codeforces.com/problemset/problem/472/C

    题目意思:给出 n 个 people(从第1行往下数,编号依次为1,2,...,n),每 个 people 由 first name 和 last name 组成,每个people用他自己的first name 或者是 last name 是不确定的。现在给出p1, p2, ..., pn 这个排列,问按照这个顺序排列能否满足字典序逐渐增加。

        思路不难得出。对于第 pi+1 这个人,只要选择比前一个人,即 pi的字典序大的name即可,由于要保证后面的pj (i < j)尽可能满足条件,我们只需要选择较小的那个name,但也要比前一个人的name要大。这个操作可以先 min(f[p], s[p]),如果比前一个人的name要小,我们才选择max(f[p], s[p])

        

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 using namespace std;
     6 
     7 const int maxn = 1e5 + 5;
     8 
     9 string f[maxn], s[maxn];
    10 string select[maxn];
    11 
    12 int main()
    13 {
    14     #ifndef ONLINE_JUDGE
    15         freopen("in.txt", "r", stdin);
    16     #endif
    17 
    18     int n, p;
    19     while (scanf("%d", &n) != EOF)
    20     {
    21         for (int i = 1; i <= n; i++)
    22            cin >> f[i] >> s[i];
    23         scanf("%d", &p);
    24 
    25         select[1] = min(f[p], s[p]);
    26         bool flag = true;
    27         for (int i = 2; i <= n; i++)
    28         {
    29             scanf("%d", &p);
    30             select[i] = min(f[p], s[p]);
    31             if (select[i] < select[i-1] && flag)
    32                 select[i] = max(f[p], s[p]);
    33             if (select[i] < select[i-1] && flag)
    34                 flag = false;
    35         }
    36         printf("%s
    ", flag ? "YES" : "NO");
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    noip2014提高组day2二题题解-rLq
    uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
    NOIP2008提高组(前三题) -SilverN
    uva 11134 fabled rooks (贪心)——yhx
    NOIP2008提高组火柴棒等式(模拟)——yhx
    NOIP2008 普及组T2 排座椅 解题报告-S.B.S
    判断https
    redis 在centos下的安装部署
    phpstorm常用快捷键
    yii 打印sql
  • 原文地址:https://www.cnblogs.com/windysai/p/4001074.html
Copyright © 2011-2022 走看看