HDOJ Problem - 1299】的更多相关文章

题意:等式 1 / x + 1 / y = 1 / n (x, y, n ∈ N+ (1) 且 x <= y) ,给出 n,求有多少满足该式子的解.(1 <= n <= 1e9) 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299 分析:x,y肯定都满足 n<x<=y; 设 x = n + k; 带入上式得 :1/y = k/(n2+n*k); 即 k要整除 (n2+n*k); 又 k 一定整除 n*k; 即求 k 整除 n…
首先 m = 1 时 ans = 0对于 m > 1 的 情况 由于 1 到 m-1 中所有和m互质的数字,在 对m的乘法取模 运算上形成了群 ai = ( 1<=a<m && gcd(a,m) == 1 ) 所以 对于 a 必然存在b = a^(-1) = inv(a) 使得 a * b = 1 (mod m) 这里存在两种情况 a != b 那么最后的连乘式中a b均出现一次,相乘得1 a == b 那么最后的连乘式中只出现一个a 实际上所有 a = inv(a) 的…
问题陈述: HDOJ Problem - 1023 问题解析: 卡特兰数(Catalan)的应用 基本性质: f(n) = f(1)f(n-1) + f(2)f(n-2) + ... + f(n-2)f(2) + f(n-1)f(1); f(n) = C(2n, n) / (n+1) = C(2n-2, n-1) / n;  Cn = (4n-2)/(n+1) Cn-1 代码详解: I: C++ #include <iostream> #include <cstdio> #incl…
#1299 : 打折机票 题目连接: http://hihocoder.com/problemset/problem/1299 Description 因为思念新宿的"小姐姐"们,岛娘计划6月份再去一趟东京,不过这次看来她需要自掏腰包.经过了几天的夜战,岛娘终于在体力耗尽之前,用Python抓下了所有6月份,上海至东京的全部共 n 张机票.现在请你帮助债台高筑的岛娘筛选出符合时间区间要求的,最贵的机票. Input 输入数据的第一行包含两个整数 n, m(1 ≤ n, m ≤ 105)…
题目链接:http://hihocoder.com/problemset/problem/1299 线段树,按照t为下标去更新v,更新的时候要保留最大的那个. #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #include <complex> #include <fstream&g…
怎么又是博弈论...我去 Orz hzwer,这道题其实是可以转化成Nim游戏的! "第一步: 先从n根巧克力棒中取出m(m>0)根,使得这m根巧克力棒的xor和为0,同时使得剩下的n-m根巧克力棒无论怎么取,xor和都不为0. m根巧克力棒的xor和为0 <=>把nim游戏的必败状态留给对方 剩下的n-m根巧克力棒无论怎么取,xor和都不为0 <=>  m为巧克力棒的xor和为0的最长子序列 第二步: 第一步以后,对手就面临一个必败状态的nim游戏. 如果他从n-…
题目传送门 /* 水题:看见x是十的倍数就简单了 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; int main(void) //HDOJ 4716…
题目传送门 /* 递推DP: 如果a, b, c是等差数列,且b, c, d是等差数列,那么a, b, c, d是等差数列,等比数列同理 判断ai-2, ai-1, ai是否是等差(比)数列,能在O(n)时间求出最长的长度 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll…
题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - len -1,r]; */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <queue> using namespace std;…
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tempter of the Bone [从零开始DFS(1)] -DFS四向搜索/奇偶剪枝 HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] -DFS四向搜索变种 HDOJ(HDU).1016 Prime Ring Problem (…
hdoj 1299 Diophantus of Alexandria 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299 题意:求 1/x + 1/y = 1/n (x <= y) 的组数. 思路:转化为一个数的因子个数. 因为x,y,z 都是整数,令 y = n+k (倒数和相等,x,y 明显大于 n),带入式子可得 x = n*n / k + n :所以 x 的组数就与k相关了,只要 k 满足是 n*n 的约数,组数就 +1.假设 n = (p…
[HDOJ 5371] Hotaru's problem Manacher算法+穷举/set Manacher算法一好文:http://blog.csdn.net/yzl_rex/article/details/7908259 套一个Manacher算出回文半径数组p之后 有两种方法 穷举法: 枚举-1的点(依据题意仅仅必为偶数回文) 找在该点回文半径内与其相隔最远 而且回文半径等于他俩距离(即两点为中心的回文串同样) 的点 记录找到时的距离 不断枚举找最大值即为最大回文串长 串长/2*3即为答…
题目传送门 /* 题意:求形如(2 3 4) (4 3 2) (2 3 4)的最长长度,即两个重叠一半的回文串 Manacher:比赛看到这题还以为套个模板就行了,因为BC上有道类似的题,自己又学过Manacher算法,结果入坑WA到死 开始写的是判断是否 p[i]-1 <= p[i+p[i]-1]-1,但是没有想到这种情况:5 (5 1) (1 5) (5 1) 1 单靠最长回文半径是不行的,看了网上的解题报告知道,要从极端位置往回挪才行 给我的教训是只会套模板是没用的,要灵活的使用该算法.另…
题目传送门 /* 题意:题目讲的很清楚:When n=123 and t=3 then we can get 123->1236->123612->12361215.要求t次操作后,能否被11整除 同余模定理:每次操作将后缀值加到上次操作的值%11后的后面,有点绕,纸上模拟一下就行了 */ /************************************************ * Author :Running_Time * Created Time :2015-8-12 8…
题目传送门 /* 这题可以用stl的mutiset容器方便求解,我对这东西不熟悉,TLE了几次,最后用读入外挂水过. 题解有O(n)的做法,还以为我是侥幸过的,后来才知道iterator it写在循环内才超时了,囧! */ /************************************************ Author :Running_Time Created Time :2015-8-4 12:10:11 File Name :G.cpp ******************…
Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always be 1…
rt 稳定婚姻匹配问题 The Stable Marriage Problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 438    Accepted Submission(s): 222 Problem Description The stable marriage problem consists of matching m…
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到boundry,使得boundry * n_edge - sum_edge <= k/b, 或者建立s->t,然后不断extend s->t. /* 4729 */ #include <iostream> #include <sstream> #include <…
LCA+RMQ.挺不错的一道题目. 思路是如何通过LCA维护费用.当加入新的点u是,费用增量为dis[u]-dis[lca(u, lower_u)] - dis[lca(u, greater_u)] + dis[lca(lower_u, greater_u)].若beg[u]大于当前最大值或小于最小值,lower_u=min of current, greater_u = max of current. /* 5296 */ #include <iostream> #include <s…
A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 242959    Accepted Submission(s): 46863 Problem Description I have a very simple problem for you. Given two integers A and B, you…
The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2259    Accepted Submission(s): 795 Problem Description In the Kingdom of Silence, the king has a new problem. There are N citi…
Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 11405    Accepted Submission(s): 5418 Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, y…
Sempr == The Best Problem Solver? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1490    Accepted Submission(s): 970 Problem Description As is known to all, Sempr(Liangjing Wang) had solved mor…
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes…
Problem Description 度熊面前有一个全是由1构成的字符串,被称为全1序列.你可以合并任意相邻的两个1,从而形成一个新的序列.对于给定的一个全1序列,请计算根据以上方法,可以构成多少种不同的序列. Input 这里包括多组测试数据,每组测试数据包含一个正整数N,代表全1序列的长度. 1≤N≤200 Output 对于每组测试数据,输出一个整数,代表由题目中所给定的全1序列所能形成的新序列的数量. Sample Input 1 3 5 Sample Output 1 3 8 Hin…
A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 260585    Accepted Submission(s): 50389 Problem Description I have a very simple problem for you. Given two integers A and B, you…
Description Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all po…
Problem Description We once did a lot of recursional problem . I think some of them is easy for you and some if hard for you. Now there is a very easy problem . I think you can AC it. We can define sum(n) as follow: if i can be divided exactly by 3 s…
Problem Description In this problem you need to make a multiply table of N * N ,just like the sample out. The element in the ith row and jth column should be the product(乘积) of i and j. Input The first line of input is an integer C which indicate the…
Problem Description Given a sequence 1,2,3,--N, your job is to calculate all the possible sub-sequences that the sum of the sub-sequence is M. Input Input contains multiple test cases. each case contains two integers N, M( 1 <= N, M <= 1000000000).i…