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 ...
随机推荐
- c++,类的对象作为形参时一定会调用复制构造函数吗?
c++,类的对象作为形参时一定会调用复制构造函数吗? 答:如果参数是引用传递,则不会调用任何构造函数:如果是按值传递,则调用复制构造函数,按参数的值构造一个临时对象,这个临时对象仅仅在函数执行是存在, ...
- 接口测试01 - HTTP协议报文结构及示例
HTTP基本架构 用一张简单的流程图来展示HTTP协议的基本架构,以便先有个基础的了解. 1)Web Client可以是浏览器.搜索引擎等等一切基于HTTP协议发起http请求的工具. 2)Web S ...
- 正则表达式test报错 is not a function
var reg = "/^1[34578]\d{9}$/"; //错误格式,这是一个字符串 var reg2 = /^1[34578]\d{9}$/; //正确格式 reg .te ...
- oracle PL、SQL(概念)
一.PL/SQL简介. Oracle PL/SQL语言(Procedural Language/SQL)是结合了结构化查询和Oracle自身过程控制为一体的强大语言,PL/SQL不但支持更多的数据类型 ...
- 解决vue跨域问题
package com.qmtt.config; import java.io.IOException; import javax.servlet.Filter; import javax.servl ...
- Android Studio V4 V7 包冲突的问题
最近被包冲突的问题搞奔溃了,特别是V4,V7 V4和V7包冲突的解决方式就是!版本要一致!! 比如我的一个项目中应用本来是这样引用包的 compile 'com.android.support:sup ...
- iOS 获取真机上系统动态库文件
iOS 获取真机上所有系统库文件 系统动态库文件存放真机地址(/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64) 在Mac\i ...
- mysql登录(linux)
一.修改配置文件 查询路径 find / -name my.cnf 修改文件 vi my.cnf [mysqld]下面加上skip-grant-tables 二.登录数据库 重启mysql servi ...
- 【整理】iview Tree数据格式问题,无限递归树处理数据
iview Tree数据格式问题,无限递归树处理数据 https://juejin.im/post/5b51a8a4e51d455d6825be20
- axios 两种异步模式,代理模式 和 异步模式
axios 两种异步模式,代理模式 和 异步模式