上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 23 下一页
摘要: Description有三个无刻度标志的水杯,分别可装 a ,b , c升水,并且a>b , a>c , a,b,c,均为正整数。任意两个水杯之间可以相互倒水。用杯子x给y倒水的时必须一直持续到把杯子y倒满或者把杯子x倒空,而不能中途停止。倒水过程中水量不变。最初的时候只有大杯子装满水,其他两个杯子为空。问能不能量出x升水,如果可以,最少需要多少步?Input输入有多组数据。每组数据为一行,有4个正整数a,b,c,x且满足:a>b,a>c,a>x,a,b,c,x <= 1000。Output输出一个整数。如果可以量出x升水,输出需要的最少步骤,否则,输出-1 阅读全文
posted @ 2012-07-18 17:03 BeatLJ 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 这题是ZOJ 1008那题。给你n*n个方块,每个方块被对角线划分为4部分,每一部分里面有一个数字,问能否将方块拼成一个边长为n的大方块,使得相邻方块的相邻数字相同。用dfs搜索,需要剪枝,同一层中相同方块只搜索一次。View Code #include <stdio.h>#include <string.h>#define N 26#define T 0#define R 1#define B 2#define L 3int x[N][4],top;int n,id[N],num[N];bool success;int Left(int k){ if(k%n==0) 阅读全文
posted @ 2012-07-18 17:00 BeatLJ 阅读(179) 评论(0) 推荐(0) 编辑
摘要: DescriptionYou are in the world of mathematics to solve the great "Monkey Banana Problem". It states that, a monkey enters into a diamond shaped two dimensional array and can jump in any of the adjacent cellsdown from its current position (see figure). While moving from one cell to another 阅读全文
posted @ 2012-07-18 16:54 BeatLJ 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 经典的线段树的题,线段染色问题。跟“Mayor's Posters”那题差不多,只不过这题有多次查询。需要注意的是给的区间[a,b],a可能会大于b。View Code #include <stdio.h>#include <string.h>#define N 100001int n,m,k,ans;int vis[31];int color[4*N];void pushdown(int cur,int x,int y){ int ls=cur<<1,rs=cur<<1|1; if(color[cur]) { color[ls]=col 阅读全文
posted @ 2012-07-13 10:21 BeatLJ 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 数学模型:给定一个整数序列(最多10000000个数),初始化为0,一共有n(最大10000)个操作,其中第i个操作是将某个指定区间内的数赋值为i,求在经过n次操作后,序列中有多少个不同的非0数该题可用线段数来做,保存的关键信息为这段的值,最后的查询只有一次。需要注意的是最多有10000000个数,但n不大,所以可以用离散化处理进行优化。View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#define N 10001#define INF 0x7fffffffint a[N], 阅读全文
posted @ 2012-07-12 16:29 BeatLJ 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 维持一个整数序列,支持2种操作:1、增加一个整数到序列中;2、求序列的第K大的数。思路:建两个堆,一个小堆来保存前K大的数,一个大堆来保存剩余的数,这样的话,就满足小堆中最小的数也会大于等于大堆中最大的数,在插入的过程中,我们仍需维持这种性质,先将插入的数进入大堆,然后比较2个堆顶的数,若不满足上述性质则交换,直到满足为止。建大堆:priority_queue<int> qmax;建小堆:priority_queue<int ,vector<int>,greater<int> >qmin.View Code #include <stdio. 阅读全文
posted @ 2012-07-12 14:51 BeatLJ 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 数学模型:维持一个01序列,支持2种操作:1、将给定区间内的数取反;2、查询给定区间内1的个数。这题就是“暑假集训每日一题0712”的简化版View Code #include <stdio.h>#define N 100001int n,m,ans;int sum[4*N],rev[4*N];void update(int cur){ int ls=cur<<1,rs=cur<<1|1; sum[cur]=sum[ls]+sum[rs];}void pushdown(int cur,int x,int y){ int mid=(x+y)>>1, 阅读全文
posted @ 2012-07-12 14:12 BeatLJ 阅读(301) 评论(0) 推荐(0) 编辑
摘要: 维持一个整数序列,支持2种操作:Q a b:查询区间[a,b]内的和;C a b x:将区间[a,b]内的每个数加上x。对于每次查询输出结果。结果可能会超32位。View Code #include <stdio.h>#define N 100001int n,m,a[N];long long ans;long long sum[4*N],inc[4*N];void update(int cur){ int ls=cur<<1,rs=cur<<1|1; sum[cur]=sum[ls]+sum[rs];}void pushdown(int cur,int x 阅读全文
posted @ 2012-07-12 13:15 BeatLJ 阅读(247) 评论(0) 推荐(0) 编辑
摘要: 维护一个只有0和1的整数序列,支持以下操作:1 x y v : 将区间[x,y]之间的所有整数都变为v(v为0或1);2 x y : 将区间[x,y]之间所有的1变为0,所有的0变为1;3 x y : 查询区间[x,y]内的1的个数。线段数练习:每段保存3个关键信息:和,修改标记,反转标记。需注意的几点:在更新某段时,之前的反转操作将无效,应将其清零,在下传修改标记时,应将左右儿子的反转标记清零。View Code #include <stdio.h>#define N 100001int n,m,ans;int a[N],sum[4*N],val[4*N],rev[4*N];vo 阅读全文
posted @ 2012-07-12 11:41 BeatLJ 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 维护一个整数序列,支持2中操作:1、修改某个指定数的值;2、查询指定区间的最大值。View Code #include <stdio.h>#define MAX(a,b) ((a)>(b)?(a):(b))#define N 200001int n,m,D;int max[4*N];void init(){ int i; for(D=1;D<n+2;D<<=1); for(i=1;i<2*D;i++) max[i]=0; for(i=1;i<=n;i++) scanf("%d",&max[i+D]); for(i=D- 阅读全文
posted @ 2012-07-11 16:56 BeatLJ 阅读(185) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 23 下一页