2020PAT甲级秋季7-4 Professional Ability Test (30分)

2023-12-09 11:48

本文主要是介绍2020PAT甲级秋季7-4 Professional Ability Test (30分),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

7-4Professional Ability Test(30分)

Professional Ability Test (PAT) consists of several series of subject tests. Each test is divided into several levels. Level A is a prerequisite (前置要求) of Level B if one must pass Level A with a score no less than S in order to be qualified to take Level B. At the mean time, one who passes Level A with a score no less than S will receive a voucher(代金券)of D yuans (Chinese dollar) for taking Level B.

At the moment, this PAT is only in design and hence people would make up different plans. A plan is NOT consistent if there exists some test T so that T is a prerequisite of itself. Your job is to test each plan and tell if it is a consistent one, and at the mean time, find the easiest way (with minimum total S) to obtain the certificate of any subject test. If the easiest way is not unique, find the one that one can win the maximum total value of vouchers.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N (≤1000) and M, being the total numbers of tests and prerequisite relations, respectively. Then M lines follow, each describes a prerequisite relation in the following format:

T1 T2 S D
where T1 and T2 are the indices (from 0 to N−1) of the two distinct tests; S is the minimum score (in the range (0, 100]) required to pass T1 in order to be qualified to take T2; and D is the value of the voucher (in the range (0, 500]) one can receive if one passes T1 with a score no less than S and plan to take T2. It is guaranteed that at most one pair of S and D are defined for a prerequisite relation.

Then another positive integer K (≤N) is given, followed by K queries of tests. All the numbers in a line are separated by spaces.

Output Specification:

Print in the first line Okay. if the whole plan is consistent, or Impossible. if not.

If the plan is consistent, for each query of test T, print in a line the easiest way to obtain the certificate of this test, in the format:

T0->T1->…->T
However, if T is the first level of some subject test (with no prerequisite), print You may take test T directly. instead.

If the plan is impossible, for each query of test T, check if one can take it directly or not. If the answer is yes, print in a line You may take test T directly.; or print Error. instead.

Sample Input 1:

8 15
0 1 50 50
1 2 20 20
3 4 90 90
3 7 90 80
4 5 20 20
7 5 10 10
5 6 10 10
0 4 80 60
3 1 50 45
1 4 30 20
1 5 50 20
2 4 10 10
7 2 10 30
2 5 30 20
2 6 40 60
8
0 1 2 3 4 5 6 7

Sample Output 1:

Okay.
You may take test 0 directly.
0->1
0->1->2
You may take test 3 directly.
0->1->2->4
0->1->2->4->5
0->1->2->6
3->7

Sample Input 2:

4 5
0 1 1 10
1 2 2 10
3 0 4 10
3 2 5 10
2 0 3 10
2
3 1

Sample Output 2:

Impossible.
You may take test 3 directly.
Error.

注意一个地方Dijkstra最短路取到最短的路径不能直接结束,因为可能有长度相同的节点,但赚的钱更多,最好是用优先队列做。有一种解法是在原有拓扑图中添加一个节点,使这个节点指向那些度为0的节点如何只需执行一次Dijkstra就可以得出答案。

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
struct Node {int s, d;
};
Node e[1050][1050];
int N, E, K, test, flag1 = 0, minS, maxD, inDegree[1050] = {0}, Dist[1050], father[1050], Voucher[1050];
vector<int> v[1050], ans;
bool visit[1050] = {false};
void dfs(int root) {if (root == -1) return;ans.push_back(root);dfs(father[root]);
}
void judge(int root, int root1) {if (flag1) return;for (int i = 0; i < v[root].size(); i++) {if (v[root][i] == root1) {flag1 = 1;return;}if (visit[v[root][i]])continue;visit[v[root][i]] = true;judge(v[root][i], root1);if (flag1) return;}
}
int main() {scanf("%d %d", &N, &E);int a, b, s, d;for (int i = 0; i < E; i++) {scanf("%d %d %d %d", &a, &b, &s, &d);inDegree[b]++;v[b].push_back(a);e[a][b].s = s;e[a][b].d = d;}scanf("%d", &K);for (int i = 0; i < N; i++) {fill(visit, visit + 1050, false);judge(i, i);if (flag1 == 1) break;}if (flag1 == 0) {printf("Okay.\n");for (int i = 0; i < K; i++) {scanf("%d", &test);if (inDegree[test] == 0) {printf("You may take test %d directly.\n", test);continue;} else {fill(Dist, Dist + 1050, INF);fill(Voucher, Voucher + 1050, 0);fill(father, father + 1050, -1);fill(visit, visit + 1050, false);minS = INF;maxD = 0;Dist[test] = 0;for (int j = 0; j < N; j++) {int minV = INF, Dot = -1;for (int t = 0; t < N; t++) {if (!visit[t] && Dist[t] < minV) {minV = Dist[t];Dot = t;}}if (Dot == -1) break;visit[Dot] = true;if (inDegree[Dot] == 0 && Dist[Dot] > minS) break;if (inDegree[Dot] == 0 && (Dist[Dot] < minS || (Dist[Dot] == minS && Voucher[Dot] > maxD))) {minS = Dist[Dot];maxD = Voucher[Dot];ans.clear();dfs(Dot);}if (Dist[Dot] > minS) break;for (int t = 0; t < v[Dot].size(); t++) {int id = v[Dot][t];if (!visit[id]) {if (Dist[id] > Dist[Dot] + e[id][Dot].s) {Dist[id] = Dist[Dot] + e[id][Dot].s;Voucher[id] = Voucher[Dot] + e[id][Dot].d;father[id] = Dot;} else if (Dist[id] == Dist[Dot] + e[id][Dot].s) {if (Voucher[id] < Voucher[Dot] + e[id][Dot].d) {Voucher[id] = Voucher[Dot] + e[id][Dot].d;father[id] = Dot;}}}}}for (int j = 0; j < ans.size(); j++) {if (j != 0) printf("->");printf("%d", ans[j]);}printf("\n");}}} else if (flag1 == 1) {printf("Impossible.\n");for (int i = 0; i < K; i++) {scanf("%d", &test);if (inDegree[test] != 0) printf("Error.\n");else printf("You may take test %d directly.\n", test);}}return 0;
}

这篇关于2020PAT甲级秋季7-4 Professional Ability Test (30分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/473666

相关文章

TP-Link PDDNS服将于务6月30日正式停运:用户需转向第三方DDNS服务

《TP-LinkPDDNS服将于务6月30日正式停运:用户需转向第三方DDNS服务》近期,路由器制造巨头普联(TP-Link)在用户群体中引发了一系列重要变动,上个月,公司发出了一则通知,明确要求所... 路由器厂商普联(TP-Link)上个月发布公告要求所有用户必须完成实名认证后才能继续使用普联提供的 D

mysql-8.0.30压缩包版安装和配置MySQL环境过程

《mysql-8.0.30压缩包版安装和配置MySQL环境过程》该文章介绍了如何在Windows系统中下载、安装和配置MySQL数据库,包括下载地址、解压文件、创建和配置my.ini文件、设置环境变量... 目录压缩包安装配置下载配置环境变量下载和初始化总结压缩包安装配置下载下载地址:https://d

30常用 Maven 命令

Maven 是一个强大的项目管理和构建工具,它广泛用于 Java 项目的依赖管理、构建流程和插件集成。Maven 的命令行工具提供了大量的命令来帮助开发人员管理项目的生命周期、依赖和插件。以下是 常用 Maven 命令的使用场景及其详细解释。 1. mvn clean 使用场景:清理项目的生成目录,通常用于删除项目中自动生成的文件(如 target/ 目录)。共性规律:清理操作

2024网安周今日开幕,亚信安全亮相30城

2024年国家网络安全宣传周今天在广州拉开帷幕。今年网安周继续以“网络安全为人民,网络安全靠人民”为主题。2024年国家网络安全宣传周涵盖了1场开幕式、1场高峰论坛、5个重要活动、15场分论坛/座谈会/闭门会、6个主题日活动和网络安全“六进”活动。亚信安全出席2024年国家网络安全宣传周开幕式和主论坛,并将通过线下宣讲、创意科普、成果展示等多种形式,让广大民众看得懂、记得住安全知识,同时还

论文翻译:ICLR-2024 PROVING TEST SET CONTAMINATION IN BLACK BOX LANGUAGE MODELS

PROVING TEST SET CONTAMINATION IN BLACK BOX LANGUAGE MODELS https://openreview.net/forum?id=KS8mIvetg2 验证测试集污染在黑盒语言模型中 文章目录 验证测试集污染在黑盒语言模型中摘要1 引言 摘要 大型语言模型是在大量互联网数据上训练的,这引发了人们的担忧和猜测,即它们可能已

Golang test编译使用

创建文件my_test.go package testsimport "testing"func TestMy(t *testing.T) {t.Log("TestMy")} 通常用法: $ go test -v -run TestMy my_test.go=== RUN TestMyTestMy: my_test.go:6: TestMy--- PASS: TestMy (0.

JavaScript正则表达式六大利器:`test`、`exec`、`match`、`matchAll`、`search`与`replace`详解及对比

在JavaScript中,正则表达式(Regular Expression)是一种用于文本搜索、替换、匹配和验证的强大工具。本文将深入解析与正则表达式相关的几个主要执行方法:test、exec、match、matchAll、search和replace,并对它们进行对比,帮助开发者更好地理解这些方法的使用场景和差异。 正则表达式基础 在深入解析方法之前,先简要回顾一下正则表达式的基础知识。正则

c++习题30-求10000以内N的阶乘

目录 一,题目  二,思路 三,代码    一,题目  描述 求10000以内n的阶乘。 输入描述 只有一行输入,整数n(0≤n≤10000)。 输出描述 一行,即n!的值。 用例输入 1  4 用例输出 1  24   二,思路 n    n!           0    1 1    1*1=1 2    1*2=2 3    2*3=6 4

mybatis if test 之 0当做参数传入出问题

首先前端传入了参数 if(StringUtils.isNotBlank(status)){requestParam.setProperty("status", Integer.parseInt(status));}List<SuperPojo> applicationList = groupDao.getApplicationListByReviewStatusAndMember(req

嵌入式面试经典30问:二

1. 嵌入式系统中,如何选择合适的微控制器或微处理器? 在嵌入式系统中选择合适的微控制器(MCU)或微处理器(MPU)时,需要考虑多个因素以确保所选组件能够满足项目的具体需求。以下是一些关键步骤和考虑因素: 1.1 确定项目需求 性能要求:根据项目的复杂度、处理速度和数据吞吐量等要求,确定所需的处理器性能。功耗:评估系统的功耗需求,选择低功耗的MCU或MPU以延长电池寿命或减少能源消耗。成本