POJ
不哭的超人
愿你孤独的努力终有回报,愿你前行的路上有人相伴。
展开
-
Remmarguts‘ Date
Remmarguts’ Date求第k短路#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef pair<int,int>P;const int N = 1e5 + 10;const long long mod = 1e9 + 7;co原创 2020-10-16 18:37:48 · 166 阅读 · 0 评论 -
POJ1845:Sumdiv
题目:Sumdiv题解:先用质因子分解A = p1a1 p2a2 p3a3…pnan (p1,p2,p3…为质数)AB = p1a1B p2a2B p3a3B…pnanB (p1,p2,p3…为质数)所求的就是(p10+…+p1a1B)(p20+…+p2a2B),所以这个就需要用到等比数列求和公式了这时候需要对(1-q)求逆元,但不能保证它们互质,所以不能单纯的使用扩展...原创 2020-05-01 21:43:20 · 268 阅读 · 0 评论 -
Looooops
题目:Looooops题解:令2^K为P,题目相当于求得是{[(A+C)%P+C]%P+C}%P…=B,执行了多少次可以转化成A+C*x-(1<<K)*y = B,表示加上x的C,减去有y次得到的结果大于(1<<K),如果这个方程有解就说明有答案。否则无解。#include <bits/stdc++.h>#include <algorithm>...原创 2020-10-19 15:30:53 · 168 阅读 · 0 评论 -
Housewife Wind
题目:Housewife Wind题解:题目修改的是边权,求的和也是边权之和,可以先建立一棵树,然后将边权移到下面的点变成点权,求和的时候只要再将LCA(x,y)的点权减掉就可以了。边权变成点权的时候需要注意是按照深度大小往下移,而不是点的大小。#include <map>#include <set>#include <stack>#include ...原创 2020-10-19 15:30:21 · 298 阅读 · 0 评论 -
IMMEDIATE DECODABILITY
题目:IMMEDIATE DECODABILITY题解:先按照每个字符串的长短从小到大排序,然后依次插入每一个字符串,并且每一个插完之后,做一下标记,如果下一个字符串访问到这个标记,则说明Not#include <string>#include <cstdio>#include <algorithm>#include <iostream>...原创 2020-10-19 15:29:56 · 524 阅读 · 0 评论 -
A Simple Problem with Integers(分块模板题)
题目:A Simple Problem with Integers #include <algorithm>#include <cstring>#include <cstdio>#include <cmath>using namespace std;typedef long long ll;const int N = 1e5+...原创 2019-11-09 23:14:37 · 469 阅读 · 0 评论 -
Radar Installation
题目:Radar Installation总结:这算是贪心的一道入门题,对于每一个点,可以求出这个点是在哪一段区间内才能被覆盖,接着对左区间从小到大排序,这样做是因为只有两个靠近的才有可能被同一个设备覆盖,接着便开始了遍历,先记录第一个区间的右端点x,判断下一个点的左端点如果大于x,那么就说明两个不可能被同一设备覆盖,需要更新x,并且设备加1。但如果小于等于x,这时候就需要考虑两个区间可能是包含...原创 2019-11-06 17:17:46 · 158 阅读 · 0 评论 -
Stall Reservations
题目:Stall Reservations总结:这道题按照时间的开始的从小到大排序,如果开始时间相同,那么就按照结束时间从小到大,用n2的时间复杂度,只要有后面的开始时间大于前面的结束时间,那么就是相同,这个超时了。所以可以用一个优先队列,按照结束时间从小到大,如果结束时间相同,那么就按照开始时间从大到小排。接下来就可以依次的遍历,如果当前牛的开始时间大于队列中第一个的结束时间,说明他们俩是可...原创 2019-11-06 14:34:16 · 574 阅读 · 0 评论 -
Sunscreen
题目:Sunscreen#include <stdio.h>#include <vector>#include <string.h>#include <algorithm>using namespace std;typedef long long ll;const int N = 1e5+5;const int inf = (1<...原创 2019-11-06 00:15:51 · 361 阅读 · 0 评论 -
Treasure Exploration
题目:Treasure Exploration总结:最小路径覆盖数=顶点个数-最大匹配数。但这个题目与普通题目有点区别,就是可能会间接相连。这个就需要floyd了#include <stdio.h>#include <vector>#include <string.h>using namespace std;const int N = 1505;c...原创 2019-11-04 18:27:30 · 236 阅读 · 0 评论 -
Antenna Placement
题目:Antenna Placement总结:题目是求最小路径覆盖,无向二分图的最小路径覆盖 = 顶点数 – 最大二分匹配数#include <stdio.h>#include <vector>#include <string.h>using namespace std;const int N = 1005;const int M = 2e3;...原创 2019-11-04 14:17:41 · 200 阅读 · 0 评论 -
Network of Schools
题目:Network of Schools总结:题目第一问求是缩点之后,入度为0的点的个数。第二问求的是缩点之后,max(入度为0的点的个数,出度为0的点的个数)。可以先用tarjan进行染色。然后再新建立一个图,分别求出它们的入度和出度。#include <stdio.h>#include <stack>#include <map>#include ...原创 2020-10-19 15:37:01 · 399 阅读 · 0 评论 -
Redundant Paths
题目:Redundant Paths总结 :这道题先给一个无向连通图,问加最少的边使这个图成为双连通图。可以先用tarjan求出桥,并且给桥做出标记。然后再用dfs给每一个点标记一个新的编号,这个地方需要利用br数组,此时的br数组为1 的是保存的是桥的起点和终点。然后统计这个新图的度为1的点答案 = (新图度为1的点+1)/2#include <stdio.h>#inclu...原创 2020-10-19 15:37:11 · 348 阅读 · 0 评论 -
Arctic Network
题目:Arctic Network总结:这道题是将原本要求P-1条边,变成求P-1-S条边里的最大值,这P-1-S条边是要求从小到大排#include <stdio.h>#include <set>#include <math.h>#include <queue>#include <string.h>#include <...原创 2020-10-19 15:40:22 · 449 阅读 · 0 评论 -
Borg Maze
题目:Borg Maze总结 :通过bfs+kruskal,用bfs找出两点之间的距离,在找道题目中两点之间的距离可能会有多个,但是后面的kruskal会通过排序把小的排在前面。所以不需要刻意的用bfs求两点之间的最短距离。然后就是kruskal的运用。结和代码#include <stdio.h>#include <set>#include <queue&...原创 2020-10-19 15:40:27 · 268 阅读 · 0 评论 -
Who Gets the Most Candies?
题目:https://vjudge.net/problem/POJ-2886思路:线段树+反素数#include <stdio.h>#include <vector>#include <math.h>#include <string>#define mid (start+end)/2#define ls (2*rt)#define r...原创 2019-09-12 16:15:23 · 251 阅读 · 0 评论 -
问题 F: Fansblog(威尔逊定理+Miller-Rabin素数检测算法)
题目描述Farmer John keeps a website called ‘FansBlog’ .Everyday , there are many people visited this blog.One day, he find the visits has reached P , which is a prime number.He thinks it is a interesting...原创 2019-08-25 17:58:37 · 184 阅读 · 0 评论 -
Cow Contest(POJ3660)
题目:Cow Contest思路:先用floyd求出有向图每两个点之间是否有关系,然后统计强于这个结点的有x个,再统计弱于这个结点的有y个,假如这个结节排第几能确定的话,肯定有x+y == n-1#include <stdio.h>const int N = 1e+4;int dp[N][N];int n,m;void floyd(){ for(int k = 1;k...原创 2019-08-11 17:05:29 · 145 阅读 · 0 评论 -
Water Testing
题目描述You just bought a large piece of agricultural land, but you noticed that – according to regulations – you have to test the ground water at specific points on your property once a year. Luckily th...原创 2020-10-19 15:38:59 · 439 阅读 · 0 评论 -
Farey Sums(欧拉函数)
题目描述Given a positive integer, N, the sequence of all fractions a/b with (0 < a ≤ b), (1 < b ≤ N) and a and b relatively prime, listed in increasing order, is called the Farey Sequence of order ...原创 2019-08-13 19:33:54 · 250 阅读 · 0 评论 -
Degree Sequence of Graph G(Havel定理)
Wang Haiyang is a strong and optimistic Chinese youngster. Although born and brought up in the northern inland city Harbin, he has deep love and yearns for the boundless oceans. After graduation, he c...原创 2019-08-06 18:27:01 · 812 阅读 · 0 评论 -
Wormholes(POJ3259)
DescriptionWhile exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a...原创 2019-07-30 10:10:36 · 136 阅读 · 0 评论 -
Watchcow(POJ2230)
思路:默认的欧拉图,将走过的路,起点的都标记一下,是可以回到起点的#include <stdio.h>#include <vector>using namespace std;vector<int>G[50005];int n,m;int len = 0;int vis[100000];void bfs(int pos){ for(int i...原创 2020-10-19 15:39:53 · 182 阅读 · 0 评论 -
Cows(POJ)
DescriptionFarmer John’s cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in his field is particularly good.Farmer Jo...原创 2019-07-19 18:08:19 · 584 阅读 · 0 评论 -
Mobile phones(POJ1195)
DescriptionSuppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and c...原创 2019-07-18 21:43:33 · 206 阅读 · 0 评论 -
P3740 [HAOI2014]贴海报 还有 Mayor‘s posters(POJ2528)
题目描述Bytetown城市要进行市长竞选,所有的选民可以畅所欲言地对竞选市长的候选人发表言论。为了统一管理,城市委员会为选民准备了一个张贴海报的electoral墙。张贴规则如下:electoral墙是一个长度为N个单位的长方形,每个单位记为一个格子;所有张贴的海报的高度必须与electoral墙的高度一致的;每张海报以“A B”表示,即从第A个格子到第B个格子张贴海报;后贴的海报可...原创 2020-10-19 15:27:43 · 197 阅读 · 0 评论 -
Stars(POJ2352)
DescriptionAstronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not...原创 2019-07-18 16:53:12 · 239 阅读 · 0 评论 -
Ultra-QuickSort(POJ2299)
DescriptionIn this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence...原创 2020-10-19 15:27:38 · 137 阅读 · 0 评论 -
Matrix Power Series(POJ3233)
DescriptionGiven a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak.InputThe input contains exactly one test case. The first line of input contains three positive inte...原创 2019-07-05 17:03:42 · 150 阅读 · 0 评论 -
Network(POJ1144)
DescriptionA Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The ...原创 2020-10-19 15:40:38 · 269 阅读 · 0 评论 -
Til the Cows Come Home(PO)2387
DescriptionBessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wa...原创 2019-07-30 22:33:07 · 157 阅读 · 0 评论 -
The Cow Prom
题目:The Cow Prom思路:用模板,统计每个连通分量内点大于1的个数#include <stdio.h>#include <stack>#include <map>#include <algorithm>using namespace std;const int N = 5e+5+10;struct str{ int do...原创 2020-10-19 15:41:52 · 329 阅读 · 0 评论 -
Constructing Roads(POJ2421)
题目:Constructing Roads思路:将已经走过的标记为0,然后使用kruskal模板#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int inf = 0x3f;struct str{ int x; int y;...原创 2019-08-05 15:37:58 · 175 阅读 · 0 评论 -
MPI Maelstrom(POJ1502)
题目:MPI Maelstrom思路:用Dijkstra模板ps:数组的范围需要注意一下,输入也需要注意一下#include <stdio.h>#include <queue>#include <iostream>using namespace std;typedef pair<int,int>P;const int N = 200;...原创 2019-08-05 13:22:11 · 164 阅读 · 0 评论 -
Balanced Lineup(POJ3264)(RMQ)
DescriptionFor the daily milking, Farmer John’s N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To ...原创 2020-10-19 15:40:59 · 189 阅读 · 0 评论 -
The Suspects(POJ1611)
DescriptionSevere acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best stra...原创 2020-10-19 15:40:48 · 121 阅读 · 0 评论 -
Silver Cow Party(POJ3268)
Silver Cow Party思考:先用Dijkstra求出x到其他点的最短距,并且保存下来。然后再循环n-1次求出其他点到x的最短距离,接着相加,求最大值。#include <stdio.h>#include <queue>#include <algorithm>using namespace std;typedef pair<int,in...原创 2019-07-31 17:38:51 · 182 阅读 · 0 评论 -
Find a multiple(POJ2356)
DescriptionThe input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000. This numbers are not necessarily different (so it may happen...原创 2019-07-22 15:30:16 · 124 阅读 · 0 评论 -
SPF(POJ1523)
Consider the two networks shown below. Assuming that data moves around these networks only between directly connected nodes on a peer-to-peer basis, a failure of a single node, 3, in the network on th...原创 2020-10-19 15:40:43 · 266 阅读 · 0 评论 -
Fence Repair(POJ3253)
DescriptionFarmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length...原创 2019-07-04 16:44:36 · 100 阅读 · 0 评论