J.The Keys

Out of all science labs constructed by the GEMA mission on Mars, the DSL - Dangerous Species Lab is the most dangerous of them all. The laboratory is so dangerous that you have to go through N doors in succession to get to it. Each one of those doors can only be opened by one key di (notice, however, that there may be different doors that can be opened by the same key).

A nameless lazy biologist (we'll call him LB) from GEMA needs to open all those doors first thing in the morning, every day. He has all the keys necessary to open them, but he finds carrying all of them in his pockets too much of a mess.

To be more organized and lose the title of being a lazy biologist, LB purchased Kkey-chains and is planning to distribute all the keys among them. His plan of distribution is very simple. For each key, randomly choose a key-chain with uniform probability and put this key on it.

When opening the doors, LB will hold one key-chain and will keep the others in his pocket (initially all of them are in his pocket). Whenever he gets to a door that needs a key that is not on the key-chain he is holding, he will swap it with the key-chain that has this key. Getting the first key-chain from his pocket is not considered a swap.

You have to help LB and find what is the expected number of key-chain swaps he will have to do when opening the doors the next morning.

Input

Input begins with N and K (1 ≤ N ≤ 105, 1 ≤ K ≤ N), the number of doors and the number of key-chains. On the next line there are N numbers di (1 ≤ di ≤ 106), the identifier of the key that opens the i-th door.

Output

Output the expected number of swaps. Your answer will be considered correct if the absolute and relative error are less than 10 - 6.

Example

Input
3 3
1 2 3
Output
1.333333333
Input
1 1
2
Output
0.000000000
Input
5 2
1 2 3 2 1
Output
2.000000000

代码:

 1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #include<cstring>
5 #include<cstdlib>
6 #include<string.h>
7 #include<set>
8 #include<vector>
9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<cmath>
13 using namespace std;
14 typedef long long ll;
15 const int N=1e5+10;
16 const int INF=0x3f3f3f3f;
17 int a[N];
18 int main(){
19 int n,k;
20 double ans;
21 while(~scanf("%d%d",&n,&k)){
22 for(int i=1;i<=n;i++)
23 scanf("%d",&a[i]);
24 ans=0;
25 if(n==1)printf("%.9f\n",(k-1)*1.0/k);
26 //if(n==1)printf("%.9f\n",ans);
27 else{
28 for(int i=2;i<=n;i++){
29 if(a[i]!=a[i-1])
30 ans+=(k-1)*1.0/k;
31 }
32 printf("%.9f\n",ans);
33 }
34 }
35 return 0;
36 }

其他的写不出来了。

最新文章

  1. Federated Identity Pattern 联合身份模式
  2. 为什么我不建议你做APP?
  3. 【spring bean】 spring中bean之间的引用以及内部bean
  4. 如何使用命令行编译以及运行java文件
  5. C#_项目做成安装包
  6. UVa 156 Ananagrams
  7. ubuntu(16.04.01)学习-day1
  8. asp.net &lt;% %&gt;,&lt;%# %&gt;,&lt;%= %&gt;,&lt;%$ %&gt;区别大集合
  9. Hyper-V网络虚拟化--VM之间拷贝速度慢
  10. [转] jQuery按键响应事件keypress对应的按键编码keycode
  11. Android4.3模拟器界面中右侧菜单按钮无法使用问题解决办法
  12. navicat连接oracle数据库报ORA-28547: connection to server failed, probable Oracle Net admin error错误的解决方法
  13. Vacations
  14. 对Spring IOC和AOP的理解
  15. vc关于大文件读写
  16. php Pthread 多线程 Worker
  17. virtualbox - 2台虚拟机之间通过ssh互访
  18. Centos7 Journald 指令
  19. 用socket.io将Node后台与M站相联系
  20. delphi WebBrowser的使用方法详解(六)

热门文章

  1. UVA:11297-Census(二维线段树)
  2. lua table长度解析
  3. Maya建模命令
  4. Sicily 8843 Ranking and Friendship
  5. Android stadio litepal
  6. Android百度地图开发 百度地图得到当前位置
  7. easyui 判断密码是否输入一致
  8. day 17 jQuery
  9. 6、CSS基础 part-4
  10. jquery实现轮播插件