zoukankan      html  css  js  c++  java
  • POJ 3617 Best Cow Line

    简单贪心。注意输出格式,每到80个字符就换一行。

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<stack>
    #include<algorithm>
    using namespace std;
    
    const int maxn = 2000 + 10;
    int a[maxn], ans[maxn];
    int n;
    
    void read()
    {
        for (int i = 1; i <= n; i++)
        {
            char s[5]; scanf("%s", s);
            a[i] = s[0] - 'A' + 1;
        }
    }
    
    void work()
    {
        int first = 1, last = n;
        for (int i = 1; i <= n; i++)
        {
            int tmp = last - first + 1;
            bool f = 0;
            for (int j = 0; j<tmp / 2; j++)
            {
                if (a[first + j]>a[last - j])
                {
                    ans[i] = a[last], last--, f = 1;
                    break;
                }
                else if (a[first + j]<a[last - j])
                {
                    ans[i] = a[first], first++, f = 1;
                    break;
                }
            }
            if (f == 0) ans[i] = a[first], first++;
        }
        int cnt = 0;
        for (int i = 1; i <= n; i++)
        {
            printf("%c", ans[i] - 1 + 'A'); cnt++;
            if (cnt == 80)
            {
                printf("
    ");
                cnt = 0;
            }
        }
        printf("
    ");
    }
    
    int main()
    {
        while (~scanf("%d", &n))
        {
            read();
            work();
        }
        return 0;
    }
  • 相关阅读:
    用Python实现多核心并行计算
    Sublime Text 中文乱码
    Python_pickle
    New blog
    git Bash常用命令
    用TTS实现文本转语音
    bc#54 div2
    用Python制作新浪微博爬虫
    hdu5000 背包dp
    mac下配置Qt for Android+iOS
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5263137.html
Copyright © 2011-2022 走看看