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;
    }
    
  • 相关阅读:
    彻底解决SQL SERVER 2008无法远程连接的问题
    将ReportingService 2008配置为匿名访问
    将低版本的数据库迁移到sqlserver 2008
    Oracle 11G R2
    Reporting Services 安装的备份和还原操作
    DefaultValue
    用户 'IIS APPPOOL\DefaultAppPool' 登录失败。
    在IIS中为SQL Server 2008配置报表服务
    数据库日志维护方式
    如何卸载的 SQL Server 2008 实例
  • 原文地址:https://www.cnblogs.com/smilesundream/p/6642557.html
Copyright © 2011-2022 走看看