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*** 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
看样例就知道了,直接模拟即可
 #include <stdio.h>
#include <string.h>
#include <stdlib.h> int main()
{
int i,j,n,m,k,t;
while(scanf("%d",&n)!=EOF)
{
int tmp1=n/,tmp2=n/,tmp3=;
for(i=;i<=n/;i++)
{
for(j=;j<=tmp1;j++)
printf("*");
for(j=tmp1;j<=tmp2;j++)
printf("D");
for(j=tmp2+;j<=n;j++)
printf("*");
printf("\n");
tmp1--;tmp2++;
}
for(i=;i<=n;i++)
printf("D");
printf("\n");
tmp1=,tmp2=n;
for(i=;i<=n/;i++)
{
for(j=;j<=tmp1;j++)
printf("*");
for(j=tmp1+;j<=tmp2-;j++)
printf("D");
for(j=tmp2;j<=n;j++)
printf("*");
tmp1++;tmp2--;
printf("\n");
}
}
return ;
}

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

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
//////////////////////////////////////////////////////
模拟题,判断每两个出现递减的,算出有多少个递减的,如果有两个以上的,就是不行的,
当为零,说明没有递减的,为一需判断起点与终点的大小,可不可以接上
 #include <stdio.h>
#include <string.h>
#include <stdlib.h> int str[]; int main()
{
int n,m,i,j;
while(scanf("%d",&n)!=EOF)
{
for(i=; i<=n; i++)
{
scanf("%d",&str[i]);
}
int sum=,tmp;
for(i=; i<=n; i++)
{
if(str[i]<str[i-])
{
sum++;
tmp=i;
} }
if(sum == )printf("0\n");
else if(sum > )printf("-1\n");
else if(sum == && str[n] <= str[])
printf("%d\n",n-tmp+);
else printf("-1\n");
}
return ;
}

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

就这样结束了……

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

上一篇:Codeforces Round #713 (Div. 3)AB题


下一篇:Java基础 -- 深入理解泛型