Optimal food pairing for CCF simulation problem

Source: Internet
Author: User

Optimal food Pairing

Time limit: 1.0s
Memory Limit: 256.0MB
Problem DescriptionThe building has recently opened a restaurant chain offering takeaway services. With more and more chain stores, how reasonable to give customers a meal has become an urgent problem to solve.
The area of the building's chain can be seen as a nxn (as shown), the location of the lattice on the grid may include the branch (green label) or the customer (blue callout), and some of the lattice points cannot be passed (red callout).
A line in a grid chart represents a road that can be walked, with a distance of 1 adjacent to the two lattice points. The building must take the road that can be walked, and cannot be marked by red dots.


The main cost of delivery is reflected in the time spent on the road, each meal to walk a unit of distance will cost 1 yuan. Each customer's needs can be delivered from any branch of the building, with no limit on the total distribution of each branch.
Now that you've got the needs of the building's customers, how much will it cost to send these meals under the best delivery mode? Input FormatThe first line of input contains four integers n, m, K, D, respectively, indicating the size of the square chart, the number of branches in the building, the number of customers, and the number of points that cannot be passed.
Next M-line, two integers per line xi, Yi, represents the horizontal and vertical coordinates of a branch of a building in a square chart.
The next K line, each line of three integer xi, Yi, CI, respectively, each customer in the grid chart of the horizontal axis, ordinate and order the amount of food. (Note that there may be multiple customers in the same position in the grid chart)
The next D line, two integers per line, represents the horizontal and vertical coordinates of each point that cannot be passed. output FormatOutputs an integer that represents the cost to be spent in the optimal feeding mode. Sample Input10 2 3 3
1 1
8 8
1 5 1
2 3 3
6 7 2
1 2
2 2
6 8 Sample Output29 Measuring use case size and conventionsThe first 30% evaluation cases meet: 1<=n <=20.
The first 60% evaluation cases meet: 1<=n<=100.
All evaluation cases are met: 1<=n<=1000,1<=m, K, d<=n^2. There may be multiple customers on the same grid point. Each customer's order quantity does not exceed 1000, each customer needs the meal to be able to be sent. Problem-solving: Search Bai. The compressed Storage data section refers to the practice of csdn a Daniel. The very mouth
1#include <bits/stdc++.h>2 #definePII pair<int,int>3 #defineLL Long Long4 using namespacestd;5 Const intMAXN =1010;6 Const intdir[4][2] = {-1,0,0,-1,1,0,0,1};7 intN,M,K,D,E[MAXN][MAXN] = {0};8 structNode {9     intX,y,step;TenNodeintA =0,intb =0,intc =0) { Onex =A; Ay =b; -Step =C; -     } the }; -Queue<node>Q; - BOOLIsIn (intXinty) { -     returnX >0&& x <= n && y >0&& y <=N; + } - LL BFs () { +LL ans =0; A     intCNT =0; at      while(!Q.empty ()) { -Node now =Q.front (); - Q.pop (); -          for(inti =0; I <4; ++i) { -             intNX = now.x+ dir[i][0]; -             intNY = now.y + dir[i][1]; in             if(IsIn (Nx,ny) &&! (e[nx][ny]&1)) { -E[nx][ny] |=1; toQ.push (Node (nx,ny,now.step+1)); +                 if(e[nx][ny]&2) { -Ans + = (now.step+1) * (e[nx][ny]>>2); the                     if(++cnt = = k)returnans; *                 } $             }Panax Notoginseng         } -     } the     returnans; + } A intMain () { the     intx, y, z +      while(~SCANF ("%d %d%d%d",&n,&m,&k,&d)) { -          for(inti =0; I < m; ++i) { $scanf"%d%d",&y,&x); $Q.push (node (x, Y,0)); -E[x][y] |=1; -         } the          for(inti =0; I < K; ++i) { -scanf" %d%d%d",&y,&x,&z);WuyiE[x][y] = (e[x][y]|2) + (z<<2); the         } -          for(inti =0; I < D; ++i) { Wuscanf"%d%d",&y,&x); -E[x][y] |=1; About         } $printf"%i64d\n", BFS ()); -     } -     return 0; -}
View Code

Optimal food pairing for CCF simulation problem

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.