• JOJ 1343 城际公路网


    WA

    1. 函数体内用的是从 1 开始的数组, 而接受的 input 是从 0 开始的, 又是好2的错误

    代码

    #include <iostream>
    #include <stdio.h>
    #include <memory.h>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <deque>
    #include <cstring>
    #define MIN(x,y) (x)<(y)?(x):(y)
    using namespace std;
    
    int matrix[100][100];
    
    int totalCost(int n) {
    	int sum = 0;
    
    	for(int i = 1; i <= n; i ++)  {
    		for(int j = 1; j <= n; j ++)  {
    			sum += matrix[i][j];
    		}
    	}
    	return sum/2;
    }
    
    int updateMatrix(int n, int from, int to, int newCost)  {
    	matrix[from][to] = newCost;
    	matrix[to][from] = newCost;
    
    	for(int i = 1; i <= n; i ++)  {
    		for(int j = 1; j <= n; j ++)  {
    			int dist1 = matrix[i][from] + matrix[to][j] + newCost;
    			int dist2 = matrix[i][to] + matrix[from][j] + newCost;
    			matrix[i][j] = min(matrix[i][j], dist1);
    			matrix[i][j] = min(matrix[i][j], dist2);
    
    			printf("matrix[%d][%d] = %d
    ",i, j, matrix[i][j]);
    		}
    	}
    	return totalCost(n);
    }
    
    int main() {
    	freopen("C:\Users\vincent\Dropbox\workplacce\joj\test.txt", "r", stdin);
    	
    	int n;
    	while(scanf("%d", &n) != EOF)  {
    		for(int i = 1; i <= n; i ++)  {
    			for(int j = 1; j <= n; j ++)  {
    				scanf("%d", &matrix[i][j]);
    			}
    		}
    		int m;
    		scanf("%d", &m);
    		for(int i = 0; i < m; i ++)  {
    			int from, to, cost;
    			scanf("%d%d%d", &from, &to, &cost);
    			int res = updateMatrix(n, from, to, cost);
    			printf("%d
    ", res);
    		}
    
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Django(60)Django内置User模型源码分析及自定义User
    Django(59)验证和授权
    Django(58)viewsets视图集详解
    Django(57)Generic类视图
    正则表达式
    JMeter之检查点(JSON断言)
    JMeter之检查点(响应断言)
    JMeter之参数化(一)
    JMeter之一个简单的性能测试
    JMeter基础
  • 原文地址:https://www.cnblogs.com/zhouzhuo/p/3679294.html
Copyright © 2020-2023  润新知