随笔分类 -  二分法

interesting sequence 二分???
摘要:算法:此题一眼看去就像是二分题,其实并不满足二分性质。假设S为29,从1开始枚举长度为2时,就不满足了,但是最长其实为3.。 1 2 20 10 10 3正确的算法是用L【i]记录 i 能最多往左扩张长度,R【i】记录i能最多往右扩张的长度。。/* * HONI, zadatak DVONIZ * Autor: Goran Zuzic * * Sluzbeno rjesenje, trebalo bi dobiti sve bodove. Ukupna slozenost O(n lg n). * */#include <algorithm>#include <functio 阅读全文

posted @ 2012-10-07 22:51 more think, more gains 阅读(221) 评论(0) 推荐(0)

HDU 3486 RMQ + 二分
摘要:算法:1.RMQ 求区间最值2.二分枚举段的数量,注意是段的数量和其和成正比,也就是枚举段的数量。View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<map>#include<set>#include<algorithm>using namespace s 阅读全文

posted @ 2012-08-18 17:31 more think, more gains 阅读(153) 评论(0) 推荐(0)

最近点对 HDU 1007
摘要:TLE。。。求出答案完全正确。就是无法处理极端情况,比如100000个X坐标相同的点,因为我是对其值进行分治,时间复杂度O(N× N)。TLE。。。修改后的算法:先对X排序,然后递归分治(1,N)区间,而不是对其实际的值进行分治.分治得到两边最小的值是ans,最后合并时,找出x坐标>= p[mid].x - ans, <= p[mid].x + ans的点,并对其按Y轴排序。两个点Y值>= ans的点 break;AC代码,二分找两边左边View Code #include<stdio.h>#include<stdlib.h>#include 阅读全文

posted @ 2012-08-08 22:02 more think, more gains 阅读(289) 评论(0) 推荐(0)

找规律 技巧题 快速幂
摘要:题意:给你个N,统计C(N,0),C(N,1)。。,C(N,N)中奇数的个数算法:统计N中1的个数就可以了,然后快速幂View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<map>#include<set>#include<algorithm>using n 阅读全文

posted @ 2012-08-07 18:13 more think, more gains 阅读(204) 评论(0) 推荐(0)

HDU 4334 Trouble
摘要:算法:比赛时,最先想到的是O( N * N * N + N ^2 * log (N * N * N )) = O( N * N*N)的时间复杂度。N <= 200,5s中肯定不会超时。写出来提交MLE。。然后计算下内存要开800 0000数组,long long 型。M =800 0000 * 8 = 6400 0000 字节 = 61 M, 只能开4000000然后开40000数组。。时间复杂度变成O( N ^ 3 * log N )提交TLE。。泪奔,改为HASH。。O(N * N * N)静态链表处理冲突。。AC。4000多ms...时间好高,旭哈希过的1600ms..原因是我定义 阅读全文

posted @ 2012-08-02 21:51 more think, more gains 阅读(143) 评论(0) 推荐(0)

Strange fuction
摘要:#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>double fun1(double x,double y){ return 6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x;}double fun2(double x,double y){ return 42*x... 阅读全文

posted @ 2011-05-03 01:16 more think, more gains 阅读(305) 评论(0) 推荐(0)

二分查找
摘要:#include<stdio.h>#include<string.h>#include<stdlib.h>int ab[1000];//二分查找 int find(int l,int r,int s) {while(l<=r){int mid=(l+r)>>1;if(ab[mid]==s) return 1;if(ab[mid]>s) r=mid-1; //注意这里不能写r=mid..否则死循环。else l=mid+1;}return 0;}int main( ){ int i; for(i=1;i<=60;i++) ab[i 阅读全文

posted @ 2011-05-03 00:46 more think, more gains 阅读(179) 评论(0) 推荐(0)

Can you solve this equation?
摘要:#include<stdio.h>#include<math.h>double fun(double x){ return 8*x*x*x*x + 7*x*x*x + 2*x*x + 3*x + 6 ;}int main( ){ int N,flag; double Y,a,b,mid; scanf("%d",&N); while(N--) { flag=0; scanf("%lf",&Y); a... 阅读全文

posted @ 2011-05-03 00:36 more think, more gains 阅读(241) 评论(0) 推荐(0)

二分查找题
摘要:hdu 2141 hdu 1025 hdu 2899 hdu 2034 hdu 1551 hdu 2199 阅读全文

posted @ 2011-05-02 23:48 more think, more gains 阅读(153) 评论(0) 推荐(0)

导航