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

    Best Cow Line
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 14718   Accepted: 4188

    Description

    FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his cows in a line and herds them past the judges.

    The contest organizers adopted a new registration scheme this year: simply register the initial letter of every cow in the order they will appear (i.e., If FJ takes Bessie, Sylvia, and Dora in that order he just registers BSD). After the registration phase ends, every group is judged in increasing lexicographic order according to the string of the initials of the cows' names.

    FJ is very busy this year and has to hurry back to his farm, so he wants to be judged as early as possible. He decides to rearrange his cows, who have already lined up, before registering them.

    FJ marks a location for a new line of the competing cows. He then proceeds to marshal the cows from the old line to the new one by repeatedly sending either the first or last cow in the (remainder of the) original line to the end of the new line. When he's finished, FJ takes his cows for registration in this new order.

    Given the initial order of his cows, determine the least lexicographic string of initials he can make this way.

    Input

    * Line 1: A single integer: N
    * Lines 2..N+1: Line i+1 contains a single initial ('A'..'Z') of the cow in the ith position in the original line

    Output

    The least lexicographic string he can make. Every line (except perhaps the last one) contains the initials of 80 cows ('A'..'Z') in the new line.

    Sample Input

    6
    A
    C
    D
    B
    C
    B

    Sample Output

    ABCBCD
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    char s[2001];
    int main()
    {
        int n;
        while(~scanf("%d",&n))
        {
            getchar();
            int cnt=0;
            for(int i=0;i<=n-1;i++)
                {
                    scanf("%c",&s[i]);
                    getchar();
                }
            int a=0,b=n-1;
            while(a<=b)
            {
             bool l=true;
            for(int i=0;a+i<=b;i++)
              {
                 if(s[a+i]<s[b-i])
                 {
                      break;
                 }
                 else
                    if(s[a+i]>s[b-i])
                 {
                      l=false;
                      break;
                 }
              }
               if(l)
                   {
                       printf("%c",s[a]);
                       a++;
                       cnt++;
                       if(cnt%80==0)
                          {
                              cout<<endl;
                              cnt=0;
                          }
                   }
               else
                 {
                     printf("%c",s[b]);
                     b--;cnt++;
                     if(cnt%80==0)
                         {
                            cout<<endl;
                            cnt=0;
                         }
                 }
            }
            if(cnt)
            printf("
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    EF CodeFirst EntityTypeConfiguration 自关联映射配置
    DDD 领域驱动设计-看我如何应对业务需求变化,领域模型调整?
    DDD 领域驱动设计-看我如何应对业务需求变化,愚蠢的应对?
    【记录】ASP.NET XSS 脚本注入攻击
    【记录】JS 获取图片原始尺寸-防止图片溢出
    让 ASP.NET vNext 在 Mac OS 中飞呀飞。。。
    Building Modern Web Apps-构建现代的 Web 应用程序(一些感想)
    【记录】ASP.NET MVC RegisterBundles
    【记录】JS 生成 URL 二维码
    关于有默认值的字段在用EF做插入操作时的思考(续)
  • 原文地址:https://www.cnblogs.com/smilesundream/p/6642557.html
Copyright © 2011-2022 走看看