首页 > 其他 > 详细

BZOJ 3943 Usaco2015 Feb SuperBull Prim

时间:2015-04-09 17:27:58      阅读:360      评论:0      收藏:0      [点我收藏+]

题目大意

异或Prim。

思路

没开long long WA了一次你敢信?

CODE

#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAX 2010
#define INF 0x3f3f3f3f
using namespace std;

int points;
int src[MAX];

int f[MAX];
bool v[MAX];

long long Prim()
{
    long long re = 0;
    for(int i = 1; i <= points; ++i) {
        int max_length = 0, p = 1;
        for(int j = 1; j <= points; ++j)
            if(!v[j] && f[j] > max_length)
                max_length = f[j], p = j;
        v[p] = true;
        re += max_length;
        for(int j = 1; j <= points; ++j)
            if(!v[j])
                f[j] = max(f[j], src[p]^src[j]);
    }
    return re;
}

int main()
{
    cin >> points;
    for(int i = 1; i <= points; ++i)
        scanf("%d", &src[i]);
    cout << Prim() << endl;
    return 0;
}

BZOJ 3943 Usaco2015 Feb SuperBull Prim

原文:http://blog.csdn.net/jiangyuze831/article/details/44961687

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!