NC232573. NuclearReactor
描述
输入描述
一个六行九列的网格,每个网格包含一个字符表示该网格内的组件情况。
“#”代表空,“U”表示铀燃料棒,“D”表示双联燃料棒,“Q”表示四联燃料棒,“N”表示中子反射板,“A”表示高级的A类散热片,“a”表示普通的A类散热片,“B”表示高级的B类散热片,“b”表示普通的B类散热片,“C”表示C类散热片。
输出描述
1、是否会发生熔毁,如果会熔毁,则在第一行输出Boom!,若可以安全运行一个周期,则给出运行结束时核反应堆的热量(保留两位小数)。
2、熔毁时或运行结束时的总发电量。
示例1
输入:
BBNNCaCaN NDQBbUa#N AQAQQNNU# AUAQ#QAQN QDNCNNUCB QQNUbUaCa
输出:
Boom! 4550
示例2
输入:
######### ######### ##ADA#### ###a##### ######### #########
输出:
Boom! 100020
示例3
输入:
######### ###UaU### ######### ######### ######### #########
输出:
Boom! 17520
C++(g++ 7.5.0) 解法, 执行用时: 10ms, 内存消耗: 456K, 提交时间: 2023-01-13 11:51:57
#include <iostream> #include <cstring> #include <algorithm> #include <iomanip> using namespace std; const int MAXX = 6 + 2; const int MAXY = 9 + 2; const int MAXTemp = 10000; const int MAXTime = 20000; const int MAXVentTemp = 1000; const int dx[4] {0, -1, 0, 1}; const int dy[4] {-1, 0, 1, 0}; char map[MAXX][MAXY]; long long mapRodHeat[MAXX][MAXY]; double mapVentHeat[MAXX][MAXY]; long long mapVentANum[MAXX][MAXY]; long long ventBNum, ventbNum; long long mapVentCNum[MAXX][MAXY]; int main() { memset(map, 0, sizeof(map)); for (int i = 1; i < MAXX - 1; ++i) { for (int j = 1; j < MAXY - 1; ++j) { map[i][j] = getchar(); } getchar(); } long long answ = 0; memset(mapRodHeat, 0, sizeof(mapRodHeat)); memset(mapVentANum, 0, sizeof(mapVentANum)); memset(mapVentCNum, 0, sizeof(mapVentCNum)); for (int i = 1; i < MAXX - 1; ++i) { for (int j = 1; j < MAXY - 1; ++j) { if (map[i][j] == 'U' || map[i][j] == 'D' || map[i][j] == 'Q') { int n = 0, m = 1, eta = 1; if (map[i][j] == 'D') { m = 2; eta = 2; } else if (map[i][j] == 'Q') { m = 4; eta = 3; } for (int di = 0; di < 4; ++di) { if (map[i + dx[di]][j + dy[di]] == 'U') { n += 1; } else if (map[i + dx[di]][j + dy[di]] == 'D') { n += 2; } else if (map[i + dx[di]][j + dy[di]] == 'Q') { n += 4; } else if (map[i + dx[di]][j + dy[di]] == 'N') { n += m; } } answ += 5 * m * (eta + n); mapRodHeat[i][j] = 2 * m * (eta + n) * (eta + n + 1); } else if (map[i][j] == 'A' || map[i][j] == 'a') { for (int di = 0; di < 4; ++di) { ++mapVentANum[i + dx[di]][j + dy[di]]; } } else if (map[i][j] == 'B') { ++ventBNum; } else if (map[i][j] == 'b') { ++ventbNum; } else if (map[i][j] == 'C') { for (int di = 0; di < 4; ++di) { ++mapVentCNum[i + dx[di]][j + dy[di]]; } } } } long long ansW = 0; double ansQ = 0; bool isBoom = 0; memset(mapVentHeat, 0, sizeof(mapVentHeat)); for (int k = 0; k < MAXTime; ++k) { ansW += answ; ansQ = max((double)0, ansQ - (5 * ventbNum)); double heatToVentB = ansQ; if (ventBNum != 0) ansQ = 0; for (int i = 1; i < MAXX - 1; ++i) { for (int j = 1; j < MAXY - 1; ++j) { if (mapRodHeat[i][j] != 0 && mapVentANum[i][j] == 0) { ansQ += mapRodHeat[i][j]; } else if (mapVentHeat[i][j] > MAXVentTemp) continue; else if (map[i][j] == 'A') { for (int di = 0; di < 4; ++di) { if (mapRodHeat[i + dx[di]][j + dy[di]] != 0) { mapVentHeat[i][j] += min((double)12, (double)mapRodHeat[i + dx[di]][j + dy[di]] / mapVentANum[i + dx[di]][j + dy[di]]); ansQ += max((double)0, (double)mapRodHeat[i + dx[di]][j + dy[di]] / mapVentANum[i + dx[di]][j + dy[di]] - 12); } } } else if (map[i][j] == 'a') { for (int di = 0; di < 4; ++di) { if (mapRodHeat[i + dx[di]][j + dy[di]] != 0) { mapVentHeat[i][j] += min((double)6, (double)mapRodHeat[i + dx[di]][j + dy[di]] / mapVentANum[i + dx[di]][j + dy[di]]); ansQ += max((double)0, (double)mapRodHeat[i + dx[di]][j + dy[di]] / mapVentANum[i + dx[di]][j + dy[di]] - 6); } } } else if (map[i][j] == 'B') { mapVentHeat[i][j] += min((double)32, (double)heatToVentB / ventBNum); ansQ += max((double)0, (double)heatToVentB / ventBNum - 32); } } } for (int i = 1; i < MAXX - 1; ++i) { for (int j = 1; j < MAXY - 1; ++j) { if (mapVentHeat[i][j] > MAXVentTemp + 10000) continue; else if (map[i][j] == 'A') { mapVentHeat[i][j] = max((double)0, mapVentHeat[i][j] - 12 - 4 * mapVentCNum[i][j]); if (mapVentHeat[i][j] > MAXVentTemp) { mapVentHeat[i][j] += 10000; for (int di = 0; di < 4; ++di) { --mapVentANum[i + dx[di]][j + dy[di]]; } } } else if (map[i][j] == 'a') { mapVentHeat[i][j] = max((double)0, mapVentHeat[i][j] - 6 - 4 * mapVentCNum[i][j]); if (mapVentHeat[i][j] > MAXVentTemp) { mapVentHeat[i][j] += 10000; for (int di = 0; di < 4; ++di) { --mapVentANum[i + dx[di]][j + dy[di]]; } } } else if (map[i][j] == 'B') { mapVentHeat[i][j] = max((double)0, mapVentHeat[i][j] - 20 - 4 * mapVentCNum[i][j]); if (mapVentHeat[i][j] > MAXVentTemp) { mapVentHeat[i][j] += 10000; --ventBNum; } } } } if (ansQ > MAXTemp) { isBoom = 1; break; } } if (isBoom) cout << "Boom!"; else printf("%.2lf", ansQ); cout << endl << ansW << endl; return 0; }
C++ 解法, 执行用时: 9ms, 内存消耗: 444K, 提交时间: 2022-01-16 18:01:53
#include<bits/stdc++.h> using namespace std; vector<pair<int,int> >d={{0,1},{0,-1},{1,0},{-1,0}}; int i,j,k,n,m,t,res,dian,cb1,cb2; int f[66][66],zz[66][66],w[66][66]; double q[66][66],g[66][66],tot; double re; #define rep for(i=1;i<=6;i++)for(j=1;j<=9;j++) string s="#UDQNAaBbC"; int main() { rep{ char c=getchar(); for(k=0;k<=9;k++)if(c==s[k]){f[i][j]=k,cb2+=(k==7),cb1+=(k==8);break;} if(k>9)j--; } rep if(f[i][j]>=1&&f[i][j]<=3){ for(auto [dx,dy]:d){ dx+=i;dy+=j; if(f[dx][dy]==4)zz[i][j]+=(1<<(f[i][j]-1)); else zz[dx][dy]+=(1<<(f[i][j]-1)); } } rep if(f[i][j]>=1&&f[i][j]<=3){ w[i][j]=5*(1<<(f[i][j]-1))*(zz[i][j]+f[i][j]); q[i][j]=2*(1<<(f[i][j]-1))*(zz[i][j]+f[i][j])*(1+zz[i][j]+f[i][j]); dian+=w[i][j]; } for(t=1;t<=20000;t++){ re=max(0.0,re-cb1*5); double tmp=min(32.0,re/max(cb2,1)); rep{ if(f[i][j]==7)g[i][j]+=tmp,re-=tmp,g[i][j]=max(0.0,g[i][j]-20); } rep{ k=0;tot=0; if(f[i][j]>=1&&f[i][j]<=3){ for(auto [dx,dy]:d){ dx+=i;dy+=j; if(f[dx][dy]==5||f[dx][dy]==6)k++; } if(!k){re+=q[i][j];continue;} tot=q[i][j]/k; for(auto [dx,dy]:d){ dx+=i;dy+=j; if(f[dx][dy]==5)g[dx][dy]+=min(12.0,tot),re+=max(0.0,tot-12.0); if(f[dx][dy]==6)g[dx][dy]+=min(6.0,tot),re+=max(0.0,tot-6.0); } } } rep{ if(f[i][j]==5)g[i][j]=max(0.0,g[i][j]-12); if(f[i][j]==6)g[i][j]=max(0.0,g[i][j]-6); if(f[i][j]==9)for(auto [dx,dy]:d){ dx+=i;dy+=j; g[dx][dy]=max(0.0,g[dx][dy]-4); } } rep{ if(f[i][j]>=5&&f[i][j]<=6&&g[i][j]>1000)f[i][j]=0; if(f[i][j]==7&&g[i][j]>1000)f[i][j]=0,cb2--; } if(re>10000)return printf("Boom!\n%d",t*dian),0; } printf("%.2lf\n%d",re,dian*20000); }