Minimum’s Revenge(hdu 5922)

这题是2016CCPC东北省赛A题,题目要求最小生成树的最小权值和。这题在vj上看到的,通过率贼高,心想应该不难,签到题。试着在草稿纸上画画,初步发现拿1和其他点连线构成的最小生成树的权值和最小,即贪心。有时候真的不能把题目想复杂,实践才能出真知!!!

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,k=0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        printf("Case #%d: %lld\n",++k,((long long)n+2)*(n-1)/2);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41061455/article/details/80469760
今日推荐