🔺 Garbage Remembering Exam UVA - 11637()
其中 x为当前单词的左右距离为k的单词的个数, 分子是把一排单词中一个单词的有效距离的单词取出来全排列到环形的无效距离内,然后剩余的单词全排列;
考虑到排列与组合数据过大,用 exp()函数,其中log(N!)=log(N)+log(N-1)+...+log(1);
需要注意 用long double能过。。。
代码如下:
没大弄明白为什么n-1-x < 2*k 的时候不考虑
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 100005
long double temp[N];
int n,k;
double solve()
{
if(n==) return ;//只有一个单词,无效为0
else if(*k+>=n) return n;//如果圈中的一个单词从左边或右边距离都小于K,则该单词无效,所有单词等效
double ret=;
for(int i=;i<=n;i++)
{
int x=min(k,i-)+min(k,n-i);//一个单词左右k范围内的单词个数
if(n--x-*k>=)
{
ret+=exp(temp[n--x]+temp[n--*k]-temp[n-]-temp[n--x-*k]);
}
// else
// ret += exp(temp[2*k] - temp[2*k-n+1+x] + temp[x] - temp[n-1]);
}
return n-ret;
}
int main()
{
temp[]=;
for(int i=;i<N;i++)
temp[i]=temp[i-]+log((long double)i);
int cas=;
while(scanf("%d%d",&n,&k))
{
if(n==&&k==) break;
printf("Case %d: %.4lf\n",cas++,solve());
}
return ;
}
🔺 Garbage Remembering Exam UVA - 11637()的更多相关文章
- UVA - 11637 Garbage Remembering Exam (组合+可能性)
Little Tim is now a graduate,and is thinking about higher studies. However, he first needs to appear ...
- uva 11673 Garbage Remembering Exam (概率)
题目链接: http://vjudge.net/problem/viewProblem.action?id=42000 该过程为随即过程,因此总期望值等于个单词对应的期望值,即它们wasted的概率 ...
- UVA 11637 Garbage Remembering Exam
#include <iostream> #include <stdio.h> #include <cstring> #include <math.h> ...
- UVa 156 (映射 map)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 训练指南 UVA - 11419(二分图最小覆盖数)
layout: post title: 训练指南 UVA - 11419(二分图最小覆盖数) author: "luowentaoaa" catalog: true mathjax ...
- 训练指南 UVA - 11383(KM算法的应用 lx+ly >=w(x,y))
layout: post title: 训练指南 UVA - 11383(KM算法的应用 lx+ly >=w(x,y)) author: "luowentaoaa" cata ...
- 训练指南 UVA - 11354(最小生成树 + 倍增LCA)
layout: post title: 训练指南 UVA - 11354(最小生成树 + 倍增LCA) author: "luowentaoaa" catalog: true ma ...
- 训练指南 UVA - 11478(最短路BellmanFord+ 二分+ 差分约束)
layout: post title: 训练指南 UVA - 11478(最短路BellmanFord+ 二分+ 差分约束) author: "luowentaoaa" catal ...
- 训练指南 UVA - 11090(最短路BellmanFord+ 二分判负环)
layout: post title: 训练指南 UVA - 11090(最短路BellmanFord+ 二分判负环) author: "luowentaoaa" catalog: ...
随机推荐
- 【转载】C/C++杂记:深入虚表结构
原文:C/C++杂记:深入虚表结构 1. 虚表与“虚函数表” 在“C/C++杂记:虚函数的实现的基本原理”一文中曾提到“虚函数表”的概念,只是为了便于理解,事实是:虚函数表并不真的独立存在,它只是虚表 ...
- 洛谷 P1941 飞扬的小鸟
洛谷 P1941 飞扬的小鸟 原题链接 首先吐槽几句 noip都快到了,我还不刷起联赛大水题! 题目描述 Flappy Bird 是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节 ...
- TensorFlow深度学习实战---图像数据处理
图像的亮度.对比度等属性对图像的影响非常大,这些因素都会影响最后的识别结构.当然,复杂的预处理过程可能会导致训练效率的下降(利用TensorFlow中多线程处理输入数据的解决方案). 同一不同的原始数 ...
- 获取Java线程返回值的几种方式
在实际开发过程中,我们有时候会遇到主线程调用子线程,要等待子线程返回的结果来进行下一步动作的业务. 那么怎么获取子线程返回的值呢,我这里总结了三种方式: 主线程等待. Join方法等待. 实现Call ...
- openvpn部署
原文发表于cu:2016-03-29 参考文档: 安装:http://qicheng0211.blog.51cto.com/3958621/1575273 安装:http://www.ipython. ...
- JS对字符串编码的几种方式
函数 描述 encodeURI() 把字符串编码为 URI encodeURIComponent() 把字符串编码为 URI 组件 escape() 对字符串进行编码 上面是查询来自w3school的 ...
- 华为笔试——C++转换字符串问题
题目:转换字符串 题目介绍: 将输入字符串中下标为偶数的字符连成一个新的字符串输出,需要注意两点: 1. 如果输入字符串的长度超过20,则转换失败,返回“ERROR!”字符串: 2. 输入字符串只能由 ...
- We are writing to let you know we have removed your selling privileges
Hello, We are writing to let you know we have removed your selling privileges, canceled your listin ...
- Python基础知识-05-数据类型总结字典
python其他知识目录 1.一道题,选择商品的序号.程序员和用户各自面对的序号起始值 如有变量 googs = ['汽车','飞机','火箭'] 提示用户可供选择的商品: 0,汽车1,飞机2,火箭用 ...
- 手动配置网卡配置文件ifcfg-eth0
linux 其他知识目录 原文链接:https://www.cnblogs.com/arvintang/p/5990599.html 网络接口配置文件[root@localhost ~]# cat / ...