题意:

给定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的更多相关文章

  1. 2012-2013 Northwestern European Regional Contest (NWERC 2012)

    B - Beer Pressure \(dp(t, p_1, p_2, p_3, p_4)\)表示总人数为\(t\),\(p_i\)对应酒吧投票人数的概率. 使用滚动数组优化掉一维空间. 总的时间复杂 ...

  2. Reporting Service 告警"w WARN: Thread pool pressure. Using current thread for a work item"

    如果Reporting Service偶尔出现不可访问或访问出错情况,这种情况一般没有做监控的话,很难捕捉到.出现这种问题,最好检查Reporting Service的日志文件. 今天早上就遇到这样一 ...

  3. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  4. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  5. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  6. LinuxMM--Memory Pressure

    Memory pressure定义在操作系统中,用户分配.文件缓存.网卡包缓冲区等等都会消耗内存.一旦出现内存紧张就会导致memory pressure.引发当某个任务需要请求内存时就有可能引发mem ...

  7. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  8. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  9. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

随机推荐

  1. scanf()和scanf_s()

    在最初的C语言中,原版的输入就是scanf("<格式化字符串>",<地址表>) ANSI C中没有scanf_s(),只有scanf(),scanf()在读 ...

  2. the little schemer 笔记(0)

    the little schemer 笔记 Z.X.L 2012年08月13日 五项规则 car的规则car只对非空列表有定义. cdr的规则cdr只对非空列表有定义.任何非空列表的cdr是另外一个列 ...

  3. C++面向对象程序设计举例

    [例8.1]最简单的例子. #include <iostream> using namespace std; class Time //定义Time类 { public : //数据成员为 ...

  4. Educational Codeforces Round 18 A

    Description There are n cities situated along the main road of Berland. Cities are represented by th ...

  5. Vue不兼容IE8原因以及Object.defineProperty详解

    Vue不兼容IE8原因以及Object.defineProperty详解 原因概述: Vue.js使用了IE8不能模拟的ECMAScript5特性. Vue.js支持所有兼容ES5的浏览器. Vue将 ...

  6. Hadoop工作流--JobControl(五)

    不多说,直接上干货! 这只是部分,做个引子. 未完,待续!

  7. .net core区域设置方式

    在Startup中配置 默认路由是这个,并不包含区域路由 routes.MapRoute( name: "default", template: "{controller ...

  8. qconbeijing2017

    http://2017.qconbeijing.com/schedule 第一天 (2017年4月16日/星期日)   签到 专题 主题演讲 快速进化的容器生态 微服务与 DevOps 最佳实践(厂商 ...

  9. P2142 高精度减法

    题目描述 高精度减法 输入输出格式 输入格式: 两个整数a,b(第二个可能比第一个大) 输出格式: 结果(是负数要输出负号) 输入输出样例 输入样例#1: 2 1 输出样例#1: 1 说明 20%数据 ...

  10. (5)《Head First HTML与CSS》学习笔记---布局与定位

    层叠与CSS的权重判断 1.要理解层叠,除了前面的内容外还差最后一个知识点.你已经知道如何使用多个样式表来更好地组织你的样式,或者支持不同类型的设备.不过实际上用户访问你的页面时还有另外一些样式表. ...