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:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <deque>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std; const int MAXN = 1e3 + ;
typedef pair<int, int> HeapNode;
struct edge
{
int v, nxt, w;
}G[MAXN*];
int head[MAXN], dis[MAXN];
int N, M, cnt; inline void init()
{
for(int i = ; i <= N; i++)
head[i] = -, dis[i] = INF;
cnt = ;
} inline void add(int from, int to, int we)
{
G[cnt].w = we;
G[cnt].v = to;
G[cnt].nxt = head[from];
head[from] = cnt++;
} void dij(int st)
{
//memset(dis, INF, sizeof(dis));
priority_queue<HeapNode, vector<HeapNode>, greater<HeapNode> > heap; //申请优先队列,以键值1排序
dis[st] = ;
heap.push(make_pair(, st));
while(!heap.empty())
{
pair<int, int>T = heap.top();
heap.pop(); if(T.first != dis[T.second]) continue; for(int i = head[T.second]; i != -; i = G[i].nxt)
{
int v = G[i].v;
if(dis[v] > dis[T.second] + G[i].w)
{
dis[v] = dis[T.second] + G[i].w;
heap.push(make_pair(dis[v], v));
}
}
}
} int main()
{
int a, b, c;
while(~scanf("%d", &N))
{
int st, ed;
scanf("%d%d", &st, &ed);
//if(N == 0 && M == 0) break;
init();
while(~scanf("%d", &a))
{
if(a == ) break;
scanf("%d%d", &b, &c);
add(a, b, c);
add(b, a, c);
} dij(st);
printf("%d\n", dis[ed]);
} return ;
}
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:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 1e5+; int P[MAXN];
int N, M; bool c(int d)
{
int last = ;
int crt = ;
for(int i = ; i < M; i++){
crt = last+;
while(crt < N && P[crt] - P[last] < d) crt++;
if(crt == N) return false;
last = crt;
}
return true;
} int main()
{
while(~scanf("%d %d", &N, &M) && (N+M)){
for(int i = ; i < N; i++)
scanf("%d", &P[i]);
sort(P, P+N);
int st = , ed = INF;
int mid = ;
while(ed - st > ){
mid = (st+ed)/;
if(c(mid)) st = mid;
else ed = mid;
}
printf("%d\n", st);
}
return ;
}
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:
#include <cstdio>
#include <cstring>
#include <bits/stdc++.h>
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MOD=1e9+;
const int MAXN=1e3+; using namespace std; struct node{
ll F,S;
}a[MAXN],b[MAXN],t;
ll pos( node a,node b)
{
return ( (a.F-b.F)*(a.F-b.F)+ (a.S-b.S)*(a.S-b.S) );
}
ll R[MAXN];
int V[MAXN];
char s[];
int main()
{
int m,n;
while(scanf("%d%d",&m,&n)!=EOF)
{
getchar();
if(n==&&m==)
break;
memset(V,,sizeof(V));
for(int i=;i<=m;i++)
{
ll x,y;
scanf("%s",s);
sscanf(s,"(%lld,%lld)",&x,&y);
a[i].F=x;
a[i].S=y;
}
getchar();
for(int i= ; i<=n ; i++)
{
ll x,y;
scanf("%s",s);
sscanf(s,"(%lld,%lld)",&x,&y);
b[i].F=x;
b[i].S=y;
}
for(int i= ; i<=n ; i++)
scanf("%lld",&R[i]); for(int i= ; i<=n ; i++)
{
int ans=;
for(int j= ; j<=m ; j++)
{
ll POS=pos(b[i],a[j]);
if(POS<=(R[i]*R[i]))
ans++;
}
V[i]=ans;
} for(int i=;i<=n;i++)
printf("%d%c",V[i],i==n?'\n':' ');
}
return ;
}
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}xlowxhigh, 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:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int n;
int sum[];
int mark[];
void nodeupdate(int root,int l,int r,ll num)
{
mark[root]^=;
sum[root]=(r-l+)-sum[root];
}
void pushdown(int root,int l,int r)//传递给两孩子
{
if(mark[root]==)return;
int mid=(l+r)/;
nodeupdate(root*,l,mid,mark[root]);
nodeupdate(root*+,mid+,r,mark[root]);
mark[root]=;
}
void update(int kl,int kr,ll num, int root=,int l=,int r=n)//区间[kl,kr]修改
{
if(kl<=l&&r<=kr){
nodeupdate(root,l,r,num);
return;
}
pushdown(root,l,r);
int mid=(l+r)/;
if(kl<=mid)
update(kl,kr,num,root*,l,mid);
if(kr>mid)
update(kl,kr,num,root*+,mid+,r);
sum[root]=sum[root*]+sum[root*+];
} struct node{
int h,a,b,flag;
}e[];
int cnt=;
bool cmp(node a,node b){
if(a.h==b.h)return a.flag>b.flag;
return a.h<b.h;
}
int main()
{
int T,m,x1,x2,y1,y2;
cin>>T;
while(T--)
{
cin>>n>>m;
memset(sum,,sizeof(sum));
memset(mark,,sizeof(mark));
cnt=;
for(int i=;i<m;i++)
{
scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
e[cnt++]=node{y1,x1,x2,};
e[cnt++]=node{y2,x1,x2,-};
}
sort(e,e+cnt,cmp);
int ans=;
for(int i=,j=;i<=n;i++)
{
while(j<cnt&&e[j].h<=i&&e[j].flag==){
update(e[j].a,e[j].b,);
j++;
}
ans+=sum[];
while(j<cnt&&e[j].h<=i){
update(e[j].a,e[j].b,);
j++;
}
}
cout<<ans<<endl;
}
}
最后自闭 A 题 和 I 题 要用到 JAVA 大数。小蒟蒻不才,来日方长。
ACM-ICPC 2017 Asia HongKong 解题报告的更多相关文章
- 2013 ACM/ICPC 成都网络赛解题报告
第三题:HDU 4730 We Love MOE Girls 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4730 水题~~~ #include < ...
- hdu 4762 && 2013 ACM/ICPC 长春网络赛解题报告
这次的答案是猜出来的,如果做得话应该是应该是一个几何概型的数学题: 答案就是:n/(m^(n-1)); 具体的证明过程: 1.首先枚举这M个点中的的两个端点,概率是:n*(n-1); 2.假设这个蛋糕 ...
- hdu 4763 && 2013 ACM/ICPC 长春网络赛解题报告
一个KMP的简单题 不过好久没用过这个东东了,今天写的时候花了很多时间: 只需要花点时间判断下所有的元素都相同的的情况就行了! #include<cstdio> #include<c ...
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- ACM ICPC 2017 Warmup Contest 9 L
L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...
- SCNU ACM 2016新生赛决赛 解题报告
新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- 「雅礼集训 2017 Day2」解题报告
「雅礼集训 2017 Day2」水箱 我怎么知道这种题目都能构造树形结构. 根据高度构造一棵树,在树上倍增找到最大的小于约束条件高度的隔板,开一个 \(vector\) 记录一下,然后对于每个 \(v ...
- 「雅礼集训 2017 Day1」 解题报告
「雅礼集训 2017 Day1」市场 挺神仙的一题.涉及区间加.区间除.区间最小值和区间和.虽然标算就是暴力,但是复杂度是有保证的. 我们知道如果线段树上的一个结点,\(max=min\) 或者 \( ...
随机推荐
- win 引用win32无效问题
我使用pycharm 安装: python window 10 下安装win32 module 问题:安装后引用win32api等依赖,无效,但是目录下确实已经安装: 解决方案: ${python_h ...
- (转)expfilt 命令
expfilt 命令 原文:https://www.ibm.com/support/knowledgecenter/zh/ssw_aix_72/com.ibm.aix.cmds2/expfilt.ht ...
- Ace向你推荐一些实用的干货库~开发安卓的好帮手
1 毁灭地球的军火库arsenal- 你想要的枪这里都有卖 哈哈哈哈 , http://android-arsenal.com/ 2 黑科技---在线反编译----嘿嘿嘿 在线反编译 方便简单 客官 ...
- 手指静脉细化算法过程原理解析 以及python实现细化算法
原文作者:aircraft 原文地址:https://www.cnblogs.com/DOMLX/p/8672489.html 文中的一些图片以及思想很多都是参考https://www.cnblogs ...
- python实现excel转json的例子
python实现excel转json的例子(改进版) 由于数值策划给出数值是excel表格,但前台flash程序用的又是json格式.服务器也用了json格式,而json又是utf-8编码的,用C++ ...
- SpringSecurity 3.2入门(10)自定义权限控制认证及授权的过程
上一章的代码实现还存在一些问题,如角色表.权限表的用处没有体现出来,但是已经能完成URL拦截功能,后面将会继续完善认证及授权的过程. 认证及授权的过程如下: 1.容器启动,MyInvocationSe ...
- 02.switch的使用
基本语法: switch-case语法: switch(表达式/变量) { case 值1: 语句块1; break; case 值2: 语句块2; break; default:语句块3; brea ...
- Session&Cookie 简介及使用
Cookie cookie 是存储于访问者的计算机中的变量.每当同一台计算机通过浏览器请求某个页面时,就会发送这个 cookie.你可以使用 JavaScript 或其它语言来创建和取回 cookie ...
- js之闭包
函数作为返回值 高阶函数除了可以接受函数作为参数外,还可以把函数作为结果值返回. 我们来实现一个对Array的求和.通常情况下,求和的函数是这样定义的: function sum(arr) { ret ...
- 2、Dubbo源码解析--服务发布原理(Netty服务暴露)
一.服务发布 - 原理: 首先看Dubbo日志,截取重要部分: 1)暴露本地服务 Export dubbo service com.alibaba.dubbo.demo.DemoService to ...