🔺 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: ...
随机推荐
- pg执行计划
- 工作中遇到的令人头疼的bug
工作中我们会遇到形形色色的bug,但是很多bug都可以调试很明显的看出来,这种bug解决起来我们不会那么头疼但是有些却让人头疼而捉急,特别是本地运行一切正常,上传服务器就会出现bug.现在我总结几个我 ...
- MySQL数据库之单双表查询
单表查询 先创建表 #创建表 create table employee( id int not null unique auto_increment, name varchar(20) not nu ...
- Python爬虫与反爬虫(7)
[Python基础知识]Python爬虫与反爬虫(7) 很久没有补爬虫了,相信在白蚁二周年庆的活动大厅比赛中遇到了关于反爬虫的问题吧 这节我会做个基本分享. 从功能上来讲,爬虫一般分为数据采集,处理, ...
- Unity Lighting - Light Probes 光照探针(十)
Light Probes 光照探针 Only static objects are considered by Unity’s Baked or Precomputed Realtime GI s ...
- Hyperledger_Fabric_Model
Hyperledger_Fabric_Model 本部分描述了Hyperledger Fabric的主要设计特点 Assets: 资产定义使得任何东西都可以通过货币值在网络中交易,从食物到老爷车再到期 ...
- golang笔记1
golang笔记1 go代码是用包来组织的,每个包有一个或多个go文件组成,这些go文件文件放在一个文件夹中 每个源文件开始都用一个package声明,指明本源文件属于哪个包 pakage声明后紧跟这 ...
- [笔记] mysql5.6一些编译参数
cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DSYSCONFDIR=/etc \ -DWITH_INNOBASE_STORAGE_ENGINE ...
- 原生js和jquey获取窗口宽高,滚动条,鼠标位置总结
JQuery获取浏览器窗口的可视区域高度和宽度,滚动条高度 alert($(window).height()); //浏览器时下窗口可视区域高度 alert($(document).height( ...
- vmvare fusion 8
http://jingyan.baidu.com/article/54b6b9c0f8830f2d583b47ce.html 补充:vmware tools 在上面,直接点击安装