从今天到最近的一场考试还有11天...虽然还有很多没有复习,但还是感觉有点闲...补番工作开始
这是我补的第一场比赛,mark一下,这场应该是去年暑假的某一场,看到现在的自己比当时同级的众神表现略好还是觉得有点进步的(啊...说出这种话真是好羞耻)
嗯,废话不多说
A
打印图形..钻石图,呃直接上代码
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
#define N
int 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;
}
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
显然,如果可以这样调整的话,将序列首尾相连,整个环只会出现一个后面元素小于前面元素的情况,问题迎刃而解。
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define N 1000010
int 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;
}
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.
A single line contains two integers m and n (1 ≤ m, n ≤ 105).
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.
6 1
3.500000000000
6 3
4.958333333333
2 2
1.750000000000
Consider the third test example. If you've made two tosses:
- You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
- You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
- You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
- 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;
}
后面两题明天添加..