图模型


zoj 1203

zoj1203
求最短路径.
当做一个平面图。
有 横 纵 坐 标 x, y 轴

最小生成树

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求最小生成树

//kruskal求最小生成树
#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]));       //计算两两间的距离}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.

加边,使得所有点都连接,用最少的公路长度。

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

已经修好的路,边权为0,没修的,边权为最大值。

用 PointB 完成并查集和比较权重的作用

struct PointB  //专门的空间负责记录端点间的权重
{int parent;double price;
};

AC代码

#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  //专门的空间负责记录端点间的权重
{int parent;double price;
};double map[MAXN][MAXN];
bool is_out;
PointB minimun[MAXN];      //parent表示父节点,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;//对于已经连通的,距离为0for (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;}}}//没有连通的才输出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;}

拓扑排序

有先修课程和后修课程的关系。

AOV网络

课程例题

排队,必须从高到矮排。

作业: 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:


固定有一些窗口填入数字
我们发现第一个和最右边和上面的,就是四个角的数字分别为1,3,7,9 ,固定不变的

#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;
}

zoj-Swordfish-2022-5-6相关推荐

  1. ZOJ - 1203 Swordfish(最短路)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1203点击打开链接 Swordfish Time Limit: 2 ...

  2. ZOJ 1203 Swordfish(最小生成树 kruskal)

    题意  给你n个点的坐标  每个点都可与其它n-1个点相连  求这n个点的最小生成树的权重 裸的最小生成树  直接kruskal咯 #include<cstdio> #include< ...

  3. zoj 1203 Swordfish

    链接:zoj 1203 题意:输入n个城市的坐标,输出使n个城市连通的最短路线的长度 分析:通过坐标能够将两两之间的长度即权值算出,再用最小生成树的算法 只是这个题要注意输出时的格式问题,两组数据间要 ...

  4. ZOJ:1203 Swordfish

    题意:给你n个城市的坐标,要求你输出连通所有城市的最小线路长度. 思路:最小生成树.注意每两个样例之间有换行. #include <cstdio> #include <cmath&g ...

  5. ZOJ POJ题目分类

    ZOJ题目分类 初学者题:1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  6. POJ ZOJ题目分类

    POJ,ZOJ题目分类(多篇整合版,分类很细致,全面) 标签: 题目分类POJ整理 2015-04-18 14:44 1672人阅读 评论(0) 收藏 举报 本文章已收录于: 分类: ACM资料(5) ...

  7. POJ,ZOJ题目分类(多篇整合版,分类很细致,全面)

    水题: 3299,2159,2739,1083,2262,1503,3006,2255,3094 初级: 一.基本算法:        (1)枚举 (1753,2965)       (2)贪心(13 ...

  8. 【ZOJ题目分类】备忘

    ZOJ 题目 分类 初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 ...

  9. 2022年新能源汽车产业集群百人会

    2022年新能源汽车产业集群百人会   3月25日-3月27日,2022年第八届中国电动汽车百人会(以下简称百人会)在线上举办.本届论坛以"迎接新能源汽车市场化发展新阶段"为主题. ...

  10. 2022年AI芯片场景

    2022年AI芯片场景 随着技术成熟化,AI芯片的应用场景除了在云端及大数据中心,也会随着算力逐渐向边缘端移动,部署于智能家居.智能制造.智慧金融等领 域:同时还将随着智能产品种类日渐丰富,部署于智能 ...

最新文章

  1. 大四狗找工作,持续更新
  2. python notebook使用,Jupyter Notebook使用笔记
  3. python_threading模块实现多线程详解(转)
  4. Hadoop 2.2.0源码浏览:4. NodeManager
  5. java并发编程(二)多个线程多个锁
  6. 使用扩展欧几里得算法对逆元求解
  7. 新冠病毒对计算机的影响,人工智能给新冠病毒分类
  8. 银行与沪深300走势对比
  9. 动手深度学习13——计算机视觉:数据增广、图片分类
  10. 1276. 不浪费原料的汉堡制作方案-数学消元法
  11. 三维点云语义分割【综述】 ——Deep Learning for 3D Point Clouds: A Survey
  12. 客制化键盘编程_最全最细客制化键盘指南!(上)
  13. PWM直流马达速度控制
  14. cad转dxf格式文件太大,怎样操作将多张CAD图纸文件转换成高版本的DXF格式?
  15. linux webdav 乱码,webDav遇到的乱码问题
  16. dash dock安装 to_Dash to Dock 安装配置(图文教程)
  17. Excel 处理重复数据的几种方法
  18. ant编译错误:不再支持源选项 1.5,请使用 1.6 或更高版本。
  19. 油猴脚本——掘金Markdown格式适配器知识点记录【油猴脚本、Markdown、浏览器文件读取、tooltip、SVG、、模拟用户输入、aria-xxxx属性、剪切板操作、】
  20. 返回按钮悬浮(类似手机的悬浮按钮)

热门文章

  1. 数据分析行业中的数据运营是怎么一回事?
  2. 《 线性代数及其应用 (原书第4版)》—— 2.7 计算机图形学中的应用
  3. Petri网-简单程序设计
  4. .bat命令脚本简单编写运行
  5. 我的面试经历:day04
  6. Ubuntu下Intel A201 Wifi6驱动安装
  7. ModuleNotFoundError: No module named ‘keras.applications.resnet50‘
  8. 新编C语言程序设计pdf
  9. xp 架设网站服务器软件,xp架设ftp服务器软件
  10. Open-Falcon 配置参数概述