摘要:题目链接:http://poj.org/problem?id=2828解题思路:线段树(单点更新) 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: poj 2828 4 problem_name: Buy Tickets 5 **************************************************************************/ 6 7 #inc...
阅读全文
摘要:解题思路:贪心 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: uva 10340 4 problem_name: All in All 5 **************************************************************************/ 6 7 #include 8 #include 9 #include 10 #include 11 #incl...
阅读全文
摘要:解题思路:记 f(n) 为 0~n 里的正完全平方数,则 f(n)=(int)sqrt(n). 则 a~b 里的正完全平方数个数为 f(b)-f(a-1). 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: uva 11461 4 problem_name: Square Numbers 5 ***********************************************************
阅读全文
摘要:解题思路:直接判断最大公约数是否整除最小公倍数,若是,输出最大公约数和最小公倍数,否则输出 -1 . 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: uva 11388 4 problem_name: GCD LCM 5 **************************************************************************/ 6 7 #include 8 #..
阅读全文
摘要:解题思路:二分 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: uvalive 3635 4 problem_name: Pie 5 **************************************************************************/ 6 7 #include 8 #include 9 #include 10 #include 1...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795解题思路:线段树(单点更新) 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: hdoj 2795 4 problem_name: Billboard 5 ************************************************************************...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150解题思路:Konig 定理:二分图的最小顶点覆盖数等于最大匹配数。 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: hdoj 1150 4 problem_name: Machine Schedule 5 **********************************************...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063解题思路:二分图匹配(匈牙利算法DFS实现) 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: hdoj 2063 4 problem_name: 过山车 5 **********************************************************************...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112解题思路:SPFA 算法(邻接矩阵) 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: hdoj 2112 4 problem_name: HDU Today 5 ********************************************************************...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874解题思路:SPFA 算法(邻接矩阵) 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: hdoj 1874 4 problem_name: 畅通工程续 5 ************************************************************************...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544解题思路:SPFA 算法(邻接矩阵) 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: hdoj 2544 4 problem_name: 最短路 5 **************************************************************************...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394解题思路:由于数据较小,可直接暴力求逆序数,也可用归并排序求逆序数。本文采用的解法为线段树(单点更新) 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: hdoj 1394 4 problem_name: Minimum Inversion Number 5 ********************...
阅读全文
摘要:题目链接:http://codeforces.com/problemset/problem/244/B解题思路:DFS 搜索 1 /************************************************************************** 2 user_id: SCNU20102200088 3 problem_id: codeforces 244B 4 p...
阅读全文
摘要:题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1060解题思路:拓扑排序 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: zoj 1060 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6...
阅读全文
摘要:解题思路:STL —— priority_queue 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 11997 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include 10...
阅读全文
摘要:解题思路:STL —— priority_queue 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uvalive 3135 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include ...
阅读全文
摘要:解题思路:将 1~1000 的因子和打表(类似素数筛法) 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 11728 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include 10 #includ...
阅读全文
摘要:解题思路:扩展 gcd 或者 直接判断 x%k 是否等于 0, 若是,可取 p=0, q=k; 否则,可取 p=-x, q=x. 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 10673 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #includ..
阅读全文
摘要:解题思路:三分 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uvalive 5009 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include 10 #include 11 #i...
阅读全文
摘要:解题思路:二分 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 10341 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #inc...
阅读全文
摘要:解题思路:矩阵快速幂 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 10870 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include 10 #include 11 #i...
阅读全文
摘要:解题思路:设一开始只有 1 只麻雀,i 天后全部死亡的概率为 f(i). 则有:f(0)=0, f(1)=p0, f(i)=p0+ p1· f(i-1)+p2· f(i-1)2+··· + pn-1· f(i-1)n-1 . 则本题答案为 f(m)k . 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 11021 3 //user_id: SCNU20102200088 4 ///////
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2844解题思路:背包 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: hdoj 2844 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203解题思路:01背包 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: hdoj 1203 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546解题思路:贪心+01背包 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: hdoj 2546 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602解题思路:01背包 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: hdoj 2602 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757解题思路:矩阵快速幂 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: hdoj 1757 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #in...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4430解题思路:二分 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: hdoj 4430 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #inclu...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4282解题思路:二分 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: hdoj 4282 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #inclu...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3750解题思路:二分 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: hdoj 3750 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199解题思路:二分 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: hdoj 2199 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #...
阅读全文
摘要:解题思路:对于 1~n, 保留 1~n/2, 把剩下的数同时减去 n/2+1, 得到 1, 2,···, n/2, 0, 1,···, (n-1)/2. 它等价于1, 2,···, n/2. 因此有如下递推关系:cal(1)=1, cal(n)=cal(n/2)+1 (n>=2). 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 11384 3 //us
阅读全文
摘要:解题思路:把每个雕塑移动到离他最近的位置 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uvalive 3708 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include 10 #include 11 ...
阅读全文
摘要:解题思路:给定数轴上的 n 个点,中位数离所有点的距离之和最小 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 11300 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include 10 #inc...
阅读全文
摘要:解题思路:按照 J 从大到小的顺序给各个任务排序,然后依次交代 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 11729 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include 10 #inc...
阅读全文
摘要:解题思路:排序后使用贪心算法 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 11292 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include ...
阅读全文
摘要:解题思路:STL —— vector, map 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 11991 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include 9 #include 10 #include 11 ...
阅读全文
摘要:解题思路:STL —— stack, queue, priority_queue 1 /////////////////////////////////////////////////////////////////////////// 2 //problem_id: uva 11995 3 //user_id: SCNU20102200088 4 /////////////////////////////////////////////////////////////////////////// 5 6 #include 7 #include 8 #include ...
阅读全文