zoj 2080 Chess War

zoj 2080 Chess War,第1张

zoj 2080 Chess War
#include <cstdio>#include <algorithm>using namespace std;const int INF = 1 << 20;const int Dir[8][2] = {    {1, 2},    {1, -2},    {-1, -2},    {-1, 2},    {2, 1},    {2, -1},    {-2, -1},    {-2, 1}};bool m[8][8];int d[8][8];int mp[8][8];int main(void){    int re;    int x, y, xx, yy, mind, ans;    scanf("%d", &re);    while(re--) {        for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++)     scanf("%d", &mp[i][j]);        ans = 0;        fill(m[0], m[8], false);        fill(d[0], d[8], INF - 1);        d[0][0] = 0;        for (int k = 0; k < 64; k++) { x = y = -1; mind = INF; for (int i = 0; i < 8; i++)     for (int j = 0; j < 8; j++)         if(!m[i][j] && d[i][j] < mind) {  mind = d[i][j];  x = i;  y = j;         } m[x][y] = true; ans += mind; for (int i = 0; i < 8; i++) {     xx = x + Dir[i][0];     yy = y + Dir[i][1];     if(xx < 0 || xx >= 8 || yy < 0 || yy >= 8)         continue;     d[xx][yy] = min(d[xx][yy], mp[x][y] + mp[xx][yy]); }        }        printf("%dn", ans);    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4898941.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存