1.Little Pony and Crystal Mine
题目链接:
http://codeforces.com/problemset/problem/454/A
解题思路:
Brief description:
Draw the grid graph as the problem said.
Analysis:
Just a few basics of your programming language. It's easy.
AC代码:
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int n;
while(~scanf("%d",&n)){
int tmp1 = n/2,tmp2 = 1,cnt = n/2+1;
for(int i = 1; i <= cnt; i++){
for(int j = 1; j <= tmp1; j++)
printf("*");
for(int j = 1; j <= tmp2; j++)
printf("D");
for(int j = 1; j <= tmp1; j++)
printf("*");
tmp1--;
tmp2 += 2;
printf("\n");
}
tmp1++;
tmp2 -= 2;
for(int i = cnt-1; i >= 1; i--){
tmp1++;
tmp2 -= 2;
for(int j = 1; j <= tmp1; j++)
printf("*");
for(int j = 1; j <= tmp2; j++)
printf("D");
for(int j = 1; j <= tmp1; j++)
printf("*");
printf("\n");
}
}
return 0;
}
2.Little Pony and Sort by Shift
题目链接:
http://codeforces.com/problemset/problem/454/B
解题思路:
Brief description:
Ask the minimum unit shift you need to sort a array.
Analysis:
Just a few basics of your programming language. It's not hard.
AC代码:
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int n;
while(~scanf("%d",&n)){
int x0,x,tmp = 0,down = 0,pos = n;
scanf("%d",&x0);
tmp = x0;
for(int i = 1; i < n; i++){
scanf("%d",&x);
if(down > 1)
continue;
if(x < tmp){
down++;
pos = i;
}
tmp = x;
}
if(down > 1 || down == 1 && x > x0)
printf("-1\n");
else
printf("%d\n",n-pos);
}
return 0;
}
3.Little Pony and Expected Maximum(排列组合)
题目链接:
http://codeforces.com/problemset/problem/453/A
解题思路:
Brief description:
Calculate the expected maximum number after tossing a m faces dice n times.
Analysis:
Take m = 6, n = 2 as a instance.
6 6 6 6 6 6
5 5 5 5 5 6
4 4 4 4 5 6
3 3 3 4 5 6
2 2 3 4 5 6
1 2 3 4 5 6
Enumerate the maximum number, the distribution will be a n-dimensional super-cube with m-length-side. Each layer will be a large cube minus a smaller cube. So we have:

Calculate in may cause overflow, we could move the divisor into the sum and calculate (i / m)n instead.
化简如下: p = ( (1^n-0^n)*1 + (2^n-1^n)*2 。。。 +(m^n - (m-1)^n)*m ) / m^n =》p = m - ((m-1)/m)^n + ((m-2)/m)^n。。。+(1/m)^n ;
AC代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main (){
int n,m;
scanf("%d%d",&m,&n);
double ans = 0;
for (int i = 1; i < m; i++)
ans += pow((double)i/m,n);
printf("%.12lf\n",(double)m - ans);
return 0;
}