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;}
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.
22 1
1
31 3 2
-1
21 2
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;}
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;}
后面两题明天添加..
- codeforces 259 div2 virtual Participation
- codeforces 260 div2 virtual Participation
- codeforces 261 div2 virtual Participation
- Codeforces Round #401 (Div. 2) (Virtual participation) 总结
- HDOJ 5334 Virtual Participation
- HDU 5334 Virtual Participation
- hdu 5334 Virtual Participation 构造
- HDOJ 5534 Virtual Participation 构造
- Hdu 5334 Virtual Participation (构造)
- [构造] HDU 5334 Virtual Participation
- 解题报告 之 HDU5334 Virtual Participation
- 构造(Virtual Participation,HDU 5334)
- hdu5334 Virtual Participation 多校联合第四场
- hdu5334(2015多校4)--Virtual Participation(构造)
- codeforces Round #259(div2) A解题报告
- codeforces Round #259(div2) B解题报告
- codeforces Round #259(div2) C解题报告
- codeforces Round #259(div2) D解题报告
- linux strace命令详解 进程跟踪
- Mac Yosemite系统下JAVA_HOME环境变量如何配置
- 国内银行核心系统建设情况调研报告
- 并行开发
- 51瞎搞系列---独立键盘+数码管
- codeforces 259 div2 virtual Participation
- mysql中的null与not null
- android圆角矩形有边框无背景色
- Ubuntu下安装ffmpeg
- 最小生成树-hdu1233-还是畅通工程
- python sklearn笔记 显示sample的图片
- C# dapper 动态参数 DynamicParameters
- 学习 iOS Autolayout的一点经验
- Ubuntuzilla: 安装最新版Mozilla软件的简单方法