随笔分类 -  数据结构

FZU 2079 最大获利
摘要:线段树优化DP是dp[i]=max{dp[j]+w[j+1][i],dp[i-1]},其中1=<i<=n,0=<j<=j-1;dp[i]表示前i个项目的最大获利,w[j][i]表示项目j到i全部投资的获利。#include<stdio.h> #include<string.h> #include<stdlib.h> typedef long long ll; int n,m; int a[20010]; struct Item{ int l,r; ll v; }item[20010]; ll dp[20010],w[70010],p[ 阅读全文

posted @ 2012-04-29 13:22 c语言源码 阅读(214) 评论(0) 推荐(0)

BOJ 394
摘要:Problem I. The Longest Sequence ofRectanglesDescriptionA rectangle is specified by a pair of coordinates (x1 , y1) and (x2 , y2)indicating its lower-left and upper-right corners (x1 <= x2 and y1 <= y2). Fora pair of rectangles, A = ((X_A1, Y_A1), (X_A2, Y_A2)) and B = ((X_B1, Y_B1),(X_B2, Y_B2 阅读全文

posted @ 2012-03-24 19:10 c语言源码 阅读(177) 评论(0) 推荐(0)

ural 1846. GCD 2010
摘要:简单线段树。用sort+unique离散化(注意要erase)#include<cstdio> #include<vector> #include<algorithm> #define con 100100 using namespace std; int op[con],pos[con],sum[con],n; vector<int> in; int tree[270010]; int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } void insert(int s,int 阅读全文

posted @ 2012-02-24 13:09 c语言源码 阅读(292) 评论(0) 推荐(0)

zoj 3453 Cupid's Sweet Bullet
摘要:简单线段树,成段更新#include <cstdio> #define con 100100 using namespace std; int em[con],l[con],r[con],n; struct Tree{ int s; int t; int max; int add; }tree[270010]; int max(int a,int b){ return a>b?a:b; } void build(int s,int t,int id){ tree[id].s=s;tree[id].t=t; tree[id].add=0; if(s==t){ tree[id]. 阅读全文

posted @ 2012-02-24 00:08 c语言源码 阅读(120) 评论(0) 推荐(0)

POJ 1840 Eqs
摘要:思路:a1x1^3+ a2x2^3+ a3x3^3 = -(a4x4^3 + a5x5^3)先求出右边能到达的值,对值进行hash,然后左边查询计数,这样比相反的顺序内存少用好多,时间也快不少#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #define inf 20003 int Max(int a,int b){ return a>b?a:b; } int Min(int a,int b){ return a>b?b:a; } int 阅读全文

posted @ 2012-02-18 17:35 c语言源码 阅读(235) 评论(0) 推荐(0)

BOJ 262 Channel Coding
摘要:DescriptionAssume an integer sequence contains N elements whose value could only be one of {0, 1, -1}. There may exist a positive integer D which can make the sum between i-th element and (i+D)-th element be zero, where i is a certain integer between 1 and N-D. Your task is to find out the maximal D 阅读全文

posted @ 2012-02-18 17:32 c语言源码 阅读(178) 评论(0) 推荐(0)

POJ 3274 Gold Balanced Lineup
摘要:hash存储,查询,跟POJ 3349类似#include<stdio.h> #include<stdlib.h>; #include<string.h> #define inf 100001 struct Edge{ int pos[32],next; }edge[100100]; int head[100100],max,num[100100],k; int Max(int a,int b){ return a>b?a:b; } int add(int b,int pos){ int i,j; int hash=b%inf; for(i=head[ 阅读全文

posted @ 2012-02-18 14:23 c语言源码 阅读(143) 评论(0) 推荐(0)

POJ 3349 Snowflake Snow Snowflakes
摘要:简单hash#include<stdio.h> #include<stdlib.h>; #include<algorithm> #define inf 100001 using namespace std; struct Edge{ int a[10],next; }edge[100100]; int a[10],head[100100],cnt; bool add(int * b){ int sum=0,i,j,p,q; for(i=0;i<6;i++) sum+=b[i]; int hash=sum%inf; for(i=head[hash];i; 阅读全文

posted @ 2012-02-18 11:06 c语言源码 阅读(418) 评论(0) 推荐(0)

导航