当前位置:网站首页>zoj-Swordfish-2022-5-6
zoj-Swordfish-2022-5-6
2022-07-24 10:13:00 【A hard-working Mengxin, come on】
Graph model


zoj 1203
zoj1203
Find the shortest path .
As a plan .
Yes cross longitudinal sit mark x, y Axis
Minimum spanning tree
so Gabriel wants to find out the minimal total length of the tunnel required to connect all these cites. Now he asks you to write a computer program to find out the minimal length.

kruskal Find the minimum spanning tree
//kruskal Find the minimum spanning tree
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
using namespace std;
int f[110], n, m;
struct node
{
int a, b;
double c;
}t[5000];
int cmp(struct node x, struct node y)
{
return x.c < y.c;
}
int find(int x)
{
if (x != f[x])
f[x] = find(f[x]);
return f[x];
}
double krus()
{
int i, k = 0, x, y;
double s=0;
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 i, j, k = 0;
double s, x[110], y[110];
memset(x, 0, sizeof(x));
memset(y, 0, sizeof(y));
while (cin>>n) {
if (n == 0)
break;
if (k >= 1)
cout << endl;
k++;
for (i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
f[i] = i;
}
m = 1;
for (i = 1; i <= n; i++)
for (j = 1; j < i; j++) {
t[m].a = i;
t[m].b = j;
t[m++].c = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])); // Calculate the distance between two
}
sort(t + 1, t + m, cmp);
s = krus();
printf("Case #%d:\nThe minimal distance is: %.2lf\n", k, s);
}
return 0;
}

zoj 2048
All highways can be used in both directions. Highways can freely cross each other.
but a driver can only switch between highways at a town that is located at the end of both highways.
The Flatopian government wants to minimize the cost of building new highways.
Thus, the least expensive highway system will be the one that minimizes the total highways length.
Input
The input consists of two parts. The first part describes all towns in the country, and the second part describes all of the highways that have already been built.
The first line of the input contains a single integer N (1 <= N <= 750), representing the number of towns.
The next N lines each contain two integers, xi and yi separated by a space.
These values give the coordinates of ith town (for i from 1 to N).
Coordinates will have an absolute value no greater than 10000. Every town has a unique location.
The next line contains a single integer M (0 <= M <= 1000), representing the number of existing highways. The next M lines each contain a pair of integers separated by a space. These two integers give a pair of town numbers which are already connected by a highway. Each pair of towns is connected by at most one highway.
Output
Write to the output a single line for each new highway that should be built in order to connect all towns with minimal possible total length of new highways. Each highway should be presented by printing town numbers that this highway connects, separated by a space.
If no new highways need to be built (all towns are already connected), then the output should be created but it should be empty.
Bordering , Make all points connected , Use the least highway length .
Sample Input
1
9
1 5
0 0
3 2
4 5
5 1
0 4
5 2
1 2
5 3
3
1 3
9 7
1 2
Sample Output
1 6
3 7
4 9
5 7
8 3
The road that has been repaired , The boundary right is 0, It's not fixed , The edge weight is the maximum .
use PointB Complete the function of searching sets and comparing weights
struct PointB // A special space is responsible for recording the weights between endpoints
{
int parent;
double price;
};
AC Code
#include<iostream>
#include<cmath>
using namespace std;
#define MAX_PRICE 1<<30
#define MAXN 1001
int f[1000];
struct node
{
int x;
int y;
}towns[750];
struct PointB // A special space is responsible for recording the weights between endpoints
{
int parent;
double price;
};
double map[MAXN][MAXN];
bool is_out;
PointB minimun[MAXN]; //parent Represents the parent node ,price Means the price
int j = 0, ct = 0, i = 0, n = 0, m = 0;
bool used[MAXN];
int find(int x)
{
if (x != f[x])
f[x] = find(f[x]);
return f[x];
}
void init()
{
cin>>n;
for (int i = 1; i <= n; i++) {
cin >> towns[i].x>> towns[i].y;
used[i] = false;
minimun[i].price = MAX_PRICE;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
map[i][j] = sqrt((towns[i].x - towns[j].x) * (towns[i].x - towns[j].x) + (towns[i].y - towns[j].y) * (towns[i].y - towns[j].y));
map[j][i] = map[i][j];
}
}
int m;
cin >> m;
int x, y;
// For those already connected , A distance of 0
for (int i = 0; i < m; i++) {
cin >> x >> y;
map[x][y] = 0;
map[y][x] = 0;
}
}
void prim()
{
minimun[1].price = 0;
used[1] = true;
int now = 1;
for (int i = 1; i < n; i++) {
double min = MAX_PRICE;
int next = 0;
for (int j = 1; j <= n; j++) {
if (!used[j]) {
if (minimun[j].price > map[now][j])
{
minimun[j].price = map[now][j];
minimun[j].parent = now;
}
if (min > minimun[j].price) {
min = minimun[j].price;
next = j;
}
}
}
// Output only when there is no connection
if (min != 0) {
is_out = false;
printf("%d %d\n", next, minimun[next].parent);
}
now = next;
used[now] = true;
}
}
int main()
{
int t = 0;
cin >> t;
while (t--) {
is_out = true;
init();
prim();
if (t)
printf("\n");
}
return 0;
}
A topological sort
There is the relationship between prerequisite courses and later courses .
AOV The Internet
Course examples
line up , You must row from high to low .
Homework : zoj 2193
2193
Window Pains
Time Limit: 2000 msMemory Limit: 65536 KB
Boudreaux likes to multitask, especially when it comes to using his computer. Never satisfied with just running one application at a time, he usually runs nine applications, each in its own window. Due to limited screen real estate, he overlaps these windows and brings whatever window he currently needs to work with to the foreground. If his screen were a 4 x 4 grid of squares, each of Boudreaux’s windows would be represented by the following 2 x 2 windows:
When Boudreaux brings a window to the foreground, all of its squares come to the top, overlapping any squares it shares with other windows. For example, if window 1 and then window 2 were brought to the foreground, the resulting representation would be:
. . . and so on . . .
Unfortunately, Boudreaux’s computer is very unreliable and crashes often. He could easily tell if a crash occurred by looking at the windows and seeing a graphical representation that should not occur if windows were being brought to the foreground correctly. And this is where you come in . . .
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.
A single data set has 3 components:
Start line - A single line:

There are fixed some windows filled with numbers
We found the first and rightmost and top , The numbers of the four corners are 1,3,7,9 , unchanging 
#include<stdio.h>
#include<string.h>
int main()
{
int win[9][4][4];
memset(win, 0, sizeof(win));
int i, j, k, bi, bj;
for (k = 0; k < 9; k++)
{
bi = k / 3;
bj = k % 3;
for (i = bi; i < bi + 2; i++)
for (j = bj; j < bj + 2; j++)
win[k][i][j] = k + 1;
}
int map[10][10], num;
char s[11];
while (gets(s), strcmp(s, "ENDOFINPUT"))
{
memset(map, 0, sizeof(map));
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
{
scanf("%d", &num);
for (k = 0; k < 9; k++)
if (win[k][i][j] && win[k][i][j] != num)
map[num][win[k][i][j]] = 1;
}
for (k = 1; k <= 9; k++)
for (i = 1; i <= 9; i++)
for (j = 1; j <= 9; j++)
map[i][j] = map[i][j] || (map[i][k] && map[k][j]);
int flag = 1;
for (i = 1; i <= 9; i++)
for (j = 1; j <= 9; j++)
if (map[i][j] && map[j][i])
flag = 0;
puts(flag ? "THESE WINDOWS ARE CLEAN" : "THESE WINDOWS ARE BROKEN");
getchar();
gets(s);
}
return 0;
}

边栏推荐
- Redis configuration serialization
- Binary original code, inverse code, complement code
- How to solve command 'xxx GCC' not found, but can be installed with:??
- Spark Learning: compile spark source code in win10
- The concept and representation of a tree
- 分布式锁-Redission 原理分析
- Analysis of distributed lock redistribution principle
- [STM32 learning] (12) STM32 realizes LCD1602 simple static reality
- System a uses window.open to call system B, and system B carries data back to system a after processing the business
- 2022 trusted cloud authoritative assessment released: Tianyi cloud has obtained ten certifications and five best practices
猜你喜欢

Ribbon's loadbalancerclient, zoneawareloadbalancer and zoneavoidancerule are three musketeers by default

【机器人学习】机构运动学分析与matlab仿真(三维模型+word报告+matlab程序)

zoj 2770 差分约束系统---2--2022年5月20日

Uniapp calendar component

Analysis of Kube proxy IPVS mode

NIO知识点

Do you really understand the concept of buffer? Take you to uncover the buffer zone~
![[STM32 learning] (11) STM32 Mifare_ Use of one (S50) m1s50 (read, write, key modification, control bit interpretation)](/img/fd/4290525914b5146fe0eb653517fef9.png)
[STM32 learning] (11) STM32 Mifare_ Use of one (S50) m1s50 (read, write, key modification, control bit interpretation)

关联规则--2022年7月10日

Dynamic programming -- a collection of stock problems
随机推荐
Value on the object Z rotation synchronization panel in unity
Arduino- how to light the LED?
[sword finger offer II 115. reconstruction sequence]
2022, will lead the implementation of operation and maintenance priority strategy
Is it safe for Oriental Fortune futures to open an online account, and will it be cheated?
Tag the specified commit and submit the tag
Uniapp calendar component
[STM32 learning] (10) stm32f1 general timer realizes pulse counter
Application of for loop
[STM32 learning] (12) STM32 realizes LCD1602 simple static reality
Spark Learning: a form of association in a distributed environment?
How to solve the problem of robot positioning and navigation in large indoor scenes with low-cost solutions?
Set scrolling for the box
OpenGL drawing simple triangles
The most complete solution for distributed transactions
程序的编译与链接
[leecode] get the longest common substring of two strings
Raspberry Pie: serial port login does not display print information
Source insight 3.5 comment garbled
【二叉树先导】树的概念和表示方法