UVALive - 6267 Beer Pressure
题意:
给定n个酒吧, 然后有k个学生投票今晚去哪个酒吧, 然后会有a个(a<=k)学生先投票了, 先投的票会影响后面的人投票的概率, 求每个酒吧今晚去的概率。
分析:
我们可以从最初的状态开始广搜, 由于搜索中会有很多重复的状态, 我们用一个map去储存这些状态, 如果map中没有这个状态再将他入队。由于搜索量很大, 如果用vector作为队列元素的话会MLE, 我们可以将最多5个酒吧,每个酒吧不超过两位的投票数映射成一个10位的long long作为队列元素, 出队时候再还原成n个投票数,最终输出所有的结果即可。
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int inf = 1e9 + ;
const int maxn = ;
double possible[maxn];
int temp[maxn];
const LL P[] = {1LL,100LL,10000LL,1000000LL,100000000LL};
int n, k;
int bfs(LL start){
map<LL, double> m;//记录状态
m[start] = 100.0;//开始状态
queue<LL> q;
q.push(start);
while(!q.empty()){
LL u = q.front(); q.pop();
double pp = m[u];
int tot = ;
LL tmp = u;
for(int i = n; i > ; i--){//将long long 还原成数组
temp[i] = int(tmp%100LL);
tmp /= 100LL;
tot += temp[i];
}
if(tot == k){//已经投完票, 选出票数最多的将概率分享。
int winner[maxn] = {};
int Max = temp[];
int chosen = ;
winner[chosen++] = ;
for(int i = ; i <= n; i++){
if(Max == temp[i])winner[chosen++] = i;
else if(temp[i] > Max){
Max = temp[i];
chosen = ;
winner[chosen++] = i;
}
}
for(int i = ; i < chosen; i++)
possible[winner[i]] += pp/(double)chosen;
}
else{
for(int i = n; i >= ; i--){
LL v = u + P[n - i];
double c = (double)temp[i] / (double)tot; map<LL, double> :: iterator it = m.find(v);
if(it == m.end())
m[v] = pp * c, q.push(v);//如果没出现这个状态就入队
else
it->second += pp * c;//出现过直接在这个状态上面加
}
}
}
}
int main(){
while(~scanf("%d %d", &n, &k)){
memset(possible,,sizeof(possible));
LL u = ;
for(int i = ; i < n; i++){int t;scanf("%d", &t); u *= 100LL, u += t;}//映射成一个10位long long
bfs(u);
for(int i = ;i <= n; i++) printf("pub %d: %.2f %%\n",i, possible[i]);
}
}
UVALive - 6267 Beer Pressure的更多相关文章
- 2012-2013 Northwestern European Regional Contest (NWERC 2012)
B - Beer Pressure \(dp(t, p_1, p_2, p_3, p_4)\)表示总人数为\(t\),\(p_i\)对应酒吧投票人数的概率. 使用滚动数组优化掉一维空间. 总的时间复杂 ...
- Reporting Service 告警"w WARN: Thread pool pressure. Using current thread for a work item"
如果Reporting Service偶尔出现不可访问或访问出错情况,这种情况一般没有做监控的话,很难捕捉到.出现这种问题,最好检查Reporting Service的日志文件. 今天早上就遇到这样一 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- LinuxMM--Memory Pressure
Memory pressure定义在操作系统中,用户分配.文件缓存.网卡包缓冲区等等都会消耗内存.一旦出现内存紧张就会导致memory pressure.引发当某个任务需要请求内存时就有可能引发mem ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
随机推荐
- shiro之自定义realm
Shiro认证过程 创建SecurityManager--->主体提交认证--->SecurityManager认证--->Authenticsto认证--->Realm验证 ...
- 跟我一起玩Win32开发(4):创建菜单
也不知道发生什么事情,CSDN把我的文章弄到首页,结果有不少说我在误人子弟,是啊,我去年就说过了,如果你要成为砖家级人物,请远离我的博客,我这个人没什么特长,唯一厉害的一点就是不相信权威,鄙视砖家,所 ...
- 双端队列 HDOJ 3530 Subsequence
题目传送门 题意:问最长子序列,满足区间最大值 - 最小值在[m, k]之间 分析:用双端队列维护最大值和最小值,保存的是位置.当满足条件时,更新最大值. /********************* ...
- curry柯里化函数实现
curry柯里化函数实现 参考文章: 一行写出javascript函数式编程中的curry 感谢作者分享 第一步: 缓存原始函数的参数个数 function curry(fn) { var limit ...
- HTTP提交方式之PUT详细介绍及POST和PUT的区别
Http定义了与 服务器的交互方法,其中除了一般我们用的最多的GET,POST 其实还有PUT和DELETE 根据RFC2616标准(现行的HTTP/1.1)其实还有OPTIONS,GET,HEAD, ...
- 150 Evaluate Reverse Polish Notation 逆波兰表达式求值
求在 逆波兰表示法 中算术表达式的值.有效的运算符号包括 +, -, *, / .每个运算对象可以是整数,也可以是另一个逆波兰计数表达.例如: ["2", "1&quo ...
- MySQL GTID复制
什么是GTID 什么是GTID呢, 简而言之,就是全局事务ID(global transaction identifier ),最初由google实现,官方MySQL在5.6才加入该功能.GTID是事 ...
- CentOS 安装图形化界面方法
登录系统,使用yum 安装 #yum groupinstall 'X Window System' -y 安装GNOME桌面环境 #yum groupinstall 'GNOME Desktop ...
- WPF日常需要使用的操作
窗体如何居中弹出 在窗体上添加属性 WindowStartupLocation="CenterScreen" 窗体如何隐藏掉windows边框 添加属性WindowStyle=& ...
- toast插件的简单封装(样式适用pc后台管理系统的场景)
直接分三个步骤吧: 1.手写一个toast.vue组件 <template> <transition name="toast-fade"> <div ...