codeforces 259 div2 virtual Participation

来源:互联网 发布:怎么用数据库做购物车 编辑:程序博客网 时间:2024/05/16 04:35

从今天到最近的一场考试还有11天...虽然还有很多没有复习,但还是感觉有点闲...补番工作开始

这是我补的第一场比赛,mark一下,这场应该是去年暑假的某一场,看到现在的自己比当时同级的众神表现略好还是觉得有点进步的(啊...说出这种话真是好羞耻)

嗯,废话不多说

A

打印图形..钻石图,呃直接上代码

#include <iostream>#include <string.h>#include <stdio.h>#include <algorithm>#include <stdlib.h>using namespace std;#define Nint main(){    int n,tmp;    cin>>n;    tmp=n/2;    for(int j=0;j<=tmp;j++){    for(int i=0;i<tmp-j;i++){        printf("*");    }    for(int i=0;i<j*2+1;i++) printf("D");    for(int i=0;i<tmp-j;i++){        printf("*");    }    printf("\n");    }    for(int j=1;j<=tmp;j++){        for(int i=0;i<j;i++) printf("*");        for(int i=0;i<n-2*j;i++) printf("D");        for(int i=0;i<j;i++) printf("*");        printf("\n");    }    return 0;}


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
题目大意就是能否通过把最后一个数字调到第一个这样的调整来实现整个序列为非递减序列

显然,如果可以这样调整的话,将序列首尾相连,整个环只会出现一个后面元素小于前面元素的情况,问题迎刃而解。

代码:

#include <iostream>#include <stdio.h>#include <string.h>using namespace std;#define N 1000010int a[N];int main(){    int n,ans,cnt,flag;    cnt=0;    cin>>n;    scanf("%d",&a[0]);    flag=n;    for(int i=1;i<n;i++){        scanf("%d",&a[i]);        if(a[i]<a[i-1]) {cnt++;        flag=i;        }    }    if(a[n-1]>a[0]){        cnt++;        flag=n;    }    if(cnt>1) printf("-1\n");    else printf("%d\n",n-flag);    return 0;}


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


这个题我确实想了半天,实在是太渣...不过还是想出来了

题目的大意是,给你一个m个面的骰子,让你投n次,求这n次投掷中的最大值的数学期望。

设n次投掷中最大值为Xi,对应的概率为Pi,E(x)=∑Xi*Pi。

显然最大值应该是从1~m,那么枚举就行了,重点是Pi怎么计算。

之前公式一直列错了。。其实只要列出所有情况,有1个最大值,有2个最大值...有n个最大值,即:

然后运用二项式定理,即可。




AC代码:

#include <iostream>#include <stdio.h>#include <math.h>using namespace std;int main(){    int m,n;    cin>>m>>n;    double ans;    ans=0;    for(int i=m;i>0;i--){        ans+=i*(pow((double)(i)/m,n*1.0)-pow((double)(i-1)/m,n*1.0));    }    printf("%.12lf\n",ans);    return 0;}

后面两题明天添加..




0 0