Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

prim水过

Posted by LEGION at 2014-07-27 16:57:34 on Problem 1789
RE一次,居然是二维字符数组行列打反了。。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
int n;
int arr[2117][2117];
int low[2117], vis[2117];
char item[2117][10];

int prim(){
    int i, j, k, sum = 0, pos, minc = inf;
    vis[1] = 1, pos = 1;
    for(i = 1; i <= n; i++){
        if(i != pos){
            low[i] = arr[pos][i];
        }
    }
    for(i = 2; i <= n; i++){
        minc = inf;
        for(j = 1; j <= n; j++){
            if(vis[j] != 1 && low[j] < minc){
                minc = low[j];
                pos = j;
            }
        }
        vis[pos] = 1;
        sum += minc;
        for(j = 1; j <= n; j++){
            if(vis[j] != 1 && arr[pos][j] < low[j]){
                low[j] = arr[pos][j];
            }
        }
    }
return sum;
}

int main(){
    int i, j, k;
    while(scanf("%d", &n) != EOF && n != 0){
        memset(arr, 0, sizeof(arr));
        memset(item, 0, sizeof(item));
        memset(low, 0, sizeof(low));
        memset(vis, 0, sizeof(vis));
        for(i = 1; i <= n; i++){
            scanf("%s", item[i]);
        }
        for(i = 1; i <= n; i++){
            for(j = i; j <= n; j++){
                for(k = 0; k < 7; k++){
                    if(item[i][k] != item[j][k]){
                        arr[i][j]++;
                        arr[j][i]++;
                    }
                }
            }
        }
//        for(i = 1; i <= n; i++){
//            printf("%s\n", item[i]);
//        }
//        for(i = 1; i <= n; i++){
//            for(j = 1; j <= n; j++){
//                printf("%d ", arr[i][j]);
//            }
//            printf("\n");
//        }
        printf("The highest possible quality is 1/%d.\n", prim());
    }
return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator