codeforces#259 div2 (a,b,c)三题
来源:互联网 发布:招聘游戏程序员 编辑:程序博客网 时间:2024/05/29 19:34
题目链接:
problem A:
A. Little Pony and Crystal Minetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwilight 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.
InputThe only line contains an integer n (3 ≤ n ≤ 101; n is odd).
OutputOutput a crystal of size n.
Sample test(s)input3
output*D*DDD*D*
input5
output**D***DDD*DDDDD*DDD***D**
input7
output***D*****DDD***DDDDD*DDDDDDD*DDDDD***DDD*****D***
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.
The only line contains an integer n (3 ≤ n ≤ 101; n is odd).
Output a crystal of size n.
3
*D*DDD*D*
5
**D***DDD*DDDDD*DDD***D**
7
***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 Shifttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne 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?
InputThe first line contains an integer n (2 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).
OutputIf 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)input22 1
output1
input31 3 2
output-1
input21 2
output0
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
这道题是简单的找规律。你会发现这个序列被分成了两个非递减的序列。。且第二个序列的最后一个元素,即
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:
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
这个题目最开始题目都没看懂。。哎
思路是:
因为是求最大点数的期望。。所以比如有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;}
加油!!希望下次不掉分。。。。
- codeforces#259 div2 (a,b,c)三题
- codeforces round # 273 div2 A, B, C题题解
- Codeforces Round #434 div2 A, B , C,D 题 题解
- codeforces Round #377 div2 A B C(数学推导)
- Codeforces 228 div2 A,B,C
- codeforces 239 (div2) A B C D
- codeforces 208(div2) A+B+C+D
- Codeforces Rounds #254 div2:A,B,C
- codeforces 260 div2 A,B,C
- Codeforces Round #278(Div2) A B C
- codeforces #285 div2 *A B *C
- codeforces 250 div2 A B C D
- Codeforces Round #432 div2 A+B+C
- codeforces#336 div2 A,B
- Codeforces Round#229 DIV2 A,B,C,D
- codeforces RCC2014 Warmup div2 A+B+C+D+E
- Codeforces Round#258 div2 A B C (Problemset 451)
- 【套题】Codeforces#306(div2)[A-C]
- Qt实现3D纹理渲染自由旋转空间立方体
- hdu 1074 Doing Homework (状态压缩dp)
- 冒泡排序实现--python
- Fibnacci序列 1
- Spinner
- codeforces#259 div2 (a,b,c)三题
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest(套题HDU4001-4010)
- Fibnacci序列2
- 程序员笑话
- 暑期实训第四课(无线串口模块进行通讯)
- qt学习笔记
- UVA 839 Not so Mobile
- 说说Web Service
- hdu1272- 小希的迷宫