• Codeforces Round #259 (Div. 2)AB


    链接:http://codeforces.com/contest/454/problem/A

    A. Little Pony and Crystal Mine
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it.

    You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw.

    Input

    The only line contains an integer n (3 ≤ n ≤ 101; n is odd).

    Output

    Output a crystal of size n.

    Sample test(s)
    input
    3
    output
    *D*
    DDD
    *D*
    input
    5
    output
    **D**
    *DDD*
    DDDDD
    *DDD*
    **D**
    input
    7
    output
    ***D***
    **DDD**
    *DDDDD*
    DDDDDDD
    *DDDDD*
    **DDD**
    ***D***


    。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
    。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
    看样例就知道了,直接模拟即可
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <stdlib.h>
     4 
     5 int main()
     6 {
     7     int i,j,n,m,k,t;
     8     while(scanf("%d",&n)!=EOF)
     9     {
    10         int tmp1=n/2,tmp2=n/2,tmp3=1;
    11         for(i=1;i<=n/2;i++)
    12         {
    13             for(j=1;j<=tmp1;j++)
    14                 printf("*");
    15             for(j=tmp1;j<=tmp2;j++)
    16                 printf("D");
    17             for(j=tmp2+2;j<=n;j++)
    18                 printf("*");
    19             printf("
    ");
    20             tmp1--;tmp2++;
    21         }
    22         for(i=1;i<=n;i++)
    23             printf("D");
    24         printf("
    ");
    25         tmp1=1,tmp2=n;
    26         for(i=1;i<=n/2;i++)
    27         {
    28             for(j=1;j<=tmp1;j++)
    29                 printf("*");
    30             for(j=tmp1+1;j<=tmp2-1;j++)
    31                 printf("D");
    32             for(j=tmp2;j<=n;j++)
    33                 printf("*");
    34             tmp1++;tmp2--;
    35             printf("
    ");
    36         }
    37     }
    38     return 0;
    39 }

    B:http://codeforces.com/contest/454/problem/B

    B. Little Pony and Sort by Shift
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:

    a1, a2, ..., an → an, a1, a2, ..., an - 1.

    Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?

    Input

    The first line contains an integer n (2 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).

    Output

    If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.

    Sample test(s)
    input
    2
    2 1
    output
    1
    input
    3
    1 3 2
    output
    -1
    input
    2
    1 2
    output
    0

    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    //////////////////////////////////////////////////////
    模拟题,判断每两个出现递减的,算出有多少个递减的,如果有两个以上的,就是不行的,
    当为零,说明没有递减的,为一需判断起点与终点的大小,可不可以接上
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <stdlib.h>
     4 
     5 int str[100010];
     6 
     7 int main()
     8 {
     9     int n,m,i,j;
    10     while(scanf("%d",&n)!=EOF)
    11     {
    12         for(i=1; i<=n; i++)
    13         {
    14             scanf("%d",&str[i]);
    15         }
    16         int sum=0,tmp;
    17         for(i=2; i<=n; i++)
    18         {
    19             if(str[i]<str[i-1])
    20             {
    21                 sum++;
    22                 tmp=i;
    23             }
    24                 
    25         }
    26         if(sum == 0)printf("0
    ");
    27         else if(sum > 1)printf("-1
    ");
    28         else if(sum == 1 && str[n] <= str[1])
    29             printf("%d
    ",n-tmp+1);
    30         else printf("-1
    ");
    31     }
    32     return 0;
    33 }

    今天没事干,模拟了下CF,只做了A题,模拟速度超慢  A题模拟了15min,B题想了一会没思路,就取看C题,找了一会规律没找到,

    就这样结束了……

    C题组合数学,看不太懂题解,
    AC不易,且行且珍惜……

  • 相关阅读:
    CPT104-labs
    Java-数据结构-ArrayList
    INT104-lab13[Parzen Window Method][此方法无数据集划分]
    INT104-lab12 [KNN Algorithm][lambda表达式]
    INT104-lab11 [聚类] [iris数据集] [K-means Algorithm]
    Nginx配置https兼容http
    JS获取整个网页html代码
    nginx重启生效conf文件的修改
    WampServer
    在win10系统中,开启hyper-v要满足下列条件
  • 原文地址:https://www.cnblogs.com/ccccnzb/p/3895751.html
Copyright © 2020-2023  润新知