![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
文章平均质量分 62
helloJeremy1996
这个作者很懒,什么都没留下…
展开
-
UVA 11292_Dragon of Loowater
题目意思:给定两组序列A和B,长度分别为n和m。对于A中的每个数据都要在B中找出大于或等于这个值的不同的值,并是这些至之和最小。 解法:贪心+搜索. #include #include #include #include #include using namespace std; vector heads, knights; vector::iterator原创 2016-01-19 13:09:43 · 315 阅读 · 0 评论 -
POJ 1008_Maya Calendar
没什么算法技巧,理解题意,and convert the dates from the Haab calendar to the Tzolkin calendar. #include #include #include #include #include using namespace std; map Haab; void init(){ Haab.insert原创 2016-01-07 22:01:55 · 590 阅读 · 0 评论 -
POJ 1007_DNA Sorting
本题先求各个DNA序列的逆序数,再排序,这里是稳定排序(题目中说明了如果二者逆序数相同不改变相对位置)。So,这里用stable_sort(),not sort()。 之前一直wa,把输入方式getline(cin,string **)改为cin>>..结果AC了,that's strange ! #include #include #include using namespace原创 2016-01-07 18:50:12 · 303 阅读 · 0 评论 -
POJ 1002_487-3279
本题没什么特别的算法,只是用到map映射来快速查找,虽然AC了但是时间和空间还是用去了很多,还是希望将来能够再优化下。Ps,之前没看到只要一个test case导致Time Limit exceeded.以后做题时要更加小心审题了…#include <iostream> #include <map> #include <string> using namespace std;map<string,原创 2016-01-05 19:43:49 · 294 阅读 · 0 评论 -
POJ 1006_Biorhythms
本题没什么编程难点,主要就是采用了中国剩余定理解题。 在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2),问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”。下面说说我对该定理的理解。 首先确定3,5,7为俩俩互质的数,找出3和5的公倍数中最小的能使它%7=1的数,再找出3和7的原创 2016-01-07 12:52:57 · 347 阅读 · 0 评论 -
二分查找算法
1.二分法搜索指定元素在有序序列中的位置或待插入的位置. 2.模拟STL里的下界和上界查找函数lower_bound()和upper_bound(). #include #include #include #include #include #define MAX(a,b) (a)>(b)?(a):(b) using namespace std; int b原创 2016-01-22 16:33:46 · 328 阅读 · 0 评论 -
POJ 1005_I Think I Need a Houseboat
#include #include using namespace std; const float PI = 3.14159; int main() { int N,NUM; float sum = 0, posX, posY, year, radius; cin >> N; NUM = 0; while (N--){ NUM++; cin >> posX >> posY原创 2016-01-05 22:17:51 · 262 阅读 · 0 评论 -
POJ 1004_Financial Management
... #include using namespace std; int main() { float n,sum = 0; int i; for ( i = 0; i < 12; i++) { cin >> n; sum += n; } cout << "$"<<sum / 12.0 << endl; return 0; }原创 2016-01-05 21:31:09 · 386 阅读 · 0 评论 -
POJ1003_Hangover
水题... #include using namespace std; int main() { float n,sum; int i; while (cin >> n&&n!=0){ for (i = 0, sum = 0; sum < n; i++){ sum += 1.0 / (2 + i); } cout <<i<<" card(s)" <<原创 2016-01-05 20:14:01 · 322 阅读 · 0 评论 -
uva_201Squares
From now on...开始刷题啦!希望2016一切顺利,哈哈。 本题直接遍历所有可能的点,用h[][],v[][]两个数组存储题目所给的两点的关系,1代表这两点有线相连,0则没有。 唯一的缺点是本题for循环太多了,由于数据量比较小所以也没什么关系就是了。 不多说,直接上代码。原创 2016-01-02 19:35:27 · 271 阅读 · 0 评论 -
UVA 10881_Piotr's Ant
问题描述: 在L cm长的杆子上有n只蚂蚁,蚂蚁的移动速度为1 cm/s,题目并告知这些蚂蚁的初始位置pos及将要移动的方向L or R。如果两只蚂蚁相遇则各自方向倒置,即往原移动方向相反的方向移动。求最终各个蚂蚁的位置及最终方向。 解题方法: 根据题目意思,终止时刻每只蚂蚁相对其他蚂蚁的位置是稳定的,即一只蚂蚁不会穿过另一只蚂蚁。我们可以假设把每只蚂蚁看作一样的,因为其最终时刻的位原创 2016-01-20 16:22:45 · 299 阅读 · 0 评论 -
最大子列和问题
解法1: 直接枚举所有情况暴力求解问题 O (n^3) 解法2: 在解法1的基础上改善了局部求和方法,使用递推和式代替每次累加求和 O (n^2) 解法3: 采用分治法求解,将数列递归地一分为二,最大子列和就等于左边的最大子列和与右边的最大子列和与跨越中线的最大子列和的最大值。 O (n logN) 解法4: 采用在线扫描方法,从起点开始往终点扫描,记录当前的子列和,如果为负数原创 2016-01-20 21:56:48 · 393 阅读 · 0 评论 -
UVALive 3708_Graveyard
题目描述: 有个1000步距离的圆环,环上的两点之间的距离是一样的,及环上的点平分周长。题目给出初始点个数和将要加上点的个数,把初始的点调整下位置,然后把要加入点的接上,求总调整距离的最小值。 解题方法: 把圆环看成一维的坐标轴。计算原始点和加上附加点后所有的坐标数组P1,P2,对比P1中每个原始点两侧离P2中任意点最近的点,贪心的算出每个的最小调整距离,其之和就是结果。原创 2016-01-20 16:46:13 · 492 阅读 · 0 评论 -
UVA 11300_ Spreading the Wealth
把问题巧妙换成求解中位数问题,妙哉! #include #include #include #include #include #define MAX(a,b) (a)>(b)?(a):(b) using namespace std; const int MAXSIZE = 1000010; long long originCoins[MAXSIZE]; lon原创 2016-01-19 21:08:58 · 274 阅读 · 0 评论 -
UVA11729_Commando War
基本的贪心算法 之前把要求输出的Case xxx写成小写case,一直没发现..结果都是wa,气炸了。所以,做题一定要细心来 #include #include #include #include #include #define MAX(a,b) (a)>(b)?(a):(b) using namespace std; struct TimePoint{ i原创 2016-01-19 15:26:04 · 298 阅读 · 0 评论 -
字符串搜索--Rabin-Karp算法
该算法采用数字指纹的思想,欲求m位目标字符串 p 在文本T中相同子串的位置转化为求p的指纹fp与文本T中一个m位窗口子串的指纹ft的关系。 有以下假设: 1. 如果fp!=ft ,则p与该窗口子串不匹配 2. 可以在O (m) 时间内计算p的指纹fp 3. 可以在 O (1) 时间内比较fp 和 ft 的大小关系 4. 可以在 O (1) 时间内利用前一个ft 计算 窗口位移一位后子串的原创 2016-02-03 16:21:03 · 477 阅读 · 0 评论