题解 | 晶体能量阱储量计算

晶体能量阱储量计算

https://www.nowcoder.com/practice/14c8232d64da4ba2aecee7621e06f4f7

#include <bits/stdc++.h>
using namespace std;

const int N = 305;
const int inf = 0x3f3f3f3f;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int m, n, e[N][N];
int edx, edy, dist[N][N];
bool st[N][N];

struct node {
    int dis, x, y;
    bool operator < (const node & t) const {
		return this -> dis > t.dis;
	}
};

void dij() {
    memset(dist, 0x3f, sizeof dist);
    priority_queue<node>q;
    for(int i=1; i<=m; i++) q.push({0,0,i}), q.push({0,n+1,i});
    for(int i=1; i<=n; i++) q.push({0,i,0}), q.push({0,i,m+1});
    while( q.size() ) {
        auto [dis, nowx, nowy] = q.top();
        q.pop();
        // cout << "x = " << nowx << " y = " << nowy << endl;
        if(st[nowx][nowy]) continue;
        st[nowx][nowy] = true;
        for(int i=0; i<4; i++) {
            int tx = nowx + dx[i], ty = nowy + dy[i];
            if(tx<1||tx>n||ty<1||ty>m) continue;
            int d = max(dis, e[tx][ty]);
            if(dist[tx][ty] > d) {
                dist[tx][ty] = d;
                q.push({d, tx, ty});
            }
        }
    }
}

int main() {
    ios :: sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> m >> n;
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            cin >> e[i][j];
        }
    }
    dij();
    int res = 0;
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            res += max(0, dist[i][j] - e[i][j]); // dist(i,j)一定大于等于e(i,j)可以不用max
            // cout << "i = " << i << " j = " << j << " dis = " << dist[i][j] << endl;
        }
    }
    cout << res;
    return 0;
}
// 64 位输出请用 printf("%lld")

观察到能使用dijkstra从终点即外面一圈的点出发计算每个点的逃逸势能

全部评论

相关推荐

行云流水1971:这份实习简历的优化建议: 结构清晰化:拆分 “校园经历”“实习经历” 板块(当前内容混杂),按 “实习→校园→技能” 逻辑排版,求职意向明确为具体岗位(如 “市场 / 运营实习生”)。 经历具象化:现有描述偏流程,需补充 “动作 + 数据”,比如校园活动 “负责宣传” 可加 “运营公众号发布 5 篇推文,阅读量超 2000+,带动 300 + 人参与”;实习内容补充 “协助完成 XX 任务,效率提升 X%”。 岗位匹配度:锚定目标岗位能力,比如申请运营岗,突出 “内容编辑、活动执行” 相关动作;申请市场岗,强化 “资源对接、数据统计” 细节。 信息精简:删减冗余表述(如重复的 “负责”),用短句分点,比如 “策划校园招聘会:联系 10 + 企业,组织 200 + 学生参与,到场率达 85%”。 技能落地:将 “Office、PS” 绑定经历,比如 “用 Excel 整理活动数据,输出 3 份分析表;用 PS 设计 2 张活动海报”,避免技能单独罗列。 优化后需强化 “经历 - 能力 - 岗位需求” 的关联,让实习 / 校园经历的价值更直观。 若需要进一步优化服务,私信
实习,投递多份简历没人回...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务