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 ...
随机推荐
- size_t与size_type区别
size() 标准库string里面有个函数size,用来返回字符串中的字符个数,具体用法如下: string st("The expense of spirit\n");cou ...
- 微信小程序资料收集(一)
1.微信小程序用户授权 https://blog.csdn.net/qq_34827048/article/details/77990510 https://blog.csdn.net/qq_3361 ...
- Python实现两已知排好序的列表合并成一个排好序的列表
#方法0.5--- lst1 = [1, 3, 7, 9, 12] lst2 = [4, 8, 9, 13, 15, 19] def merge(a, b): c = [] h = j = 0 whi ...
- bzoj1878 [SDOI2009]HH的项链【莫队】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1878 以每个询问左端点所属的块的编号为第一关键字,右端点本身为第二关键字,排序,然后保利扫描 ...
- Java项目的命名规则
Java类的命名规范如下: 1. 项目名全部小写 2. 包名全部小写 3. 类名首字母大写,如果类名由多个单词组成,每个单词的首字母都要大写. 如:public class MyFirstClass{ ...
- Android利用tcpdump抓包,用wireshark分析包。
1.前言 主要介绍在android手机上如何利用tcpdump抓包,用wireshark分析包. android tcpdump官网: http://www.androidtcpdump.com/ t ...
- Appium + Python自动化 - 元素定位uiautomatorviewer
元素定位主要介绍如何使用uiautiomatorviewer,通过定位到页面上的元素,然后进行相应的点击等操作.uiautiomatorviewer是android-sdk自带的一个元素定位工具,非常 ...
- rhel 6.5--samba
配置匿名共享: 服务端: [root@master ~]# yum install -y samba 或者 [root@master ~]# yum groupinstall -y "CIF ...
- dataTables去掉搜索框和每页多少条框体,解决Cannot reinitialise DataTable问题
$('#example').DataTable({ searching:false, //去掉搜索框 bLengthChange:false,//去掉每页多少条框体 "language&qu ...
- (转)编码剖析@Resource注解的实现原理
http://blog.csdn.net/yerenyuan_pku/article/details/52860046 上文我们已经学会使用@Resource注解注入属性.学是学会了,但也仅限于会使用 ...