链接:http://codeforces.com/contest/454/problem/A
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.
The only line contains an integer n (3 ≤ n ≤ 101; n is odd).
Output a crystal of size n.
3
*D*
DDD
*D*
5
**D**
*DDD*
DDDDD
*DDD*
**D**
7
***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("\n"); 20 tmp1--;tmp2++; 21 } 22 for(i=1;i<=n;i++) 23 printf("D"); 24 printf("\n"); 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("\n"); 36 } 37 } 38 return 0; 39 }
B:http://codeforces.com/contest/454/problem/B
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:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
The first line contains an integer n (2 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
2
2 1
1
3
1 3 2
-1
2
1 2
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\n"); 27 else if(sum > 1)printf("-1\n"); 28 else if(sum == 1 && str[n] <= str[1]) 29 printf("%d\n",n-tmp+1); 30 else printf("-1\n"); 31 } 32 return 0; 33 }
今天没事干,模拟了下CF,只做了A题,模拟速度超慢 A题模拟了15min,B题想了一会没思路,就取看C题,找了一会规律没找到,
就这样结束了……
C题组合数学,看不太懂题解,
AC不易,且行且珍惜……