摘要: 给你十亿个浮点型数据,需要你设计一个高效的算法找出前一万个大的数,依次输出。思路:可以开一个s[10000][100005]的二维数组,将十亿个数据读进去,再分别对每行数据用c++的sort()函数进行降序排序,再开一个t[10000]的数组用来标记s数组的每一行已经是前一万个大的数的下标.............说的不是很清楚,明天将代码附上。 阅读全文
posted @ 2012-11-23 16:55 紫忆 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 假设这有一个各种字母组成的字符串,假设这还有另外一个字符串,而且这个字符串里的字母数相对少一些。从算法上讲,什么方法能最快的查出所有小字符串里的字母在大字符串里都有? 比如,如果是下面两个字符串: String 1: ABCDEFGHLMNOPQRS String 2: DCGSRQPOM 答案是true,所有在string2里的字母string1也都有。如果是下面两个字符串: String 1: ABCDEFGHLMNOPQRS String 2: DCGSRQPOZ 答案是false,因为第二个字符串里的Z字母不在第一个字符串里。一看到这题,我首先排除直接拿string2里的... 阅读全文
posted @ 2012-11-23 16:28 紫忆 阅读(200) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1042#include<stdio.h>#include<math.h>int main(){ long m,i,j,a[10000],w,n,c; while(scanf("%ld",&n)>0) { a[0]=1; m=0; for(i=1;i<=n;i++) { c=0; for(j=0;j<=m;j++) { a[j]=a[j]*i+c; //关键语句 c=a[j]/10000; a[j]%=10000; } if(c>0) 阅读全文
posted @ 2012-11-23 13:35 紫忆 阅读(198) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1316#include<stdio.h>#include<string.h>long s[10000][200]={0};char t[10000][200];int main(){ char a[200],b[200]; long i,j,n,m,count,k; s[1][0]=1; s[2][0]=2; k=0; for(i=3;i<10000;i++) for(j=0;j<200;j++) { k+=s[i-1][j]+s[i-2][j]; s[i][j]=k%10 阅读全文
posted @ 2012-11-23 13:20 紫忆 阅读(206) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1753#include<stdio.h>#include<string.h>char s[402],t[402],c[402];int a[402];int main(){ int i,j,k,d,b,n,m,f,w1,w2; while(scanf("%s %s",s,t)>0) { n=strlen(s); m=strlen(t); w1=w2=0; for(i=0;i<n;i++) if(s[i]!='.') if(s[i]!=&# 阅读全文
posted @ 2012-11-23 13:17 紫忆 阅读(201) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>2#include<string.h>3usingnamespacestd;45voidmultiply(constchar*a,constchar*b);67intmain()8{9//cout<<"hicjiajia"<<endl;1011stringnum1,num2;//初始状态用string来存储大数12cout<<"现在,来两个大数吧!"<<endl;13cin>>num1>>num2;1415constchar 阅读全文
posted @ 2012-11-23 13:15 紫忆 阅读(180) 评论(0) 推荐(0) 编辑
摘要: (a * b) % c = ((a % c) * (b % c)) % c(a + b) % c = ((a % c) + (b % c)) % c10000位大的数字可以分开算:比如:m=123123 = (1*10 + 2)*10 + 3m%n = 123%n = (((1%n * 10%n + 2%n)%n * 10%n) % n + 3%n)%n#include<stdio.h>#include<string.h>int main(){char s[1000];long a[1000],i,t,m,n,r;while(scanf("%s%ld" 阅读全文
posted @ 2012-11-23 13:14 紫忆 阅读(336) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2086可由已经给出的函数,推导出n=3;4A1=3A0+A4-6C1-4C2-2C3n=2;3A1=2A0+A3-4C1-2C2n=1;2A1=A0+A2-2C1数学归纳证明:再假设n=5时;5A1=4A0+A5-8C1-6C2-4C3-2C4;再用n=5的情况减去n=4的情况,会得出A1=A0+A5-A4-2C1-2C2-2C3-2C4;再根据已有关系,带入数据,假设A0=30,A1=10,C1=10,C2=20,C3=10,C4=20,C5=10;可以算出A1=10;则上述成立#include<io 阅读全文
posted @ 2012-11-23 13:12 紫忆 阅读(213) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1098有一个函数: f(x)=5*x^13+13*x^5+k*a*x给定一个非负的 k 值 求最小的非负的 a 值 使得对任意的整数x都能使f(x) 被 65 整除。每输入一个k 值 , 对应输出一个 a值 , 若不存在a值 则输出 no 数学归纳法证明:1.假设当x=n时,f(n)=........%65==0成立则只需要证明f(n+1)=5(n+1)^13+13(x+1)^5+k*a*(x+1)%65==0成立即可将f(x+1)用二项式分解,会发现5(n+1)^13+13(x+1)^5一定能被%65==0 阅读全文
posted @ 2012-11-23 13:10 紫忆 阅读(283) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1698大意:给一组棍子染色,不同的颜色有不同的值,执行一系列的区间染色后,问这组棍子的总值是多少。题目分析:建树:节点的域有左右节点和颜色,l,r,num;num=0时表示这个区间由多种颜色覆盖。更新的时候,如果更新区间比当前区间小,并且当前区间的颜色大于0,说明已经被完全染色,就把该区间颜色传递到左右子树上,该区间染色为0,然后根据更新区间的大小,在左右子树上去搜索。求和的时候遇到区间的num>0的时候说明完全被染色过了,就把区间的长度乘以颜色的值加到总和里面去,然后结束这个方向的递归查询,代码:#i 阅读全文
posted @ 2012-11-23 12:21 紫忆 阅读(352) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1754View Code #include<iostream>using namespace std;struct{ int l,r,max;}s[200005*4];int data[200005];void build(int l,int r,int n){ int mid=(l+r)/2; if(l==r) { s[n].l=l; s[n].r=r; s[n].max=data[l]; } else { s... 阅读全文
posted @ 2012-11-23 08:49 紫忆 阅读(164) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1255http://acm.hdu.edu.cn/showproblem.php?pid=1542思路:嗯哼,要开始利用线段树求解矩形面积的并、交、以及周长了。先看一下吧给定一个矩形的左下角坐标和右上角坐标分别为:(x1,y1)、(x2,y2),对这样的一个矩形,我们构造两条线段,一条定位在x1,它在y坐标的区间是[y1,y2],并且给定一个cover域值为1;另一条线段定位在x2,区间一样是[y1,y2],给定它一个cover值为-1。根据这样的方法对每个矩形都构造两个线段,最后将所有的线段根据所定位的x从 阅读全文
posted @ 2012-11-23 08:47 紫忆 阅读(440) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1166用线段树做,比树状数组费时#include<iostream>using namespace std;const int N=50005;struct { int left,right,num;}s[4*N];int data[N];void build(int left,int right,int n){ int mid; mid=(left+right)/2; if(left==right) { s[n].left=left; s[n].ri... 阅读全文
posted @ 2012-11-23 08:40 紫忆 阅读(170) 评论(0) 推荐(0) 编辑