随笔分类 - ---其他算法---
摘要:题目链接:poj1741_Tree 题意: 给你一颗n个节点的树,每条边有一个值,问有多少点对(u,v),满足u->v的最短路径小于k。 题解: 典型的树的分治,板子题。 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #
阅读全文
摘要:题目链接:hdu_5324_Boring Class 题意: 给出n个二维点对,求LIS长度和编号字典序最小的LIS(x非增,y非减) 题解: dp[i]=max(dp[j]) (i>j,l[i]>=l[j],r[i]<=r[i]) 一看就是三维偏序问题。 如果树套树写的好,空间开的大的话,一样可以
阅读全文
摘要:题目链接:hdu_5618_Jam's problem again 题意: 给你n个点,每个点有一个坐标(x,y,z),找出有ans个点,3个坐标都比该点小,这个点的level就为ans,然后让你输出所有点的ans. 题解: 对于第一维,直接排序,后面两维的处理可以用线段树套lowbit,但空间用的
阅读全文
摘要:题目链接:hdu_5968_异或密码 题意: 中午,不解释 题解: 前缀处理一下异或值,然后上个二分查找就行了,注意是unsigned long long 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;i++) 3 usi
阅读全文
摘要:题目链接:hdu_5878_I Count Two Three 题意: 给你一个n,让你找满足那个式子的不比n小的最小数 题解: 先上个预处理,然后二分查找就行 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;i++) 3
阅读全文
摘要:题目链接:hdu_5884_Sort 题意: 有n个数,每个数有个值,现在你可以选择每次K个数合并,合并的消耗为这K个数的权值和,问在合并为只有1个数的时候,总消耗不超过T的情况下,最小的K是多少 题解: 首先要选满足条件的最小K,肯定会想到二分。 然后是如何来写这个check函数的问题 我们要贪心
阅读全文
摘要:题目链接:hdu_5855_Less Time, More profit 题意: 有n个工厂,每建一个工厂要花费vi,需要时间ti,然后有m个商店,每个商店需要在指定的k个工厂中进货,才能盈利,如果其中一个不在,都不能盈利,问在满足利润大于等于k的情况下的最少时间t,和在t时刻的最大利润 题解: 二
阅读全文
摘要:题目链接:poj_1743_Musical Theme 题意: 给你一串数字,让你找最长的变化相同不重叠的子串,至少长度为5 题解: 处理数据后用后缀数组加二分答案,然后用height数组check答案,运用height数组求相同不重叠的子串经典运用 1 #include<cstdio> 2 #in
阅读全文
摘要:题目链接:hdu_5806_NanoApe Loves Sequence Ⅱ 题意: 给你一段数,问你有多少个区间满足第K大的数不小于m 题解: 直接双指针加一下区间就行 1 #include<cstdio> 2 #include<algorithm> 3 #define F(i,a,b) for(
阅读全文
摘要:B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output B. Powers of Two time l
阅读全文
摘要:C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n poin
阅读全文
摘要:C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output C. They Are Every
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1950 题意:实际就是求最长递增子序列 题解:有两种解法,一种是利用二分,一种是用线段树 这个是这题的二分代码: 1 #include <cstdio> 2 #include<algorithm> 3 #
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4521 题意:中文题,不解释 题解:这题就是LIS的加强版,可以用二分的nlogn来做,也可以用线段树的nlogn 做这个带间隔的LIS,具体看代码 1 #include<stdio.h> 2 #incl
阅读全文
摘要:题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #incl
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 题意:看了老半天,就是有N个饼,要分给f+1个人,每个人只能一样多,不能拼凑,多余的丢弃,问每个人最多能分到多少 题解:将最大的那个饼拿来二分,然后无限逼近满足能分出f+1个相同大小的饼 ,的最大
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2446 题意:题面很大,有用的就那么几句,意思就是用自然数来堆它画的那个金字塔,比如第一个金字塔的第一个数为1,第二个金字塔的第一个数为2,第三个金字塔的第一个数为5……。 题解:可以打表,最多有381W
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题意:叫你找三个数,使得这三个数的值为X,如果找得到就输出YES否则输出NO,注意两个32位数相加会爆int 1 #include<cstdio> 2 #include<algorithm> 3
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2899 题意:让你解方程 题解:对于只有一个凸或者没有凸的图像,可以直接上三分解决、 1 #include<cstdio> 2 #include<cmath> 3 double eps=1e-7; 4 i
阅读全文
摘要:D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The term of this pro
阅读全文

浙公网安备 33010602011771号