ZJNU training for Provincial Collegiate Programming Contest(9)

来源:互联网 发布:用java搭建app服务器 编辑:程序博客网 时间:2024/05/20 05:11

A. 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:

题意:

就是给一个m个面的多面体,求抛n次。得到的最大值得期望;

如果对于最大为K为言。那么最大为k则抛的面数将会有k种情况。而且这k种情况必须有一次在k的面。那么我们假设多面都为k那么抛的概率为(k/m)。总的概率为pow(k/m,n);而这概率中有不满足情况的,就没有第k个面的那个面值,从而减掉。现在就相当于有(k-1)个情况,此时的概率为pow((k-1)/m,n)

所以最后的概率为:pow(k/m,n)- pow((k-1)/m,n)

从而期望就乘以相应的面值就可以了

就是对于每个值都求得它的最大的期望。

#include<stdio.h>#include<string.h>#include<math.h>int main(){int n,m,i,j,k;double ans=0,temp;scanf("%d%d",&m,&n);for(i=1;i<=m;i++){temp=pow(i*1.0/m,n)-pow((i-1)*1.0/m,n);ans+=temp*i;}printf("%.12lf\n",ans);}

B. Suffix Structures
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.

At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.

Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.

Input

The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.

Output

In the single line print the answer to the problem. Print "need tree" (without the quotes) if word s cannot be transformed into word teven with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.

It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.

Sample test(s)
input
automatontomat
output
automaton
input
arrayarary
output
array
input
bothhot
output
both
input
needtree
output
need tree
Note

In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".


这道题的实质就是一道题模拟题,叫你判断该执行什么操作对于给出的两个字符串a与b,使得a能够变到b串去。

给出的操作有4种:automation就是代表这个操作可以进行任意字符的删减,然后array代表的是进行字符串中任意两个字符的交换。both代表两个操作要同时进行才可以。need tree则代表没有办法使得a变到b。

然后叫你判断该进行什么操作。

#include<stdio.h>#include<string.h>char a[111],b[111];int map1[333],map2[333];int main(){int len1,len2;scanf("%s",a);len1=strlen(a);int i,j,k;for(i=0;i<len1;i++){map1[a[i]-'a'+1]++;}scanf("%s",b);len2=strlen(b);for(i=0;i<len2;i++) map2[b[i]-'a'+1]++;//如过长度相同并且两个字符串不同,那么只能是交换了; if(len1==len2){int flag=1;for(i=1;i<=26;i++){if(map1[i]==map2[i]) continue;else {flag=0; break;}}if(flag) puts("array");else puts("need tree");}else if(len1!=len2){int flag=1;//下面是为了判断b中的a中是否都有;  for(i=1;i<=26;i++){if(map1[i]<map2[i]) {flag=0; puts("need tree"); break;}}//如果长度不相等,那么一定要删减的;//如果b中有的a中也有的话,那么就只要判断是删减还是both就好了; if(flag){int select=0;int f1=0;//下面的那个操作是为了判断a串是不是要进行交换;//若满足a中的若干字符出现在b的话,那么就不用交换; for(i=0;i<len1;i++){if(a[i]==b[select]){select++;}}if(select==len2) f1=1;if(f1) puts("automaton");else puts("both");}}}

D. Multiplication Table
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bizon the Champion isn't just charming, he also is very smart.

While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted ann × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?

Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number.

Input

The single line contains integers nm and k (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m).

Output

Print the k-th largest number in a n × m multiplication table.

Sample test(s)
input
2 2 2
output
2
input
2 3 4
output
3
input
1 10 5
output
5
Note

2 × 3 multiplication table looks like this:

1 2 32 4 6

这道题的大致题意就是:给你一个n*m的乘法表,然后叫你判断按照不递减排下来的话,第k大的数是什么、

也是一道找规律的题:

同时也用到了二分法,这里要注意写法。

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;typedef long long ll;ll k,n,m;//每次对数字进行寻找它是第几个; ll getnum(ll x){ll sum=0;for(int i=1;i<=n;i++){sum+=min(x/i,m);}return sum;}int main(){int i,j;scanf("%lld%lld%lld",&n,&m,&k);ll l=1,r=n*m,mid;while(l<=r){mid=(l+r)/2;if(getnum(mid)>=k) r=mid-1;else l=mid+1;}printf("%lld\n",l);}

如果对于二分实现不知道该输出什么的时候那么就判断一下那个大就好了。


感觉能从不同的题目中收获不同的东西。

加油,hades!

0 0