题目链接:pid=3641">传送门 题意: 求最小的 ( x! ) = 0 mod (a1^b1*a2^b2...an^bn) 分析: 首先吧a1~an进行素因子分解,然后统计下每一个质因子的指数.因为随着x的增大,质因子的个数是逐渐添加的 因此我们能够二分x.对x!进行素因子分解推断是否满足条件.然后求出最小的就能够了. 代码例如以下: #include <iostream> #include <cstring> #include <algorithm&g…
/** 大意:给定一组ai,bi . m = a1^b1 *a2^b2 * a3^ b3 * a4^b4*...*ai^bi 求最小的x!%m =0 思路: 将ai 质因子分解,若是x!%m=0 那么x! 质因子分解之后 质因子的个数一定大于等于m的个数.二分求解可得 注意: 二分时,需要将,上下限 设定好,low =0: high = 1ll<<60; **/ #include <iostream> #include <cstring> #include <cm…
题目地址:HDU 3468 这道题的关键在于能想到用网络流.然后还要想到用bfs来标记最短路中的点. 首先标记方法是,对每个集合点跑一次bfs,记录全部点到该点的最短距离.然后对于随意一对起始点来说,仅仅要这个点到起点的最短距离+该点到终点的最短距离==起点到终点的最短距离,就说明这点在某条从起点到终点的最短路上. 然后以集合点建X集,宝物点建Y集构造二分图,将从某集合点出发的最短路中经过宝物点与该集合点连边.剩下的用二分匹配算法或最大流算法都能够.(为什么我的最大流比二分匹配跑的还要快....…
题意: A-Z&&a-z 表示 集结点 从A点出发经过 最短步数 走到下一个集结点(A的下一个集结点为B ,Z的下一个集结点为a) 的路上遇到金子(*)则能够捡走(一个点仅仅能捡一次) 求从A点出发走遍全部的的集结点 最多能捡多少金子 思路:先对于第 i 个集结点用BFS求出 对于每一个点从该集结点所需的步数  为D[ I ] [ t ] 对于随意一个金子若  两个相邻的集结点的最短步数=其到该金子的步数和 则建一条边(能够拿) 然后最大流求 #include <cstdio>…
[Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列上可以向上走,其他列不能向上走.可以重复经过同一个点.求从(1,1)出发,经过所有宝藏的最短路径长度 \(n,m,k,q \leq 2 \times 10^5\) 分析 贪心考虑,我们应该按照行一层一层的走.每一行应该从最左的宝藏走到最右的宝藏,或者从最右的宝藏走到最左的宝藏,然后找最近的一个可以向…
Codeforces Round #577 (Div. 2)  D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以还是可以看出来这个是一个dp的. 然后对于每一段,肯定是从左到右或者从右到左这个是最优的,这里就是有一点点贪心的思想. 所以要我们首先要求出每一行的最大最小,然后就是开始转移. 题目要求只有一部分的列才可以竖直方向的走,这个让我就有点迷糊. 首先每一段向下转移,如果这个位置向下转移到的那个位置直接有…
http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*==================================================== 二分查找符合条件的最小值 ======================================================*/ ll solve() { __int64 low = 0, high = INF, mid ; while(low <=…
//给一个n*m的图 //.表示空白地 //*表示有黄金 //#表示墙 //一个人须要依照A...Z..a..z的顺序以最短路径走到下一个 //每次仅仅能在他的路线上经过的地方取一块黄金 //问最多能取多少黄金 //对于每次起点和终点,用bfs搜索最短路,再用dfs找出最短路线经过的全部点 //对于第i次找最短路线与其走过的点建立边,然后用二分匹配就能找出 #include<iostream> #include<vector> #include<cstdio> #inc…
题意: 输入一个n行m列的图 每次按字母顺序走最短路, 从一个字母走到下一个字母的过程中,只能拿走一个金子,求走完当前图中所有的字母后能拿到的金子的最大值 解析: bfs求最短路 对于一个金子如果 dis1[i] + dis2[i] == dis1[next] 那么就代表着这个金子 在这条最短路上 可以拿 那么从上一个 字母 到当前节点连一条边 权值为1 会了吧... #include <iostream> #include <cstdio> #include <sstrea…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5652 Problem Description A long time ago there are no himalayas between India and China, the both cultures are frequently exchanged and are kept in sync at that time, but eventually himalayas rise…
http://acm.hdu.edu.cn/showproblem.php?pid=4750 题意: 定义f(u,v)为u到v每条路径上的最大边的最小值..现在有一些询问..问f(u,v)>=t的点对有所少对,注意(1,2)和(2,1)是不同的点对 分析: 原来最小生成树有一个很鬼畜的结论,那就是一个图的最小生成树中任意两个点的路径中的最大边一定最小.(妈蛋,完全不知道这个) 然后此题就变得很明朗了,用kruskal算法,加边的时候此边连接的两个集合的路径中的最大边就是这个边,存储下来,询问的时…
Problem Description background: A new semester comes , and the HDU also meets its 50th birthday. No matter what's your major, the only thing I want to tell you is:"Treasure the college life and seize the time." Most people thought that the colle…
Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8942    Accepted Submission(s): 2744 Problem Description The WHU ACM Team has a big cup, with which every member drinks water. Now, we know th…
http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:现在有一n个顶点的树形图,还有k只猴子,每个顶点只能容纳一只猴子,而且每只猴子至少和另外一只猴子通过边相连,现在要删边,保留最少的边使得满足题意. 思路: 贪心的想一想,顶点两两匹配时一条边的贡献值就是两只猴子,那这不就是二分匹配吗.所以先求个二分匹配即可,然后如果此时还是不够的话,那么剩下的猴子每只猴子都需要一条边. 如果用二分匹配的算法可能不太行,虽然看别人用Hopcroft-Carp算法跑了…
http://acm.hdu.edu.cn/showproblem.php?pid=2061 Problem Description background:A new semester comes , and the HDU also meets its 50th birthday. No matter what's your major, the only thing I want to tell you is:"Treasure the college life and seize the…
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5265 bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=599&pid=1002 题意: 从n个数中取两个数A,B,使得(A+B)%p最大. 题解: 首先对所有的数先取一次模,那么则有0<=a[i]+a[j]<=2*p-2(i!=j),对于a[i]+a[j]>=p的,只要使a…
India and China Origins 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5652 Description A long time ago there are no himalayas between India and China, the both cultures are frequently exchanged and are kept in sync at that time, but eventually hima…
DZY Loves Partition 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5646 Description DZY loves partitioning numbers. He wants to know whether it is possible to partition n into the sum of exactly k distinct positive integers. After some thinking he f…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1065    Accepted Submission(s): 536 Problem Description Today, bes…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6041 [题目大意] 给出一个仙人掌图,求第k小生成树 [题解] 首先找到仙人掌图上的环,现在的问题就是从每个环中删除一个元素, 求出删除元素总和中的第K大,我们发现通过限定第K大的大小,可以有效地搜索剪枝, 限制的大小导致搜索出来的总和数量是具有单调性的,我们可以二分这个值, 然后用搜索来定位第K大的大小.Thanks to Claris. [代码] #include <cstdio> #in…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3081 题意 有n对男女 女生去选男朋友 如果女生从来没和那个男生吵架 那么那个男生就可以当她男朋友 女生也可以选择从来没和自己闺蜜吵过架的男生当男朋友 如果 女生A和女生B是闺蜜 女生A和男生C吵过架 但是女生B和男生C从来没吵过架 那么女生A是可以选择男生C当男朋友的. 看来 讨好闺蜜是一件多么重要的事情.. T T组数据 给出 n, m, f 有N对男女, m对从未吵架关系 f 对闺蜜关系 思路…
题目传送门//res tp hdu 目的 在尾部逐步插入n个元素,求插入第i个元素时,[1,i)内删去多少个元素,可使前缀和[1,i]不大于m 多测Q [1,15] n [1,2e5] m [1,1e9] 每个元素Wi [1,m] (i∈[1,n]); 数据结构 树状数组 分析 维护两个树状数组,分别储存前缀和前缀中元素数量.先将元素全部读入,之后进行排列,同时记录好每个元素排列之后的下标.按下标向树状数组插入元素.之后二分枚举即可 时间复杂度O(Qnlognlogn) #include<ios…
HDU - 3586 Information Disturbing 题目大意:从敌人司令部(1号节点)到前线(叶子节点)的通信路径是一个树形结构,切断每条边的联系都需要花费w权值,现在需要你切断前线和司令部的连接,(就是所有叶子节点都到不了根节点),并且总花费不能超过m.问能够实行的方案中,最大花费的最小值,否则输出-1. 树形dp的题还是很好意识到用树形dp的,但最好是画一画图进行理解和推导,就像现在我随手画的图(第一次发现可以传图片). (画得有点小丑,问题不大) 现在回到问题,就是我们需要…
Information Disturbing Problem Description   In the battlefield , an effective way to defeat enemies is to break their communication system.The information department told you that there are n enemy soldiers and their network which have n-1 communica…
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…
Problem Description Rompire is a robot kingdom and a lot of robots live there peacefully. But one day, the king of Rompire was captured by human beings. His thinking circuit was changed by human and thus became a tyrant. All those who are against him…
Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know ∑i=1n∑j=inf(i,j) mod (109+7).   Input There are m…
Rabbit's String Problem Description Long long ago, there lived a lot of rabbits in the forest. One day, the king of the rabbit kingdom got a mysterious string and he wanted to study this string. At first, he would divide this string into no more than…
题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果攻占城市,就能装满背包.从城市到城市消耗的粮食等于两城市的距离,如果距离大于士兵当前的背包的容量,士兵就不能走这条路.士兵可以选择空降一次,空降不耗费.求p个士兵攻占所有城市所需要的最小背包容量k. 来源:2013 暑期多校联合训练 第一场 思路 非常好的一道比较综合的题目~首先我们能想到这是可相交…
题目链接 题意:n个人, 要完成a个x任务, b个y任务. 求,最短的时间 思路:由于时间较大,用 二分来找时间. dp[i][j]表示 i个人完成j个x任务, 最多能完成的y任务个数 这个题 不是很好想, 还参考了一下大神的博客 #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namesp…