上一页 1 ··· 4 5 6 7 8 9 10 11 下一页
摘要: Finding Nemo大意:有一个迷宫,在迷宫中有墙与门有m道墙,每一道墙表示为(x,y,d,t),x,y表示墙的起始坐标d为0即向右t个单位,都是墙d为1即向上t个单位,都是墙有n道门,每一道门表示为(x,y,d),x,y表示门的起始坐标d为0即向右一个单位表示门d为1即向上一个单位表示门再给出你起点的位置(f1,f2),并保证这个点的位置不会再墙或者门中,为起点到(0,0)最少要穿过多少条门思路:将坐标系看成网格,在这里我以每个格子的左下点为基点,那么坐标对应网格坐标(0,0)的网格为(1,1)坐标(1,1)的网格为(2,2)坐标(1,2)的网格为(2,3)...依次类推我再定义X[i] 阅读全文
posted @ 2013-11-27 16:22 GLSilence 阅读(337) 评论(0) 推荐(0) 编辑
摘要: Rectangle and Square大意:给你8个点,看里面能不能有一个正方形,一个矩形,如果有,输出YES和正方形点的编号和矩形编号,不能输出NO。PS:正方形和矩形的判断可以当做模板来使用 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define LL long long 10 using namespace std; 11 #define N 12 13 struct node 14 { 15 int x... 阅读全文
posted @ 2013-11-10 20:52 GLSilence 阅读(291) 评论(0) 推荐(0) 编辑
摘要: Monthly Expense大意:给你天数N(1 ≤ N ≤ 100,000),和每天需要花的钱(存放在数组中),让你把这些天分成M(1 ≤ M ≤ N)份(每份都是连续的天),要求每份的和最大值尽量小,输出这个和。思路:二分查找。让数组中的最大值为左界,数组的和为右界。左界的含义是将整个数组分成N块,那么和的最大值就是数组元素中的最大值。右界的含义是将整个数组当做一块,那么最大值就是所有数字之和。那么在左右界中(含左右界)的数肯定有一个是解。二分搜索:给定一个初始数mid,从数组首元素开始叠加,超出mid那么分组数i加1,那么这么遍历一遍后能得到以mid为解所需的分组数,要是i小于M,说明 阅读全文
posted @ 2013-11-09 17:18 GLSilence 阅读(247) 评论(0) 推荐(0) 编辑
摘要: Monkey and Banana大意:把给定的长方体(不限个数)叠加在一起,上面的长和宽比下面的长和宽短,求这些长方体加起来的最高高度。思路:每个格子最多3个状态,也就是高最多有3种,也就是一共有N*3 最多90个格子,但是X和Y可以对调,那么就最多180个,对180个格子对X从小到大排序,X相等,Y就从小到大排序,那么这个问题就可以转换成类似求最大递增子序列问题一样思路的DP,DP[i]表示第i个格子时的最大值,dp[i+1]就是从前i个中找符合条件的最大的一个加上去。 1 #include 2 #include 3 #include 4 #include 5 #include ... 阅读全文
posted @ 2013-11-09 14:56 GLSilence 阅读(159) 评论(0) 推荐(0) 编辑
摘要: Largest Rectangle in a Histogram大意:找到面积最大的矩形思路:对于每一个a[i],用dp找出a[i]左边和右边连续大于自己的数的长度 l[i]表示比a[i]大的数连续的最左边的位置 r[i]表示比a[i]大的数连续的最右边的位置 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define LL __int6410 using namespace std;11 12 LL a[100010], dp_l[... 阅读全文
posted @ 2013-11-08 19:45 GLSilence 阅读(211) 评论(0) 推荐(0) 编辑
摘要: Bone Collector最基本的01背包 两种实现都要掌握的很熟练!二维数组实现01背包: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define LL long long10 using namespace std;11 12 int dp[1010][1010];13 14 void run()15 {16 int p, n, m;17 int a[1010], b[1010];18 scanf("%d",... 阅读全文
posted @ 2013-11-06 20:03 GLSilence 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 饭卡思路:先把最贵的一个拿出来,剩下的用背包求出最优解,用5元去买最贵的。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define LL long long10 using namespace std;11 12 void run()13 {14 int n, m;15 int a[1010], dp[1010];16 while(~scanf("%d", &n) && n)17 {18 in... 阅读全文
posted @ 2013-11-06 16:56 GLSilence 阅读(189) 评论(0) 推荐(0) 编辑
摘要: The Twin TowersLCS水题,就是题读的时候有点费劲。 我英语是渣渣- -! 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define LL long long10 using namespace std;11 12 void run()13 {14 int n, m;15 int dp[110][110];16 int a[110], b[110];17 int cnt = 0;18 w... 阅读全文
posted @ 2013-11-06 09:40 GLSilence 阅读(160) 评论(0) 推荐(0) 编辑
摘要: GCC大意:给一个n,一个m,求(0! + 1! + 2! + 3! + 4! + ... + n!)%m 0 m,那么m!+(m+1)!+...+n!这些项都是可以被m整除的,要对m求余,只需要找比m小的阶乘即可,而m的范围为1000000,在O(m)的复杂度下是可以完成的。所以只需判断n是否... 阅读全文
posted @ 2013-11-04 23:47 GLSilence 阅读(446) 评论(2) 推荐(0) 编辑
摘要: Paths on a Grid大意:矩形方格,从左下角走到右上角,只能向上或向右,问一共有多少种情况。思路:排列组合,每一个点的不同走法的总数,是由左边的点和下边的点的总数之和,这就很容易联想到排列组合的一个公式:,其中,n为走到这点所总共经过的边数(不分横边竖边),r可以看为已经走过的横边或者竖边。即有n = a + b,r = a 或者 r = b。#include #include #include #include #include #include #include #include #define LL long longusing namespace std;LL C(LL x, 阅读全文
posted @ 2013-11-04 21:18 GLSilence 阅读(248) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 下一页