上一页 1 2 3 4 5 6 7 8 9 10 ··· 12 下一页

2012年8月8日

poj2352(树状数组)

摘要: 2011-08-08 20:01:28第一道树状数组,赤裸裸的树状数组题目大意看了半天啊,曾一度想找个学英语的给我翻一下,原来看题都没有觉得这么难理解这里贴一个有翻译的链接:http://www.docin.com/p-270244818.html其实这道题图的样子和树状数组的图的样子是一样的,都是求左边的和下面的之和,画个图或许可以帮助理解 1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 int c[32005]; 5 int lowbit(int x) 6 { 7 return 阅读全文

posted @ 2012-08-08 20:06 矮人狙击手! 阅读(588) 评论(0) 推荐(0) 编辑

树状数组

摘要: 转自:http://www.cnblogs.com/yykkciwei/archive/2009/05/08/1452889.html#commentform(有删改)问题提出:已知数组a[],元素个数为n,现在更改a中的元素,要求得新的a数组中i到j区间内的和(1<=i<=j<=n).思考:对于这个问题,我们可以暴力地来解决,从a[i]一直累加到a[j],最坏的情况下复杂度为O(n),对于m次change&querry,合起来的复杂度为O(m*n),在n或m很大的情况下,这样的复杂度是让人无法忍受的.另外,如果没有元素的变更,我们完全可以存储sum[1,k](k=1 阅读全文

posted @ 2012-08-08 17:08 矮人狙击手! 阅读(198) 评论(0) 推荐(0) 编辑

hdu4339(线段树)

摘要: 线段树啊,有是线段树,有点东西老是搞不懂,build,update ,query,这三个函数到底怎么写,还是不太懂啊有时候看代码真的很抽象,画个图或许可以帮助理解 1 #include <iostream> 2 #include <string.h> 3 #include <cstring> 4 #include <stdio.h> 5 using namespace std; 6 char b[1000005],f[1000005]; 7 int first,a,d; 8 int min(int a ,int b) 9 { 10 return 阅读全文

posted @ 2012-08-08 16:15 矮人狙击手! 阅读(367) 评论(0) 推荐(0) 编辑

2012年8月7日

poj2709

摘要: 确实是水题一道,今天早上没吃饭,看题看了好半天题意:有个卖玩具的店里有一种类似颜料盒的东东,颜料盒的颜色种数从3到12不等,每种颜料有50ml。有一种很特别的颜色叫做灰色,任何一种颜料盒里本来不存在这种颜色,但是可以用任意3种不同的颜色混合而成。现在你需要N种颜色的颜料盒,并且每种颜料的需求量也给定,包括灰色,让你求出需要的最少的该颜料盒的个数思路:如果有灰色,在前面的颜色中选择三种最小的,分别加1,灰色减一,直到灰色为零 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 in 阅读全文

posted @ 2012-08-07 11:11 矮人狙击手! 阅读(265) 评论(0) 推荐(0) 编辑

poj2497(买一送一poj2593)

摘要: 1 #include <stdio.h> 2 int main() 3 { 4 int left[100005]; 5 int right[100005]; 6 int a[100005]; 7 int Case; 8 scanf("%d",&Case); 9 while(Case--)10 {11 int n,i;12 scanf("%d",&n);13 if(n==0) break;14 for(i=0;i<n;i++)15 {16 ... 阅读全文

posted @ 2012-08-07 09:42 矮人狙击手! 阅读(263) 评论(0) 推荐(0) 编辑

2012年8月6日

poj2593

摘要: 题目链接:http://poj.org/problem?id=2593动态规划大意:给你一个数列,求数列中两个不重叠的子序列的最大和。 从左向右求得left[]数组,left[i]表示0~i之间的最大连续子序列。再从右往做左求最大子序列,然后求0~i,i+1~n-1的两段子序列中的最大和。 1 1 #include <stdio.h> 2 2 int main() 3 3 { 4 4 int left[100005]; 5 5 int right[100005]; 6 6 int a[100005]; 7 7 8 8 while(1) 9 ... 阅读全文

posted @ 2012-08-06 21:24 矮人狙击手! 阅读(981) 评论(0) 推荐(0) 编辑

qsort()与sort()

摘要: 转自:http://blog.163.com/fzu_q_q/blog/static/18645105720115270952949/sort和qsort使用差别2011-06-27 00:09:52|分类:默认分类|字号订阅一、对int类型数组排序int num[100];Sample:int cmp ( const void *a , const void *b ){return *(int *)a - *(int *)b;}qsort(num,100,sizeof(num[0]),cmp);二、对char类型数组排序(同int类型)char word[100];Sample:int cm 阅读全文

posted @ 2012-08-06 18:30 矮人狙击手! 阅读(1857) 评论(0) 推荐(1) 编辑

map

摘要: 转自:http://www.cnblogs.com/skynet/archive/2010/06/18/1760518.htmlMap是标准关联式容器(associativecontainer)之一,一个map是一个键值对序列,即(key ,value)对。它提供基于key的快速检索能力,在一个map中key值是唯一的。map提供双向迭代器,即有从前往后的(iterator),也有从后往前的(reverse_iterator)。map要求能对key进行<操作,且保持按key值递增有序,因此map上的迭代器也是递增有序的。如果对于元素并不需要保持有序,可以使用hash_map。map中ke 阅读全文

posted @ 2012-08-06 12:22 矮人狙击手! 阅读(352) 评论(0) 推荐(0) 编辑

poj2028

摘要: 水题一道啊,一次AC啊 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 int main() 7 { 8 int a[105]; 9 int res[105];10 int n,q,m;11 int i,j;12 while(1)13 {14 cin>>n>>q;15 if(n==0 && q==0) break;16 memset(res,0,sizeof(r... 阅读全文

posted @ 2012-08-06 10:45 矮人狙击手! 阅读(145) 评论(0) 推荐(0) 编辑

poj1083

摘要: 水题一道,看清房间到底是怎么分布的看清了啊,我就是第一次没有看清这才wa的 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int cmp (int a,int b) 7 { 8 return a>b; 9 }10 int main()11 {12 int Case;13 cin>>Case;14 int from, to;15 int room[405];16 int i,j;17 while(Ca.. 阅读全文

posted @ 2012-08-06 09:57 矮人狙击手! 阅读(164) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 9 10 ··· 12 下一页

导航