Zoj 1586 QS Network, zoj1586qsnetwork

Source: Internet
Author: User

Zoj 1586 QS Network, zoj1586qsnetwork

Link: zoj 1586

If you want to connect two QS to the Internet, you have to buy an adapter for both of them,

Minimum fee for connecting all QS to the Internet

Analysis: in addition to the edge weight, the vertex also has the right value. Therefore, to obtain the minimum value, you must calculate the weight and

# Include <cstdio> # include <algorithm> using namespace std; int f [1010], n, m; struct stu {int a, B, c;} t [500100]; int cmp (struct stu x, struct stu y) {return x. c <y. c;} int find (int x) {if (x! = F [x]) f [x] = find (f [x]); return f [x];} int krus () {int I, k = 0, s = 0, x, y; for (I = 1; I <m; I ++) {x = find (t [I]. a); y = find (t [I]. b); if (x! = Y) {s + = t [I]. c; k ++; if (k = N-1) break; f [x] = y;} return s;} int main () {int T, I, j, a [1010], c, s = 0; scanf ("% d", & T); while (T --) {scanf ("% d", & n ); for (I = 1; I <= n; I ++) {f [I] = I; scanf ("% d", & a [I]);} m = 1; for (I = 1; I <= n; I ++) for (j = 1; j <= n; j ++) {scanf ("% d", & c); if (j <I) {t [m]. a = I; t [m]. B = j; t [m ++]. c = c + a [I] + a [j]; // calculate the sum of edge and vertex weights} sort (t + 1, t + m, cmp ); s = krus (); printf ("% d \ n", s) ;}return 0 ;}





A typical DP question is best created

Zju search dp question summary favorites
|
Search:
50 search questions

1002 Fire Net-OK
1004 Anagrams by Stack-OK
1005 Jugs-OK
1008 Gnome Tetravex-OK but not ac
1091 Knight Moves-OK
1101 Gamblers-OK
1204 Additive equations
1221 Risk
1230 Legendary Pokemon
1249 Pushing Boxes
1364 Machine Schedule
1368 BOAT
1406 Jungle Roads --- OK

1411 Anniversary
1453 Surround the Trees convex hull
1516 Uncle Tom's Inherited Land --- OK
1525 Air Raid may be more suitable for Network Flow Calculation
1586 QS Network
1602 Multiplication Puzzle dp
1649 Rescue
1671 Walking Ant ---- OK

1711 Sum It Up dfs ---- OK
1901 A Star not a Tree? The search may be a bit controversial (no matter)
1940 Dungeon Master ---- OK
2100 Seeding ---- OK
2110 Tempter of the Bone
2140 Ball
(27)
The above questions may be relatively simple. Just practice basic algorithms.
========================================================== ========================================================
The following questions are not easy to do.
Difficulties & classic
1003 Crashing Balloon
1015 Fishing Net perfect image
1144 Robbery
1149 Dividing up
1161 Gone Fishing
1197 Sorting Slides
1217 Eight
1228 Farewell, My Friend
1237 Fans and Gems
1455 Schedule Problem
1456 Minimum Transport Cost graph Shortest Path to save
1492 Maximum Clique classical Graph Theory Algorithms-the largest group
1600 Market Place
1605 One-way Traffic
1568 WishingBone's Room Plan
1742 Gap has no idea so far. It's hard !!!
1743 Concert Hall Scheduling
1827 The Game of 31
1855 Maze
1903 Jogging Trails China mail routes
1909 Square classic dfs.
2064 Bomberman-Just Search! Classic!
2094 Max Angle Calculation ry + game
2125 Rocket Mania
2126 Rocket Mania Plus
2127 Zuma
2128 Seven Seas
2129 Mummy Maze
2142 Light The Square
(24 channels)
========================================================== ===
Dp
50 dp questions

1499 Increasing Sequenc ...... remaining full text>

ZOJ-1649 does the breadth-first algorithm of priority queue fail?

You are a little brave ..
I used the char array a to record sum.

Problems:
Since it is a char array, the maximum value is 256, which may not be enough to record the sum size.
If the sum in a is exactly the same as 'A', 'R ','. ',' # ', then you won't be able to tell whether the sum recorded after the trip is passed or the 'A', 'R ','. ','#'

For specific changes, refer to my views.
# Include <iostream> # include <string> # include <queue> using namespace std; int n, m, I, j, sum = 0; int rx, ry; char a [205] [205]; int aa [205] [205]; // Add aa to replace the original a array to store sumstring s; struct State {int x, y; state (int x, int y) {this-> x = x; this-> y = y ;}}; struct cmp {bool operator () (State a, State B) {return aa [. x] [. y]> aa [B. x] [B. y]; // compare values from aa }}; priority_queue <State, vector <State>, cmp> qs; bool find (State sStar T) {int dir [4] [2] = {1, 0}, {0,-1}, {-1, 0}, {0, 1 }}; qs. push (sStart); aa [sStart. x] [sStart. y] = sum; // set the accessed flag, and use sum to record the minimum time for this step while (! Qs. empty () {State state = qs. top (); qs. pop (); for (int I = 0; I <4; I ++) {int xx = state. x + dir [I] [0]; int yy = state. y + dir [I] [1]; if (aa [xx] [yy]! =-1) continue; // skip if (a [xx] [yy] = 'A ') {sum = aa [xx-dir [I] [0] [yy-dir [I] [1] + 1; // return true with aa ;} if (a [xx] [yy] = '. ') {aa [xx] [yy] = aa [xx-dir [I] [0] [yy-dir [I] [1] + 1; // replace qs with aa. push (State (xx, yy);} if (a [xx] [yy] = 'X ') {aa [xx] [yy] = aa [xx-dir [I] [0] [yy-dir [I] [1] + 2; // replace qs with aa. push (State (xx, yy) ;}} return false ;}in ...... remaining full text>

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.