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<m≤50). The second section contains two integers representing the original power card Po(0 < Po \le m)(0<Po≤m) and the target power card Pt (0 < Pt \le m)Pt(0<Pt≤m). 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?,j≤20) 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 }

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(2≤S≤L) base stations at L (2 \le L \le 100, 000)L(2≤L≤100,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(0≤Pi≤1,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 “00 00”.

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 }

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}(x?x)2+(y?y)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,n≤1000). 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 [-100000, 100000][?100000,100000].

Output

The output for each test case contains a line of nn integers, k_1, k_2, ... , k_nk1?,k2?,...,kn?, where each ki represents the total number of bicycles that are within a distance of s_isi? from user ii, for i = 1,2,...,ni=1,2,...,n.

样例输入复制

4 2
(0,0) (0,1) (1,0) (1,1)
(0,0) (1,1)
1 1
0 0

样例输出复制

3 3

题意概括:

先给出 N 个自行车的坐标, 然后给 M 个人的坐标,依次输出与第 j 个人距离为 sj 的自行车的数量( 1 < j <= M );

解题思路:

暴力纯模拟,不过输入用 sscanf 会方便很多。

输出是要注意格式,最后一个空格不输出。

AC code:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <bits/stdc++.h>
 4 typedef long long ll;
 5 const int INF=0x3f3f3f3f;
 6 const int MOD=1e9+7;
 7 const int MAXN=1e3+5;
 8
 9 using namespace std;
10
11 struct node{
12     ll F,S;
13 }a[MAXN],b[MAXN],t;
14 ll  pos( node a,node b)
15 {
16     return ( (a.F-b.F)*(a.F-b.F)+ (a.S-b.S)*(a.S-b.S) );
17 }
18 ll R[MAXN];
19 int V[MAXN];
20 char s[500000];
21 int main()
22 {
23     int m,n;
24     while(scanf("%d%d",&m,&n)!=EOF)
25     {
26         getchar();
27         if(n==0&&m==0)
28             break;
29         memset(V,0,sizeof(V));
30         for(int i=1;i<=m;i++)
31         {
32             ll x,y;
33             scanf("%s",s);
34             sscanf(s,"(%lld,%lld)",&x,&y);
35             a[i].F=x;
36             a[i].S=y;
37         }
38         getchar();
39         for(int i=1 ; i<=n ; i++)
40         {
41             ll x,y;
42             scanf("%s",s);
43             sscanf(s,"(%lld,%lld)",&x,&y);
44             b[i].F=x;
45             b[i].S=y;
46         }
47         for(int i=1 ; i<=n ; i++)
48         scanf("%lld",&R[i]);
49
50         for(int i=1 ; i<=n ; i++)
51         {
52             int ans=0;
53             for(int j=1 ; j<=m ; j++)
54             {
55                 ll POS=pos(b[i],a[j]);
56                 if(POS<=(R[i]*R[i]))
57                 ans++;
58             }
59             V[i]=ans;
60         }
61
62         for(int i=1;i<=n;i++)
63             printf("%d%c",V[i],i==n?‘\n‘:‘ ‘);
64     }
65     return 0;
66 }

B - Black and White

Considerasquaremapwith N \times NN×N cells. We indicate the coordinate of a cell by(i,j)(i,j),where 1 \le i,j \le N1≤i,j≤N. Each cell has a color either white or black. The color of each cell is initialized to white. The map supports the operation flip([x_{low}, x_{high}], [y_{low}, y_{high]})([xlow?,xhigh?],[ylow?,yhigh]?), which flips the color of each cell in the rectangle [x_{low}, x_{high}] \times [y_{low}, y_{high}][xlow?,xhigh?]×[ylow?,yhigh?]. Given a sequence of flip operations, our problem is to count the number of black cells in the final map. We illustrate this in the following example. Figure (a)(a) shows the initial map. Next, we call flip([2,4],[1,3])([2,4],[1,3]) and obtain Figure (b)(b). Then, we call f lip([1, 5], [3, 5])([1,5],[3,5]) and obtain Figure (c)(c). This map contains 1818 black cells.

Input

The first line contains the number of test cases T (T < 10)T(T<10). Each test case begins with a line containing two integers NN and K (1 < N,K < 10000)K(1<N,K<10000), where NN is the parameter of the map size and KK is the number of flip operations. Each subsequent line corresponds to a flip operation, with four integers: x_{low}x_{high}xlow?xhigh?, y_{low}, y_{high}ylow?,yhigh?.

Output

For each test case, output the answer in aa line.

样例输入复制

1
5 2
2 4 1 3
1 5 3 5

样例输出复制

18

题意概括:

黑白两色,矩阵初始化为白色,后面操作把 操作矩阵颜色反转。求黑色方块数量。

解题思路:

树状数组扫描线模板题。

AC code:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4
 5 int n;
 6 int sum[40000];
 7 int mark[40000];
 8 void nodeupdate(int root,int l,int r,ll num)
 9 {
10 mark[root]^=1;
11 sum[root]=(r-l+1)-sum[root];
12 }
13 void pushdown(int root,int l,int r)//传递给两孩子
14 {
15 if(mark[root]==0)return;
16 int mid=(l+r)/2;
17 nodeupdate(root*2,l,mid,mark[root]);
18 nodeupdate(root*2+1,mid+1,r,mark[root]);
19 mark[root]=0;
20 }
21 void update(int kl,int kr,ll num, int root=1,int l=1,int r=n)//区间[kl,kr]修改
22 {
23 if(kl<=l&&r<=kr){
24 nodeupdate(root,l,r,num);
25 return;
26 }
27 pushdown(root,l,r);
28 int mid=(l+r)/2;
29 if(kl<=mid)
30 update(kl,kr,num,root*2,l,mid);
31 if(kr>mid)
32 update(kl,kr,num,root*2+1,mid+1,r);
33 sum[root]=sum[root*2]+sum[root*2+1];
34 }
35
36 struct node{
37 int h,a,b,flag;
38 }e[404040];
39 int cnt=0;
40 bool cmp(node a,node b){
41 if(a.h==b.h)return a.flag>b.flag;
42 return a.h<b.h;
43 }
44 int main()
45 {
46 int T,m,x1,x2,y1,y2;
47 cin>>T;
48 while(T--)
49 {
50 cin>>n>>m;
51 memset(sum,0,sizeof(sum));
52 memset(mark,0,sizeof(mark));
53 cnt=0;
54 for(int i=0;i<m;i++)
55 {
56 scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
57 e[cnt++]=node{y1,x1,x2,1};
58 e[cnt++]=node{y2,x1,x2,-1};
59 }
60 sort(e,e+cnt,cmp);
61 int ans=0;
62 for(int i=1,j=0;i<=n;i++)
63 {
64 while(j<cnt&&e[j].h<=i&&e[j].flag==1){
65 update(e[j].a,e[j].b,1);
66 j++;
67 }
68 ans+=sum[1];
69 while(j<cnt&&e[j].h<=i){
70 update(e[j].a,e[j].b,1);
71 j++;
72 }
73 }
74 cout<<ans<<endl;
75 }
76 }

最后自闭 A 题 和 I 题 要用到 JAVA 大数。小蒟蒻不才,来日方长。

原文地址:https://www.cnblogs.com/ymzjj/p/9784504.html

时间: 2024-10-22 14:00:27

ACM-ICPC 2017 Asia HongKong 解题报告的相关文章

ACM : HDU 2899 Strange fuction 解题报告 -二分、三分

Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5933 Accepted Submission(s): 4194 Problem Description Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100) C

ACM: The Suspects-并查集-解题报告

The Suspects Time Limit:1000MS Memory Limit:20000KB 64bit IO Format:%lld & %llu Description 严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3月中旬开始被认为是全球威胁.为了减少传播给别人的机会, 最好的策略是隔离可能的患者. 在Not-Spreading-Your-Sickness大学( NSYSU), 有许多学生团体.同一组的学生经常彼此相通,一个学生可以同时加入几个小

NOIP模拟2017.6.11解题报告

T1: 水题: 代码: #include <cstdio> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 int n,ai[maxn],Max[maxn],bi[maxn],size; int tree[maxn]; inline void in(int &now) { char Cget=getchar();now=0; while(Cget&

ACM: Ubiquitous Religions-并查集-解题报告

Ubiquitous Religions Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Description 当今世界有很多不同的宗教,很难通晓他们.你有兴趣找出在你的大学里有多少种不同的宗教信仰. 你知道在你的大学里有n个学生(0 < n <= 50000) .你无法询问每个学生的宗教信仰.此外,许多学生不想说出他们的信仰.避免这些问题的一个方法是问m(0 <= m <= n(n -

UPC5431/acm icpc 2017 Tehran Column Addition

题目链接:http://exam.upc.edu.cn/problem.php?cid=1326&pid=7 题意:给你一个可能存在错误的加法等式,问最少删除多少列能使等式成立. eg: 思考:如果某一列已经成立,如上图的1+4=5,他一定可以加到前面最长的成立的等式上,类似于最长上升子序列,不过要n^2扫. 做题时WA了几发,因为没考虑到等式的最高位不能有进位,以及可能某一列一开始没有进位,但是后来由于前面低位的进位导致了自己的进位(这种情况只会出现在初始和为9,低位又进一的情况). 1 #i

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri

2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 1496    Accepted Submission(s): 723 Problem Description Kelukin is a businessman. Every day, he travels arou

2014哈商大ICPC/ACM校赛解题报告

被debug邀请去參加校赛,哎,被虐..我对不起工大.. 由于本人不搞ACM,算法处于HelloWorld水准.. 虽然题目除了鸟不拉屎星人之外都非常水,但我能做到这个程度,全然是超水平发挥了.. 数据:点此下载 ============================================================== a:逆序数组+删除特定元素 题目: 小伙伴们好像非常多没接触过ICPC,那先来一道水题尝尝鲜,给出 一个数组,和一个特征值.将这个数组中特征值值删除后逆序输出.

hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1610    Accepted Submission(s): 630 Problem Description (From wikipedia) For bina