ACM-ICPC 2017 Asia HongKong 解题报告

ACM-ICPC 2017 Asia HongKong 解题报告

任意门:https://nanti.jisuanke.com/?kw=ACM-ICPC%202017%20Asia%20HongKong

按AC次序:

D - Card collection

In an online game, a player can collect different types of power cards. Each power card can enable a player to have a unique game magic. There are m power cards available in the game as (P_1, . . . , P_m)(P1,...,Pm). AA power card can be acquired by game points or through trading with others. In order to support the trading easier, a platform has been built. The platform charges a fixed amount C_iCi,jj game points for trading respective power cards,P_iPi and P_jPj. Note. Trading P_iPi to P_jPj or P_jPj to P_iPi would be of the same charge.

Write a program to calculate the minimal number of game points with a given original power card (P o)(Po) to a target one (Pt)(Pt). The output of your program should be the minimal game point value.

Input

The test data may contain many test cases. Each test case contains three data sections. The first section is an integer to indicate the number of power card types m (1 < m \le 50)m(1<m50). The second section contains two integers representing the original power card Po(0 < Po \le m)(0<Pom) and the target power card Pt (0 < Pt \le m)Pt(0<Ptm). Also, Po cannot be the same as Pt. The third section has a set of triplets and each triplet contains two cards id ii, jj and the charge amount c_i,j (0 < c_i,j \le 20)ci,j(0<ci,j20) between 22 types of power cards (P_i,P_j)(Pi,Pj). The end part of section 33contains a single 00.

Output

The output for each test case is the minimal number of game points needed for the trading.

样例输入
5
2 4
1 2 1
2 3 4
5 4 2
3 4 1
2 5 2
0
7
6 7
1 2 4
1 3 2
1 6 1  
2 7 1
3 4 2
4 7 1
4 5 1
5 6 2
0
样例输出
4
4

题意概括:

一道英文题,其实讲的是:有N个结点,输入起点 o 终点 t ,输入路径建无向图,求 o 到 t 的最短路。

解题思路:

静态邻接表建图,stl优先队列优化的Dijsktra求单源最短路。

AC code:

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <deque>
 5 #include <cstdio>
 6 #include <vector>
 7 #include <queue>
 8 #include <cmath>
 9 #define INF 0x3f3f3f3f
10 using namespace std;
11 
12 
13 const int MAXN = 1e3 + 50;
14 typedef pair<int, int> HeapNode; 
15 struct edge
16 {
17     int v, nxt, w;
18 }G[MAXN*100];
19 int head[MAXN], dis[MAXN];
20 int N, M, cnt;
21 
22 inline void init()
23 {
24     for(int i = 0; i <= N; i++)
25         head[i] = -1, dis[i] = INF;
26     cnt = 0;
27 }
28 
29 inline void add(int from, int to, int we)
30 {
31     G[cnt].w = we;
32     G[cnt].v = to;
33     G[cnt].nxt = head[from];
34     head[from] = cnt++;
35 }
36 
37 void dij(int st)
38 {
39     //memset(dis, INF, sizeof(dis));
40     priority_queue<HeapNode, vector<HeapNode>, greater<HeapNode> > heap;    //申请优先队列,以键值1排序
41     dis[st] = 0;
42     heap.push(make_pair(0, st));
43     while(!heap.empty())
44     {
45         pair<int, int>T = heap.top();
46         heap.pop();
47 
48         if(T.first != dis[T.second]) continue;
49 
50         for(int i = head[T.second]; i != -1; i = G[i].nxt)
51         {
52             int v = G[i].v;
53             if(dis[v] > dis[T.second] + G[i].w)
54             {
55                 dis[v] = dis[T.second] + G[i].w;
56                 heap.push(make_pair(dis[v], v));
57             }
58         }
59     }
60 }
61 
62 int main()
63 {
64     int a, b, c;
65     while(~scanf("%d", &N))
66     {
67         int st, ed;
68         scanf("%d%d", &st, &ed);
69         //if(N == 0 && M == 0) break;
70         init();
71         while(~scanf("%d", &a))
72         {
73             if(a == 0) break;
74             scanf("%d%d", &b, &c);
75             add(a, b, c);
76             add(b, a, c);
77         }
78 
79         dij(st);
80         printf("%d\n", dis[ed]);
81     }
82 
83     return 0;
84 }
View Code

E - Base Station Sites

5 is the proposed next telecommunications standards beyond the current 4G4G standards. 5G5G planning aims at higher capacity than current 4G4G, allowing a higher density of mobile broadband users, and supporting device-to- device, reliable, and massive wireless communications. AA telecommunication company would like to install more base stations to provide better communication for customers. Due to the installation cost and available locations, the company can only install S (2 \le S \le L)S(2SL) base stations at L (2 \le L \le 100, 000)L(2L100,000) candidate locations. Since the base stations work in the same frequency band, they will interfere and cause severe performance degradation. To provide high quality communication experience to customers, the company would like to maximize the distance between the base stations so as to reduce the wireless interference among the base stations. Suppose the L candidate locations are in a straight line at locations P_1, P_2, ... , PL (0 \le Pi \le 1, 000, 000)P1,P2,...,PL(0Pi1,000,000) and the company wants to install SS base stations at the LL candidate locations. What is the largest minimum distance among the SS base stations?

Input

The input data includes multiple test sets.

Each set starts with a line which specifies LL (i.e.i.e., the number of candidate locations) and SS (i.e.i.e., the number of base stations). The next line contains LL space-separated integers which represent P_1P1 , P_2P2 , ... , P_LPL . The input data ends “000”.

Output

For each set, you need to output a single line which should be the largest minimum distance among the base stations.

For the first set, the 33 base stations can be installed at locations 2, 6, 112,6,11.

样例输入
5 3
2 3 9 6 11
4 3
1 4 9 10
0 0
样例输出
4
3

题意概括:

有 N 个坐标(非有序),在这N个坐标里选S个,使得两两间最小的距离最大化。

即:POJ 2456

解题思路:

二分搜索 最大化最小值

C( d ):可以安排基站的位置使得最近两个基站距离不小于 d;

那么问题就变成了求满足 C( d )的最大 d 。另外,最近的间距不小于 d 也就说明所有基站距离都不小于 d。

C( d ): 可以安排基站的位置使得任意基站的间距都不小于 d。

贪心法求解这个问题:

①对基站坐标进行排序

②把第一个基站放进 P0 坐标

③如果第 i 个基站放在 Pj 的话,第 i+1 个基站就要放入满足 Pj+d <= Pk 的最小的 Pk 中。

AC code:

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <cmath>
 6 #define INF 0x3f3f3f3f
 7 using namespace std;
 8 const int MAXN = 1e5+10;
 9 
10 int P[MAXN];
11 int N, M;
12 
13 bool c(int d)
14 {
15     int last = 0;
16     int crt = 0;
17     for(int i = 1; i < M; i++){
18         crt = last+1;
19         while(crt < N && P[crt] - P[last] < d) crt++;
20         if(crt == N) return false;
21         last = crt;
22     }
23     return true;
24 }
25 
26 int main()
27 {
28     while(~scanf("%d %d", &N, &M) && (N+M)){
29         for(int i = 0; i < N; i++)
30             scanf("%d", &P[i]);
31         sort(P, P+N);
32         int st = 0, ed = INF;
33         int mid = 0;
34         while(ed - st > 1){
35             mid = (st+ed)/2;
36             if(c(mid)) st = mid;
37             else ed = mid;
38         }
39         printf("%d\n", st);
40     }
41     return 0;
42 }
View Code

F - Nearby Bicycles

With fast developments of information and communication technology, many cities today have established bicycle sharing systems. The key component of the system is to provide information on nearby bicycles to potential users.

Consider mm bicycles and nn customers, where each bicycle is located at coordinate (c_j , d_j )(cj,dj) for j = 1, 2, ... , m,j=1,2,...,m,and each user ii is located at coordinate (a_i, b_i)(ai,bi) for i = 1, 2, ... , ni=1,2,...,n The distance between two coordinates (x, y)(x,y)and (x, y)(x,y) is measured by \sqrt{(x-x)^2 +(y-y)^2}(xx)2+(yy)2. For each user i = 1,2,...,ni=1,2,...,n, you are given a threshold s_isi, your task is to return the total number of bicycles that are within a distance of si from user ii.

Input

The test data may contain many test cases. Each test case contains four lines. The first line of each case contains two integers, mm and n (0 < m, n \le 1000)n(0<m,n1000). The second line contains the coordinates, (c_1, d_1), (c_2, d_2), ... , (c_m, d_m)(c1,d1),(c2,d2),...,(cm,dm), of bicycles 1, 2, ... , m1,2,...,m, respectively, which are separated by a space. The third line contains the coordinates,(a1, b1), (a2, b2), ... , (an, bn)(a1,b1),(a2,b2),...,(an,bn), of users 1, 2,... , n1,2,...,n, respectively, which are separated by a space. contains the thresholds, s_1, s_2, ... , s_ns1,s2,...,sn, of the nn users. The last test case is followed by a line of two 00s. All the number of coordinate in the input is in the range 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值