zoukankan      html  css  js  c++  java
  • HAUT校赛 魔法宝石 暴力

    问题 C: 魔法宝石

    时间限制: 2 秒  内存限制: 64 MB
    提交: 505  解决: 149
    提交 状态 

    题目描述

    小s想要创造n种魔法宝石。小s可以用ai的魔力值创造一棵第i种魔法宝石,或是使用两个宝石合成另一种宝石(不消耗魔力值)。请你帮小s算出合成某种宝石的所需的最小花费。

    输入

    第一行为数据组数T(1≤T≤3)。
    对于每组数据,首先一行为n,m(1≤n,m≤10^5)。分别表示魔法宝石种类数和合成魔法的数量。
    之后一行n个数表示a1到an。(1≤ai≤10^9)。a_i表示合成第i种宝石所需的魔力值。
    之后n行,每行三个数a,b,c(1≤a,b,cn),表示一个第a种宝石和第b种宝石,可以合成一个第c种宝石。

    输出

    每组数据输出一行n个数,其中第i个数表示合成第i种宝石的魔力值最小花费。

    样例输入

    13 11 1 101 2 3

    样例输出

    1 1 2

    显然,每次更新最值小值就可以了,我把数据开到了1e2,这个应该满足上界了。

    #include <map>
    #include <set>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    #include <iostream>
    #include <stack>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <cstdlib>
    //#include <bits/stdc++.h>
    //#define LOACL
    #define space " "
    #define lson o<<1, l, mid
    #define rson o<<1|1, mid+1, r
    #define ll o<<1
    #define rr o<<1|1
    using namespace std;
    typedef long long LL;
    //typedef __int64 Int;
    typedef pair<int, int> PAI;
    const int INF = 0x3f3f3f3f;
    const double ESP = 1e-5;
    const double PI = acos(-1.0);
    const int MOD = 1e9 + 7;
    const int MAXN = 1e5 + 10;
    const int MAX = 3000;
    int ar[MAXN];
    struct node 
    {
        int a, b, c;
    }data[MAXN];
    int main(int argc, char const *argv[])
    {
        int T, N, M;
        scanf("%d", &T);
        while (T--) {
            scanf("%d%d", &N, &M);
            for (int i = 1; i <= N; i++) scanf("%d", &ar[i]);
            for (int i = 0; i < M; i++) {
                int a, b, c;
                scanf("%d%d%d", &a, &b, &c);
                data[i].a = a;
                data[i].b = b;
                data[i].c = c;
                ar[c] = min(ar[c], ar[a] + ar[b]);
            }
            for (int i = 0; i < 1e2; i++) {
                for (int j = 0; j < M; j++) {
                    int ta = data[j].a;
                    int tb = data[j].b;
                    int tc = data[j].c;
                    ar[tc] = min(ar[tc], ar[ta] + ar[tb]);
                }
            }
            printf("%d", ar[1]);
            for (int i = 2; i <= N; i++) {
                printf(" %d", ar[i]);
            }
            printf("
    ");
        }
        return 0;
    }
    
    

     

  • 相关阅读:
    【IntelliJ Idea】git commit 显示 Local Changes
    【Nginx】worker_connections设置
    【Java Web开发学习】DataSource获取的Connection要不要关闭
    【Redis】LOADING Redis is loading the dataset in memory
    shell 常用
    insert DB
    mq部署
    systemctl启动方式
    mq启动报错ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! !!
    redis哨兵centos7开机自启动
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770740.html
Copyright © 2011-2022 走看看