Poj 3216 least Point Coverage and some summary

Source: Internet
Author: User

Question in: http://poj.org/problem? Id = 3216

Our repair team is responsible for the maintenance tasks in N blocks. Now we know the direct distance between blocks.

Now there are m tasks, each of which has its own block (the task can appear in the same block), the latest Task start time, and task duration information.

Now, after programming, at least several maintenance personnel can be dispatched to complete the maintenance task.

Here, I want to summarize the two types of questions that can be matched by the maximum bipartite graph.

The first type of problem is the naked binary match. To put it bluntly, it is the number of vertices in the graph, and then the connection relationship of the vertex is given. Based on these relations, we can find the maximum match or the minimum point overwrite, or the minimum path Overwrite

For example:

Http://poj.org/problem? Id = 1466 directly models based on romance to find the largest independent subset

Http://poj.org/problem? Id = 3692 create a Bipartite Graph Based on the relationship between boys and girls and obtain the minimum vertex coverage.

The second type of problem is that although a graph is provided on the surface, some nodes in the graph are special. Our task is not to solve this graph, but to address these special points, re-create a new graph G, and then convert G to A bipartite graph to find the maximum path coverage.

For example:

Http://poj.org/problem? Id = 3020 antenna coverage
Each signal point in the figure that must be overwritten

Http://poj.org/problem? Id = 2594 the accessibility is defined according to the treasure search rule, that is,

Http://poj.org/problem? Id = 1422 create a Bipartite Graph Based on the relationship between the row and column, and then obtain the minimum vertex overwrite.

Http://poj.org/problem? Id = 1548 create a Bipartite Graph Based on spam points and find the minimum path overwrite.

Http://poj.org/problem? Id = 3041 create a Bipartite Graph Based on the rows and columns, and then obtain the minimum vertex coverage.

Http://poj.org/problem? Id = 1325 models based on different models of the two machines, and then calculates the minimum point coverage.

Sometimes, when creating a new graph G Based on the problem (for example, 1548 finds all the garbage), you need to find it by yourself. In this process, we often need to assist some other algorithms. For example, in 2594, we use the Floyd algorithm to find the accessibility between all points. For example, in 1548, for example, whether the position of the garbage point matches the direction of robot traversal.

In fact, this question also belongs to the second type. are different tasks reachable, that is to say, the current task I is at the latest time + the duration of I + the time from I to the block where J is located <j's latest start time.

So the program is as follows:

#include <stdio.h>#include <memory.h>#include <algorithm>using namespace std;#define MAX_NUM 22#define MAX_TASK 201#define MAX_DISTANCE 10000000struct Task{int block;int deadLine;int durationTime;};Task vTasks[MAX_TASK];int vvAdj[MAX_NUM][MAX_NUM];int visit[MAX_TASK];int vvTask[MAX_TASK][MAX_TASK];int matched[MAX_TASK];int nTask, nPoins;void floyd(){int k,i,j;for( k = 0; k < nPoins; k++){for( i = 0; i < nPoins; i++){for( j = 0; j < nPoins; j++){if( i != j){vvAdj[i][j] = min(vvAdj[i][j], vvAdj[i][k] + vvAdj[k][j]);}}}}}bool dfs(int f){for( int i = 0; i < nTask; i++){if(!visit[i] && vvTask[f][i]){visit[i] = true;if(matched[i] == -1 || dfs(matched[i])){matched[i] = f;return true;}}}return false;}bool TaskReachable(int i, int j){return (vTasks[i].deadLine + vTasks[i].durationTime +     vvAdj[vTasks[i].block][vTasks[j].block]) <= vTasks[j].deadLine;}void CreateTaskGraph(){int i,j;for( i = 0; i < nTask; i++){for( j = 0; j < nTask; j++){if( i != j && TaskReachable(i, j)){vvTask[i][j] = 1;}}}}int main(){int i,j;int dis;while(scanf("%d%d", &nPoins, &nTask)){if(nPoins == 0 && nTask == 0){break;}memset(vvAdj, 0, sizeof(vvAdj));memset(vvTask, 0, sizeof(vvTask));memset(matched, -1, sizeof(matched));for( i = 0; i < nPoins; i++ ){for( j = 0; j < nPoins; j ++){scanf("%d", &dis);if(dis == -1){vvAdj[i][j] = MAX_DISTANCE;}else{vvAdj[i][j] = dis;}}}int tt, dt, block;for( i = 0; i < nTask; i++){scanf("%d%d%d", &block, &tt, &dt);vTasks[i].deadLine = tt;vTasks[i].durationTime = dt;vTasks[i].block = block - 1;}floyd();CreateTaskGraph();int count = 0;for( i = 0; i < nTask; i++){memset(visit, 0, sizeof(visit));if(dfs(i)){count++;}}printf("%d\n", nTask - count);}return 0;}

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.