QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685372 | #3565. Beer Pressure | fatchuan | 0 | 0ms | 0kb | C++20 | 2.1kb | 2024-10-28 19:05:27 | 2024-10-28 19:05:27 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int inf = 1e9 + 7;
const int maxn = 8;
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 = 0;
LL tmp = u;
for(int i = n; i > 0; i--){//将long long 还原成数组
temp[i] = int(tmp%100LL);
tmp /= 100LL;
tot += temp[i];
}
if(tot == k){//已经投完票, 选出票数最多的将概率分享。
int winner[maxn] = {0};
int Max = temp[1];
int chosen = 0;
winner[chosen++] = 1;
for(int i = 2; i <= n; i++){
if(Max == temp[i])winner[chosen++] = i;
else if(temp[i] > Max){
Max = temp[i];
chosen = 0;
winner[chosen++] = i;
}
}
for(int i = 0; i < chosen; i++)
possible[winner[i]] += pp/(double)chosen;
}
else{
for(int i = n; i >= 1; 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,0,sizeof(possible));
LL u = 0;
for(int i = 0; i < n; i++){int t;scanf("%d", &t); u *= 100LL, u += t;}//映射成一个10位long long
bfs(u);
for(int i = 1;i <= n; i++) printf("pub %d: %.2f %%\n",i, possible[i]);
}
}
詳細信息
Pretests
Final Tests
Test #1:
score: 0
Runtime Error
input:
3 7 3 1 1 1 1 1 1 50 1 2 2 1 1 2 50 1 1 2 50 1 2 3 3 1 1 1 3 50 1 1 1 3 50 1 1 2 4 4 1 1 1 1 4 50 1 1 1 1 4 50 1 1 1 2 5 5 1 1 1 1 1 5 50 1 1 1 1 1 5 50 1 1 1 1 2 4 49 2 10 4 2 4 36 4 3 2 4 3 27 2 6 10 1 16 9 3 43 3 6 3 2 28 6 5 3 37 5 7 9 1 44 1 5 44 8 1 9 8 7 3 46 8 2 6 4 28 4 10 4 9 4 50 1 8 6 4 ...