
acm / icpc
文章平均质量分 61
icpc题解
Sankkl1
这个作者很懒,什么都没留下…
展开
-
(2021 ICPC)亚洲区域赛(昆明)J.Parallel Sort(思维)
题目链接:https://ac.nowcoder.com/acm/contest/12548/J分析数字所要去的位置会形成一个循环关系,如 2 3 4 1 ,会形成如下的循环关系:2 要到 3 的位置,3 要到 4 的位置 4 要到 1 的位置:我们如果将其进行对称交换,会发现下一轮只要再换一次就可以有序。所以最多只要进行两轮交换。代码#include<bits/stdc++.h>using namespace std;int n,cnt;int a[100005];v原创 2021-04-05 11:31:15 · 1738 阅读 · 0 评论 -
(2021 ICPC)亚洲区域赛(昆明)I.Mr. Main and Windmills
题目链接:https://ac.nowcoder.com/acm/contest/12548/I分析直线用 y = kx + b 来存,直接算交点看是否在线段上,然后根据交点和起点的距离排序即可。注意计算公式,比赛中因为公式抄错就没过,后来检查了半天才发现代码#include<bits/stdc++.h>using namespace std;typedef long double ld;int n,q;const ld eps = 1e-6;const ld INF =原创 2021-04-04 18:53:23 · 3138 阅读 · 2 评论 -
2018 ICPC 银川 H.Fight Against Monsters(贪心)
It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagnan Egbert Felix Gaspar Humbert Ignatius Jayden Kasper Leroy Maximilian. As a storyteller, today I decide to tell you and others a story about the hero Huriyyah,原创 2021-01-25 17:31:12 · 220 阅读 · 0 评论 -
2018 ICPC 银川 F.Moving On(floyd变形)
For each test case, the first line contains two integers n (1 \le n \le 200)n(1≤n≤200) which is the number of cities, and q (1 \le q \le 2 \times 10^4)q(1≤q≤2×104) which is the number of queries that will be given. The second line contains nn integers r_1,原创 2021-01-25 17:22:16 · 265 阅读 · 0 评论 -
2018 ICPC 沈阳 G.Best ACMer Solves the Hardest Problem(预处理 思维)
题目链接:https://nanti.jisuanke.com/t/A2168分析这题关键在怎么将 k 拆分成两个可以开方的数,可以先预处理出可能的对数,然后直接调用,同时一定要注意越界的问题。代码#include<bits/stdc++.h>using namespace std;typedef long long ll;const ll mod = 6000;int n,m,t;map<pair<int,int>,int> mp;ll ans;原创 2021-01-23 17:49:28 · 204 阅读 · 0 评论 -
2017 ICPC 乌鲁木齐区域赛 D.Fence Building(平面图欧拉公式)
分析根据平面图欧拉公式可以推导出来,面数 = 新产生的点数 + 边数 + 1 。新产生的点数:C(n, 4) ,因为四个点可以产生一个新的点边数:C(n, 2) ,因为每两个点可以连成一条边最后公式就为 ans = C(n, 4) + C(n, 2) + 1代码#include<bits/stdc++.h>using namespace std;typedef long long ll;const ll mod = 1e9+7;ll n;ll qm(ll x,ll y)原创 2021-01-22 16:32:45 · 245 阅读 · 0 评论 -
2017 ICPC 南宁 M.The Maximum Unreachable Node Set(floyd 二分图最大匹配 求最大独立集)
题目描述In this problem, we would like to talk about unreachable sets of a directed acyclic graph G = (V, E). In mathematics a directed acyclic graph (DAG) is a directed graph with no directed cycles. That is a graph such that there is no way to start at an原创 2021-01-21 18:06:42 · 162 阅读 · 0 评论 -
2017 ACM-ICPC 区域赛青岛站(现场赛) K.Our Journey of Xian Ends(最小费用最大流 拆点)
Life is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpected places and unexpected people. Now our journey of Xian ends. To be carefully considered are the following questions.A few months later in Qingdao, an esse原创 2021-01-19 17:08:47 · 439 阅读 · 0 评论 -
2020牛客国庆集训派对day2 B.CHEAP DELIVERIES(状态压缩dp + dijkstra)
题目链接:https://ac.nowcoder.com/acm/contest/7818/B示例输入5 5 3 1 2 1 2 3 2 3 4 3 4 5 4 5 2 4 2 3 1 2 5 3 输出12分析题目可以简化为有 k 条路,每条都要按规定走过。我们可以想到,每条路要走到别的路肯定是从该路的结束点到其他路的开始点, k 最大18,那么我们可以给每条路按照这样的规则连边,然后用状态压缩来得到答案。代码#include<bits/stdc++.h>原创 2020-12-23 23:14:10 · 363 阅读 · 0 评论 -
第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(南京)F.Fireworks(概率+三分)
分析这题是一道几何分布的问题,百度对于几何分布的解释:做一个完美烟花的概率为 p ,我们可以算出 x 个烟花中含有完美的烟花的概率为 (1 - (1 - p)x) ,则做出烟花个数的期望就为 1 / (1 - (1 - p)x),那么做出完美烟花的花费的期望就是 (x * n + m) / (1 - (1 - p)x) ,这是一个凹函数,可以用三分找到答案。代码#include<bits/stdc++.h>using namespace std;int n,m,p;dou...原创 2020-12-22 22:15:42 · 478 阅读 · 1 评论 -
第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(上海)D.Walker(二分)
分析我们可以发现总共可以分一下情况:一个人走完全程两个人交叉走(不回头)一个人走一部分,路径不交叉前两种情况我们可以直接算出来,后面的一种我们要将路程分为两段,一段 p1 跑,一段 p2 跑,两个人跑完的时间越接近,情况越优。所以我们可以二分分割点(肯定在 p1 和 p2 之间)。代码#include<bits/stdc++.h>using namespace std;double n,p1,v1,p2,v2;double eps = 1e-8;void solve原创 2020-12-16 22:19:02 · 410 阅读 · 0 评论 -
2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest D.Keiichi Tsuchiya the Drift King(几何)
题目链接:https://codeforc.es/gym/102028/problem/DDrifting is a driving style in which the driver uses the throttle, brakes, clutch, gear shifting and steering input to keep the car in a state of oversteer while manoeuvring from turn to turn. As a sport, the d原创 2020-12-01 21:45:06 · 172 阅读 · 0 评论 -
2020ICPC·小米 网络选拔赛第一场 D.Router Mesh(tarjan 割点)
题目链接:https://ac.nowcoder.com/acm/contest/7501/Dtarjan的割点算法可以参考博文:https://blog.youkuaiyun.com/csyifanZhang/article/details/105370924分析求一个图去掉第 i 个点后的连通块数量分析对于每个点,首先总共有 sum 个连通块,求出每个点所在的强连通分量的个数 x ,如果是割点,那么去掉以后还剩下 sum + x - 1 个连通块。注意如果连通块只有一个点,那么去掉这个点后,连通块原创 2020-11-27 18:59:26 · 191 阅读 · 1 评论 -
2020ICPC·小米 网络选拔赛第一场 J.Matrix Subtraction(二维差分)
题目链接:https://ac.nowcoder.com/acm/contest/9541/J题目描述Given a matrix M_{}M of size n\times mn×m and two integers a, b_{}a,b , determine weither it is possible to make all entrys of M_{}M zero by repeatedly choosing a\times ba×b submatrices and reduce the v原创 2020-11-26 21:01:11 · 145 阅读 · 0 评论 -
2017ACM/ICPC亚洲区沈阳站 L.Tree (dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6228Problem DescriptionConsider a un-rooted tree T which is not the biological significance of tree or plant, but a tree as an undirected graph in graph theory with n nodes, labelled from 1 to n. If you cann原创 2020-11-19 21:05:53 · 221 阅读 · 0 评论 -
2020ICPC 江西省大学生程序设计竞赛 K.Travel Expense(floyed + 二分)
题目链接:https://ac.nowcoder.com/acm/contest/8827/K题目描述Huanhuan is always working on fansy programming questions. However, today he decided to give himself a break and travel to a beautiful country. Therefore, another problem arose.There are totally n citie原创 2020-11-17 22:03:52 · 690 阅读 · 0 评论 -
2020ICPC·小米 网络选拔赛第二场 H.Knapsack(贪心+背包)
题目链接:https://ac.nowcoder.com/acm/contest/7502/H分析这题如果直接用背包做的话会超时,因为 w 的范围非常小,所以算法的复杂度会很大。既然 w 很小,那么我们可以先贪心,根据每一个单位的价值来排序,前面的可以直接放进包里,从而达到缩小 dp 范围的目的。代码#include<bits/stdc++.h>using namespace std;typedef long long ll;ll n,m;struct node{ ll原创 2020-11-04 21:52:45 · 463 阅读 · 0 评论 -
第 45 届国际大学生程序设计竞赛(ICPC)亚洲网上区域赛模拟赛 B.XTL‘s Chessboard(思维)
题目链接:https://ac.nowcoder.com/acm/contest/8688/B题目描述Xutianli is a perfectionist, who only owns “Good Chessboard”.A well-known definition to the Good Chessboard is that there exists two integers u,v which satisfies ux+vy=1+u+v, with the given length x and原创 2020-11-01 18:56:40 · 3025 阅读 · 6 评论 -
第 45 届国际大学生程序设计竞赛(ICPC)亚洲网上区域赛模拟赛 D.Pokemon Ultra Sun(dp动态规划)
题目链接:https://ac.nowcoder.com/acm/contest/8688/D题目描述Two pokemons are in a battle.One is our and another is the opposite’s.Our pokemon is in confusion and the opposite’s pokemon is frozen.Once per turn , the opposite’s pokemon does nothing and our pokemo原创 2020-10-31 18:41:57 · 587 阅读 · 0 评论 -
【ACM-ICPC 2018 南京现场赛 】 I.Magic Potion(网络最大流)
题意有 n 个英雄,m 个怪兽, k 瓶药水,接下来n行代表第 i 个人可以杀的怪兽编号,每个人只能击败一只怪兽,但是如果有药水就可以杀两只怪兽,但是每个人只能用一次药水。 问最多能杀多少只怪兽。分析可以用网络最大流做,难点就在建图时如何连点。解法一源点连每个英雄,流通量为1;英雄连怪兽,流通量为1;怪兽连汇点,流通量为1;源点再连一个中转点出来,流通量为 k ;中转点连每个英雄,流通量为1。只需要跑一遍dinic。样例1:仔细思考一下,挺巧妙的。解法二源点连每个英雄,流通量为1;.原创 2020-10-22 22:46:51 · 285 阅读 · 0 评论 -
【ACM-ICPC 2018 南京现场赛 】 J.Prime Game(思维 + 素数筛)
题意题目意思就是每个子区间乘积总共有多少不同质因数。分析第 i 个数的质因数对总数的贡献就是 i * (n - i + 1) ,即这个数被包含在 i * (n - i + 1) 个子区间里。但是我们发现如果有两个数有同一个质因数,那么这种算法就会将一部分重复计算,于是我们可以用一个 pos 数组来记录某个质因数在前面最后出现的位置,那么公式就变成了 (i - pos[x]) * (n - i + 1) ,这样就能避免重复计算。解决了重复计算的问题,接下来就只要解决质因数的问题就可以了。如何得到一个.原创 2020-10-22 21:26:38 · 224 阅读 · 0 评论