当前位置:网站首页>[C language brush leetcode] 1462. curriculum IV (m)
[C language brush leetcode] 1462. curriculum IV (m)
2022-07-26 02:00:00 【kinbo88】
【
You need a total of numCourses Course , The course numbers are 0 To numCourses-1 . You'll get an array prerequisite , among prerequisites[i] = [ai, bi] If you want to choose bi Course , you must Choose... First ai Course .
Some classes have direct prerequisite courses , For example, if you want to take a course 1 , You must take the course first 0 , Then it will be [0,1] The number of prerequisite courses is given in the form of number pairs .
The prerequisite can also be indirect Of . If the course a It's a course b prerequisites , Course b It's a course c prerequisites , So the course a It's the course c prerequisites .
You also get an array queries , among queries[j] = [uj, vj]. For the first j A query , You should answer the course uj Is it a course vj prerequisites .
Returns a Boolean array answer , among answer[j] It's No j The answer to a query .
Example 1:
Input :numCourses = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]]
Output :[false,true]
explain : Course 0 Not a course 1 A prerequisite course for , But the course 1 It's a course 0 A prerequisite course for .
Example 2:
Input :numCourses = 2, prerequisites = [], queries = [[1,0],[0,1]]
Output :[false,false]
explain : There is no prerequisite course for , So each course is independent .
Example 3:
Input :numCourses = 3, prerequisites = [[1,2],[1,0],[2,0]], queries = [[1,0],[1,2]]
Output :[true,true]
Tips :
2 <= numCourses <= 100
0 <= prerequisites.length <= (numCourses * (numCourses - 1) / 2)
prerequisites[i].length == 2
0 <= ai, bi <= n - 1
ai != bi
Each pair of [ai, bi] all Different
There is no ring in the prerequisite course map .
0 <= ui, vi <= n - 1
ui != vi
source : Power button (LeetCode)
link :https://leetcode.cn/problems/course-schedule-iv
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
】
A violent meal takes time 196ms, result AC 了
bool* checkIfPrerequisite(int numCourses, int** prerequisites, int prerequisitesSize, int* prerequisitesColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){
int i, j, k;
int carr[numCourses][numCourses];
bool *retarr;
retarr = (bool *)malloc(sizeof(bool) * queriesSize);
*returnSize = queriesSize;
memset(carr, 0, sizeof(carr));
for (i = 0; i < prerequisitesSize; i++) {
carr[prerequisites[i][0]][prerequisites[i][1]] = 1; // Record the relationship between the pre selected courses given
}
for (i = 0; i < numCourses; i++) { // Find out all the relationships between the first courses , violence
for (j = 0; j < numCourses; j++) {
if (carr[i][j] == 1) {
for (k = 0; k < numCourses; k++) {
if (carr[k][i] == 1) {
carr[k][j] = 1;
}
}
}
}
}
for (i = 0; i < queriesSize; i++) {
if (carr[queries[i][0]][queries[i][1]] == 1) {
retarr[i] = true;
} else {
retarr[i] = false;
}
}
return retarr;
}边栏推荐
- The work of robot engineering and the puzzle of postgraduate entrance examination "volume" supplement
- 【深入浅出玩转FPGA学习11----Testbench书写技巧1】
- SQL injection tutorial: learn through examples
- There is no setter method in grpc list under flutter. How to use related attributes
- NFT market also began to diversify
- Move bricks (greedy perturbation + 01 backpack)
- 达梦数据库表导入导出按钮灰色,导入不了dmp文件
- DialogRPT-Dialog Ranking Pretrained Transformers
- MPLS knowledge points
- Make and makefile summary I
猜你喜欢

Composition API的优势

Protect syslog servers and devices

BGP knowledge points summary

Worthington papain - production of glycopeptides from purified proteoglycans (attached Literature)

How to display numbers / English time in Excel

【独立站建设】shopify卖家:学会这几点,网上商店销量翻倍!

The e-commerce project is written in the resume. How to answer it during the interview

保护系统日志服务器和设备

Worthington nuclease and Micrococcus related research and determination scheme

Implementation of recommendation system collaborative filtering in spark
随机推荐
Pt onnx ncnn conversion problem record (followed by yolov5 training)
给RestTemplate添加拦截器记录请求响应,还需解决流只读一次的问题
Build embedded development environment and FRP penetration under win
How to display numbers / English time in Excel
Excuse me, sir. Oracle to PG CDC Oracle, the upper case of the field is the same as that of PG
How to install opengauss manually (non om mode)
Summary after reading "poor dad and rich dad"
dataframe 修改某行某列位置的值
[Verilog digital system design (Xia Yuwen) 4 ----- basic concepts of Verilog syntax 2]
Jupiter notebook reported an error: notebook validation failed: non unique cell ID '2a4xx6' detected
IDEA如何快速删除最近打开的项目
MPLS知识点
怎么使用宝塔面板把node全栈项目部署到服务器上
DQN Pytorch示例
餐饮连锁门店重塑增长背后的数字化转型
劳驾问一下各位老师 oracle 到pg cdc oracle 那边字段大写 pg 这边小写 同
Phoenix中常用shell操作
Implementation of recommendation system collaborative filtering in spark
JS add random pixel noise background to the page
Digital transformation behind the reshaping growth of catering chain stores