zoukankan      html  css  js  c++  java
  • 计算机学院大学生程序设计竞赛(2015’12)Happy Value

    Happy Value

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1337    Accepted Submission(s): 392


    Problem Description
    In an apartment, there are N residents. The Internet Service Provider (ISP) wants to connect these residents with N – 1 cables. 
    However, the friendships of the residents are different. There is a “Happy Value” indicating the degrees of a pair of residents. The higher “Happy Value” is, the friendlier a pair of residents is. So the ISP wants to choose a connecting plan to make the highest sum of “Happy Values”.
     

    Input
    There are multiple test cases. Please process to end of file.
    For each case, the first line contains only one integer N (2<=N<=100), indicating the number of the residents.
    Then N lines follow. Each line contains N integers. Each integer Hij(0<=Hij<=10000) in ith row and jth column indicates that ith resident have a “Happy Value” Hijwith jth resident. And Hij(i!=j) is equal to Hji. Hij(i=j) is always 0.
     

    Output
    For each case, please output the answer in one line.
     

    Sample Input
    2 0 1 1 0 3 0 1 5 1 0 3 5 3 0
     

    Sample Output
    1 8
     

    总是望着曾经的空间发呆,那些说好不分开的朋友不在了,转身,陌路。 熟悉的,安静了, 安静的,离开了, 离开的,陌生了, 陌生的,消失了, 消失的,陌路了。快哭了

    #include <stdio.h>
    #include <string.h>
    #define MaxInt 9999999
    #define N 110
    int map[N][N],low[N],visited[N],n;
    int prim()
    {
        int i,j,pos=1,min,result=0;
        memset(visited,0,sizeof(visited));
        visited[1]=1;
        for(i=2; i<=n; i++)
           low[i]=map[pos][i];
        for(i=1; i<n; i++)
        {
            min=MaxInt;
            for(j=1; j<=n; j++)
                if(visited[j]==0&&min>low[j])
                {
                    min=low[j];
                    pos=j;
                }
            result+=min;
            visited[pos]=1;
            for(j=1; j<=n; j++)
                if(visited[j]==0&&low[j]>map[pos][j])
                    low[j]=map[pos][j];
        }
        return result;
    }
    int main()
    {
        int i,v,j,ans;
        while(scanf("%d",&n)!=EOF)
        {
            memset(map,MaxInt,sizeof(map));
            for(i=1; i<=n; i++)
                for(j=1; j<=n; j++)
                {
                    scanf("%d",&v);
                    map[i][j]=-v;
                }
            ans=-1*prim();
            printf("%d
    ",ans);
        }
        return 0;
    }
    

    @执念  "@☆但求“❤”安★ 下次我们做的一定会更好。。。。吐舌头

    为什么这次的题目是英文的。。。。QAQ...哭

    ------------------- 这是千千的个人网站哦! https://www.dreamwings.cn -------------------
  • 相关阅读:
    将您的基于 Accelerator 的 SAP Commerce Cloud Storefront 迁移到 Spartacus Storefront
    SAP S/4HANA: 一条代码线,许多种选择
    windows系统中远程登录ubuntu18服务器的桌面
    C语言格式控制符/占位符
    C语言变量声明和定义
    C语言数据类型 / 变量类型
    C语言 Hello World
    C语言代码注释
    变量命名 – 匈利亚命名法则
    设置 Visual Studio 字体/背景/行号
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989698.html
Copyright © 2011-2022 走看看