Codeforces Round #259 (Div. 2)

A. Little Pony and Crystal Mine http://codeforces.com/contest/454/problem/A

 1 #include<cstdio>
 2 int main(){
 3     int n;
 4     while(~scanf("%d",&n)){
 5         for(int i=1;i<=n/2;i++){
 6             for(int j=0;j<n/2+1-i;j++){
 7                 printf("*");
 8             }
 9             for(int j=0;j<i*2-1;j++){
10                 printf("D");
11             }
12             for(int j=0;j<n/2+1-i;j++){
13                 printf("*");
14             }
15             puts("");
16         }
17         for(int i=1;i<=n;i++){
18             printf("D");
19         }
20         puts("");
21         for(int i=1;i<=n/2;i++){
22             for(int j=0;j<i;j++){
23                 printf("*");
24             }
25             for(int j=0;j<(n/2+1-i)*2-1;j++){
26                 printf("D");
27             }
28             for(int j=0;j<i;j++){
29                 printf("*");
30             }
31             puts("");
32         }
33     }
34     return 0;
35 }
View Code

 B. Little Pony and Sort by Shift http://codeforces.com/contest/454/problem/B

 1 #include<cstdio>
 2 const int M=100010;
 3 int a[M];
 4 int main(){
 5     int n;
 6     while(~scanf("%d",&n)){
 7         for(int i=0;i<n;i++){
 8             scanf("%d",&a[i]);
 9         }
10         int cnt=0,id;
11         for(int i=0;i<n-1;i++){
12             if(a[i]>a[i+1]){
13                 cnt++;
14                 id=i+1;
15             }
16         }
17         if(cnt>1) puts("-1");
18         else if(cnt<1) puts("0");
19         else if(a[n-1]>a[0]) puts("-1");
20         else printf("%d\n",n-id);
21     }
22     return 0;
23 }
View Code

 C. Little Pony and Expected Maximum http://codeforces.com/contest/454/problem/C

 1 #include<cstdio>
 2 int m,n;
 3 double mypow(int i){
 4     double a=i*1.0/m,res=1;
 5     int p=n;
 6     while(p){
 7         if(p&1) res*=a;
 8         a*=a;
 9         p>>=1;
10     }
11     return res;
12 }
13 int main(){
14     while(~scanf("%d%d",&m,&n)){
15         double ans=0;
16         for(int i=1;i<=m;i++){
17             ans+=i*(mypow(i)-mypow(i-1));
18         }
19         printf("%.12f\n",ans);
20     }
21     return 0;
22 }
View Code

 

 

 

 

end

posted on 2014-08-02 10:49  gaolzzxin  阅读(135)  评论(0编辑  收藏  举报