自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

傻笨

我是菜鸟,但我是勤奋的菜鸟

  • 博客(297)
  • 收藏
  • 关注

原创 区间取点问题

数轴上有n个闭区间[ai,bi]。取尽量少的点,使得每个区间内都至少有一个点(不同区间内含的点可以是同一个)。例题如下:N one dimensional kingdoms are represented as intervals of the form [ai , bi] on the real line.A kingdom of the form [L, R] can be destro

2015-01-11 16:11:00 1142

原创 UVA 11292 和 UVA 11729

最近开始刷刘汝佳的大白书,这两道

2014-05-15 21:43:49 634

原创 1038. 二哥的约瑟夫

http://acm.sjtu.edu.cn/OnlineJudge/problem/1038好久没写过博客了,搞了这么久的算法,觉得自己还是不会灵活运用,这题用树状数组+二分;如果想到了,并且思路清晰的话,那就比较简单,可是我一开始根本就不会往这个方面就想;后来还是问了队长,队长直接告诉了我想法,然后拍出来了,哎,自己怎么这么弱啊!!这题思路;这题先用树状数组来标记,然后二分来查找,

2014-03-31 21:19:29 1206

原创 set 容器的巧妙利用

Egg pain's hzfTime Limit: 3000MS Memory Limit: 65535KBSubmissions: 45 Accepted: 10Descriptionhzf is crazy about reading math recently,and he is thinking about a

2013-12-27 15:54:48 639

原创 ACM俱乐部算法基础练习赛(4)

问题 A : 解密信息时间限制:1 秒内存限制:32 兆特殊判题: 否提交:67解决: 20标签简单模拟题目描述一天,小明收到了小红给他发来的一封邮件,但是大眼看上去是一堆乱码,不过在邮件的最后小明看到了小红写的邮件解密的方法,举例如下:给出一串解密key,例如yrwhsoujgcxqbativndfezmlpk。这串解密key的意思就是邮件中的‘a’实际上应该是‘y’,邮件中的‘b

2013-12-10 18:31:46 1219

原创 Codeforces Round #218 (Div. 2) B题

这题真SB了,就一个地方判断错了,好不容易想出来的方法!!什么都不说了!!一开始错的代码:#include #include #include #include #include using namespace std;int n,k;int main() {    while(scanf("%d%d",&n,&k)!=EOF) {        int

2013-12-08 21:49:12 599

原创 HDU 1087 最大子序列和

#include #include #include #include using namespace std;const int maxx=1005;int n,a[maxx],dp[maxx];int main() { int maxn; while(scanf("%d",&n),n) { memset(dp,0,sizeof(dp));

2013-12-06 20:29:14 557

原创 HDU 1257 最长上升子序列

#include #include #include #include using namespace std;const int maxn=30005;int n,a[maxn],f[maxn];int bsearch(int* f,int size,int& a) { int left=0; int right=size-1; while(left<=

2013-12-06 19:10:39 647

原创 HDU 1025 最大递增子序列长度

这道题目一开始我的是复杂度为 n^2的DP,发现超时了,于是去学了,nlgn的DP+二分的方法,一开始样例过了,我还以为自己写对了,后来交上去却WA了,原来对这个还是理解不是太深,写起来有个地方没有理解清楚后来慢慢看懂了!!!!其实这个原理很简单,就是先比较一头一尾,然后进行二分,找到其中第一个比他大的数,然后拿这个数替换掉那个比他大的数,一直进行这样,时间就会减少!!!!

2013-12-06 18:57:58 493

原创 HDU 1054

这道题目是二分匹配,我一开始用的是邻接矩阵,却交上去超时了, 于是我想到教主说的用vector来存二维数组,但是不太熟悉,后来 看了匡斌的博客里面就有这样写的模板,就看了看, 代码如下: #include #include #include #include #include using namespace std;const int maxn=1505;int dis

2013-12-03 21:32:29 630

原创 1000. Clumsy Cows

1000. Clumsy CowsTotal: 71 Accepted: 33Time Limit: 1sec Memory Limit:256MBDescriptionBessie the cow is trying to type a balanced string of parentheses into her new laptop, but she is suffici

2013-11-23 20:39:07 846

原创 RQNOJ Mato完整版学体育

这是好坑的题目啊!!最近在练邻接表写最短路的题目。http://www.rqnoj.cn/problem/398 题目链接由于这题的最后一组数据有问题,所以就只好cheat了#include #include #include #include #include using namespace std;const int inf=0x3f3f3f3f;const int

2013-11-20 14:16:13 1124

原创 最短路

这题题目如下:9360. HIPERCIJEVIConstraintsTime Limit: 4 secs, Memory Limit: 256 MBDescriptionIn a galaxy far, far away, the fastest method of transportation is using hypertubes.

2013-11-19 17:10:55 885

原创 HDU 3242 两个字符串的相加和相减

这道题目可以利用 vetor来做,因为它是动态的数组,可以进行插入和删除及更多功能#include #include #include #include #include #include using namespace std;string str1,str2,str3;vectorvt;vector::iterator it;void push(string st

2013-11-16 18:44:39 1069

原创 成都站现场赛——题目重现 Hard Disk Drive

题目如下:Hard Disk DriveTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0Problem DescriptionYesterday your dear cous

2013-11-16 13:34:42 750

原创 Codeforces Round #212 (Div. 2) A题

这道题目其实蛮简单的,我比赛的时候一看到这个题目就想到用广搜,可是错在第三组数据上了,后面就没怎么想了,原来题目有两个条件很重要,我却没看,导致CF只刷了一题,今天晚上重做这题时,看到了这两个条件,就把它给AC 了!!这两个条件是:'#'这个不能加入判断,因为题目中说可以穿过‘#’,还有就是两个人同时动,所以利用广搜的思路,一个人不动,另一个人去搜他,然后判断步数是不是偶数,如果是奇数的

2013-11-15 18:48:48 758

原创 HDU 2531 BFS

#include #include #include #include using namespace std;const int N=110;const int M=10010;char s[N][N];int n,m,ans;int vis[N][N];int dir[4][2]= {{0,1},{0,-1},{1,0},{-1,0}};int px[M],py[M];

2013-11-14 20:35:32 518

原创 HDU 1429 BFS+状态压缩

#include #include #include #include #include #include using namespace std;const int N=21;const int KEY=10;char s[N][N];int dir[4][2]= {{0,1},{0,-1},{1,0},{-1,0}};int n,m,k;bool hash[N][N][

2013-11-13 16:49:16 563

原创 HDU 4771 BFS+状态压缩

这题意思就是求出从起点到所给出来的点的所有点的最少路径数#include #include #include #include #include using namespace std;const int N=105;int n,m,k;int dir[4][2]= {{0,1},{0,-1},{1,0},{-1,0}};char s[N][N];int p[N][N];

2013-11-13 14:20:36 577

原创 HDU 2216 有意思的BFS

这道题目 首先得看懂题目意思,还有一个就是 知道怎么判断 该点在你点的附近,代码如下:#include #include #include #include #include #include #include using namespace std;const int N=30;char s[N][N];int n,m;int dir[4][2]={{0,1},{0,-

2013-11-08 18:25:29 710

原创 HDU 2653 BFS+优先队列

/* 这题题意:告诉起点Y的位置,然后告诉终点L的位置,然后输入 n, m, t ,p,其中 n和m是代表行和列,而t 是时间,p代表能量,如果在t范围内没有找到L的话,就失败了,如果在t范围内找到了L,那么求出最少步数, .代表空地,可以走路过去,也可以飞过去,#代表不能走路过去,也不能飞过去,而@代表的是可以飞过去,但不能 走路过去,所以要广搜的同时要用到优先队列,

2013-11-06 16:45:48 553

原创 HDU 1973 BFS+素数打表

思路:先素数打表,把1到10005范围内的素数找出来,然后把要输入的两个数当做字符串输入,然后进行广搜广搜的思路就是,把每一位数都变化一下,存入队列中,然后不断的比较,就可以得出结果了!!!!#include #include #include #include #include #include using namespace std;const int maxn=10005

2013-11-06 13:10:19 637

原创 HDU 2209

这个题目,一开始以为好难,看别人的思路,要分两种情况,就是第一种:第一张牌翻过来 第二种:第一张牌不翻过来,然后当i-1张牌全部翻过来了,只要考虑第i张牌时正的,还是反的就可以了第一种写法,搜索(递归)#include #include #include #include using namespace std;const int inf=0x3f3f3f3f;char s

2013-10-24 16:55:58 567

原创 HDU 1035 简单搜索,

/* 这题看起来好吓人,但是慢慢看下去,会发现就是简单那的 模拟题,也可以说是简单的搜索,不过搜索的方向是题目告诉的 方向,只要判断两个点就够了,一是直接出去的时候, 二是:当在某个时候一直在里面循环!! */#include #include #include #include using namespace std;char s[12][12];

2013-10-23 17:01:28 526

原创 RQNOJ 金明的预算方案 (分组背包)

这道题目 意思要好好看,好好研究一下,然后慢慢想想,你会发现比较简单!我一开始没有做出来,然后看了大牛的博客,那天晚上不知道怎么死都看不进去,看不懂,第二天我先好好看了一下题目,发现了这句话(q是所属主件的编号),其实这道题目是在另外一道简单的 01背包上改编而来的,原题大概意思是:告诉 N和M;N表示总钱数,M表示希望购买物品的个数;然后就是从第2行到第m+1行,第j行给出了编号为j-

2013-10-13 11:54:11 785

原创 Codeforces Round #119 (Div. 2) A题

/* 当我看到这题时,我懂意思了,题意就是:给你一条长度n的丝带,然后让你切断,但是切断 后的丝带长度必须是给出的三个数据中的长度。 题目意思很简单,可我却没有什么思路,傻逼了,后来看了别人的解题报告, 发现自己真心好水啊!!抓狂!!! 暴力来做,也叫枚举,先枚举 a 和 b 的数量 然后再算 C 数量,然后进行比较 就可以计算出结果!!!*/#incl

2013-10-11 17:28:40 516

原创 HDU 1423 最大公共递增子序列长度

#include#includeint a[510],b[510];int dp[510];//这个数组表示每个i位置的最大公共递增子序列的长度int main(){ int t,m,n,i,j; scanf("%d",&t); while(t--) { scanf("%d",&m); for(i=1; i<=m; i++)

2013-10-10 22:33:28 453

原创 HDU 1159 && poj 1458

这是两道最简单的最基础的求最大公共子序列的长度:/* 对于求最大公共子序列长度 if(a[i-1]==b[j-1]) { dp[i][j]=dp[i-1][j-1]+1;//这里比较好理解,当a[i-1]==b[j-1],那么自然dp[i][j]+1 }

2013-10-10 16:42:21 521

原创 HDU 1069 DP

/* 这题题目大意是:输入一个 n ,然后n组 a b c,然后让你随意组成长方形, 然后求出你组合的这些长方形叠起来的最大高度,能够叠起来的条件是( xx>x,yy>y); 思路:因为一组数据就可以有6种组合,所以可以把所有的组合弄出来, 然后按照 x的大小排序,然后从最大的x这种长方形作为基底,*/#include #include #inc

2013-10-09 17:15:36 463

原创 HDU 1058

#include #include #include #include using namespace std;int a[5850];int n;int min1(int a1,int a2,int a3,int a4){ if(a1<=a2&&a1<=a3&&a1<=a4)return a1; else if(a2<=a1&&a2<=a3&&a2<=

2013-10-08 21:08:57 561

原创 HDU 2084 基础DP

这题思路就是从倒数第二层往上推,因为这题只能从相邻走,所以只有两种选择,同样也有一个状态转移方程:a[i][j] += max(a[i+1][j],a[i+1][j+1])#include #include #include #include using namespace std;const int maxn=105;int a[maxn][max

2013-10-08 20:14:45 568

原创 HDU 1176 基础DP

由于刚开始搞DP,看了一下大牛的思路,才写出这题,这题中这人移动有三种方法,要么不移动,要么向左移动,要么向右移动,那么用a[i][j]表示的是在i秒j点有多少个饼掉下来,f[i][j]表示的是直到在i秒j点一共接到多少个饼,就可以写出一个状态方程,也就是关键解题思路:f[i][j]=max(f[i-1][j-1],f[i-1][j],f[i-1][j+1])+a[i][j];

2013-10-08 19:51:03 507

原创 HDU 1864 01背包

#include #include #include #include using namespace std;const int maxn=5000005;int f[maxn];int num[50];double q;int t;int main(){ int i,j,n,m; double x; int ta,tb,tc,r; ch

2013-09-22 20:27:06 539

原创 Codeforces Round #197 (Div. 2) A题

擦,这题有个地方搞了好久,主要是一个地方不知道,就是字符串如果定义为全局变量就是全部为 \0, 如果定义为局部变量就只有在字符串的末尾是\0;哎!解题报告:#include #include #include #include #include using namespace std;int main(){ char s[105]; int a[100],i

2013-09-21 16:29:47 425

原创 Codeforces Beta Round #25 (Div. 2 Only) A题

这题只要看懂了意思,一分钟就可以A掉,我一开始理解错了题目意思,还是我同学告诉我的,这题大概意思就是:给你一个n,然后有n个数,这n个数中,要么只有一个偶数,要么只有一个奇数,找出这一个偶数或者奇数的位置!!代码如下:#include #include #include using namespace std;int s[105];int main(){ int n

2013-09-21 15:32:29 511

原创 poj 3628 01背包

这道题目的意思看了好久,看了discuss后,写了一下,竟然WA了,后来看了别人的博客才发现与我所理解的意思刚好相反!!英语不行真命苦啊!!这里我大致说一下题目意思:输入 n 和 b,其中n是指奶牛的数量,b则是指书架的高度,然后奶牛之间叠罗汉,找出超出书架的值中取最小的!!代码如下:#include #include #include #include using namesp

2013-09-12 21:21:45 599

原创 POJ 3624 01背包入门题目

#include #include #include #include using namespace std;const int maxn=15005;int value[3500],cost[3500];int f[maxn];int n,m;void zeropack(int cost1,int value1){ for(int i=m; i>=cost1;

2013-09-12 20:27:11 658

原创 HDU 3732 多重背包

这道题目意思很简单就是:输入 N 和 C ,N是代表N行,而C是复杂性,输入一些单词,然后告诉这些单词的价值,还有这些单词的复杂性! 一开始我一看这个题目就以为是01背包,然后就马上写完,第一组测试数据过了,但是却WA!后来看别人的博客,发现用多重背包,就想想,后来想通了,首先用01背包做第一组数据之所以能过,是因为第一组数据没有给出重复的单词,如果给出重复的单词就会出现数目的问题,就不能用

2013-09-12 18:40:40 733

原创 HDU 1059多重背包

#include #include #include #include using namespace std;const int maxn=200005;int cost[10],value[10];int f[maxn];int a[7];int v;void zeropack(int cost1,int value1){ for(int i=v; i>=co

2013-09-11 22:13:52 492

原创 HDU 2191 多重背包

这道题目以前也看过,但是没学多重背包,就没做,今天做一下,思路要清晰,一定要搞清楚,谁是背包容量,这里背包容量就是所带的钱,单价是cost,粮食的重量是value,代码如下:#include #include #include #include using namespace std;const int maxn=20005;int value[maxn],cost[maxn],

2013-09-11 18:16:21 479

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除