Fzu problem 2233 ~aptx4869 (and check set + sort)

Source: Internet
Author: User

Topic Links:

Fzu problem 2233 ~aptx4869

Title Description:

To a n*n matrix, (I, j) represents the value of the influence of the material of type I and J, which represents the influence value between the N items. When the n items are divided into two parts, each part of the internal material will not affect each other, but the different parts of the material will affect each other. Q How does partitioning make the minimum impact value between two parts of the material maximum?

Problem Solving Ideas:

Material inside does not affect, then only need to put the impact of small items in the same part, so use the structure to save the effect between the value of the items, and then sort, the impact of small items with and check set in a set, when the set equals 2, the Traverse to the item in different sets of influence value is ans.

1#include <cstdio>2#include <queue>3#include <stack>4#include <cmath>5#include <cstring>6#include <iostream>7#include <algorithm>8 using namespacestd;9 Ten #defineLson 2*root One #defineRson 2*root+1 A typedef __int64 LL; - ConstLL mod =1000000007; - ConstLL inf= 1e9+7; the Const intMAXN =810; -  - structnode - { +     intx, y, Z; -}a[maxn*MAXN]; + intVIS[MAXN]; A BOOLCMP (Node A, Node B) at { -     returnA.z <b.z; - } -  - voidInit () - { in      for(intI=0; i<maxn; i++) -Vis[i] =i; to } +  - intFind (intx) the { *     if(Vis[x]! =x) $VIS[X] =find (Vis[x]);Panax Notoginseng     returnVis[x]; - } the intMain () + { A     intN; the      while(SCANF ("%d", &n)! =EOF) +     { - init (); $         intm =0; $          for(intI=0; i<n; i++) -              for(intj=0; j<n; J + +) -             { thescanf ("%d", &a[m].z); -                 if(I <j)Wuyi                  { thea[m].x =i; -A[m ++].y =J; Wu                  } -             } AboutSort (A, A +m, CMP); $  -         intAns = INF, cnt =N; -          for(intI=0; i<m; i++) -         { A             intx =find (a[i].x); +             inty =find (A[I].Y); the  -             if(x = =y) $                 Continue; the  the             if(x! = y && cnt >2) the             { theVIS[X] =y; -CNT--; in             } the             Else theAns =min (ans, a[i].z); About  the             if(ans! =INF) the                  Break; the         } +  -printf ("%d\n", ans); the     }Bayi     return 0; the } the  - /* - 4 the -1 the 100-1 the 400-1 the 600-1 - */

Fzu problem 2233 ~aptx4869 (and check set + sort)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.