codeforces#259 div2 (a,b,c)三题

来源:互联网 发布:招聘游戏程序员 编辑:程序博客网 时间:2024/05/29 19:34

题目链接:

啊哈哈,点我点我

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 ≤ 101n 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<cstdio>#include<cstring>const int maxn=101+10;char map[maxn][maxn];int vis[maxn][maxn];int main(){    int n,cal,sum;    while(~scanf("%d",&n))    {        memset(vis,0,sizeof(vis));        cal=(n+1)/2;        for(int i=1;i<cal;i++)            for(int j=cal,k=cal,sum=1;sum<=i;j--,k++,sum++)                    vis[i][j]=vis[i][k]=1;        for(int i=1;i<=n;i++)            vis[cal][i]=1;        for(int i=1;i<cal;i++)        {            for(int j=1;j<=n;j++)            {                int tmp=vis[i][j];                 vis[n+1-i][j]=tmp;            }        }        for(int i=1;i<=n;i++)        {            for(int j=1;j<=n;j++)               {                   if(vis[i][j])                     printf("%c",'D');                   else                     printf("*");               }                printf("\n");        }    }    return 0;}
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
22 1
output
1
input
31 3 2
output
-1
input
21 2
output
0

这道题是简单的找规律。你会发现这个序列被分成了两个非递减的序列。。且第二个序列的最后一个元素,即

a[n]要小于等于a[1]才能最后经过若干次翻转成为一个飞递减的序列。。。所以我们首先找到第二个序列的首位置即可。。

代码为:

#include<cstdio>#include<algorithm>#include<iostream>using namespace std;const int maxn=100000+10;int a[maxn],c[maxn];int main(){    int cal,ok,temp,pos,n,ans,i;    while(~scanf("%d",&n))    {        ok=0;        for(int i=1;i<=n;i++)           scanf("%d",&a[i]);        for(i=1;i<=n;i++)        {            if(i==1)                temp=a[i];            else            {                if(a[i]<temp)                {                    pos=i;                    break;                }                else                    temp=a[i];            }        }        if(i==n+1)        {            printf("0\n");            continue;        }        ans=pos;        //cout<<"cal"<<cal<<endl;        cal=1;        for(i=pos;i<=n;i++)        {            c[cal]=a[i];            cal++;        }        for(i=1;i<=pos-1;i++)        {            c[cal]=a[i];            cal++;        }        cal--;        for(i=1;i<=n;i++)        {             if(i==1)                temp=c[i];             else             {                 if(c[i]<temp)                   {                     ok=1;                     break;                   }                else                    temp=c[i];             }          }          if(ok)            printf("-1\n");          else            printf("%d\n",n-ans+1);    }    return 0;}/*45 6 4 5*/

problem  c:

C. Little Pony and Expected Maximum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.

The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the m-th face contains mdots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice n times.

Input

A single line contains two integers m and n (1 ≤ m, n ≤ 105).

Output

Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10  - 4.

Sample test(s)
input
6 1
output
3.500000000000
input
6 3
output
4.958333333333
input
2 2
output
1.750000000000
Note

Consider the third test example. If you've made two tosses:

  1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
  2. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
  3. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
  4. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.

The probability of each outcome is 0.25, that is expectation equals to:

You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value

这个题目最开始题目都没看懂。。哎 

思路是:

因为是求最大点数的期望。。所以比如有6面。5个骰子,那么出现最大点为1的次数为1^5,出现最大点为2的次数为2^5-1^5,以此类推最后得到最大点为i的次数为(i^n-(i-1)^n ),那么求最大点的期望就很简单了。。。

不知道为什么直接用pow函数比快速幂还快一点。。。。顺便复习一下快速幂。。比如求a^b,那么比如b为13

那么b可以用二进制表示成1101,所以就是a^1*a^4*a^8,所以每次对b进行左移操作,如果为基数,则进行计算,偶数不做处理,但是不管是基数,还是哦偶数,a都要进行平方。。。。。我也讲不清楚。读者自行理解。。

代码为:

#include<cstdio>using namespace std;double Pow(double a,int b){    double ans;    ans=1.0;    while(b)    {        if(b&1)            ans=ans*a;        a=a*a;        b=b/2;    }    return ans;}int main(){    int m,n;    double ans;    while(~scanf("%d%d",&m,&n))    {        ans=0;        for(int i=1;i<=m;i++)            ans=ans+i*(Pow(i*1.0/m,n)-Pow((i-1)*1.0/m,n));        printf("%.12lf\n",ans);    }    return 0;}

加油!!希望下次不掉分。。。。快哭了快哭了快哭了



0 0
原创粉丝点击