自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

liwei的专栏

记录生活与学习的点点滴滴

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

原创 project euler problem 8:Largest product in a series

一串1000字符的串,5个连续的数相乘最大的是哪个5个连续的数?直接循环……#include #include #include #include #include #include #include using namespace std;int main(){ char a[1005]={"7316717653133062491922511967442657474

2013-09-30 23:46:18 985

原创 project euler problem 5:Smallest multiple

Problem 52520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.What is the smallest positive number that is evenly divisible by all of the n

2013-09-30 22:26:41 579

原创 POJ 2406 Power Strings:KMP算法

Sample Inputabcdaaaaababab.Sample Output143HintThis problem has huge input, use scanf instead of cin to avoid time limit exceed。思路:用KMP算法,但是刚开始不知道怎么判断重复多少次,所以写出了那个next的每个值

2013-09-30 18:23:10 881

原创 POJ 2309树状数组的简单变型

InputIn the input, the first line contains an integer N, which represents the number of queries. In the next N lines, each contains a number representing a subtree with root number X (1 31 - 1).

2013-09-30 16:33:06 660

原创 COJ 1251最近点对(模板题)

[007]【算法实验项目】最近点对Time Limit: 3000 ms     Memory Limit: 65536 KBTotal Submit: 19     Accepted: 6 Description平面上有一系列点,请求出最近两点之间的距离Input第一行是一个整数T,表示测试数据个数接下来对于每个测试数据输入一个正整数N,表示点的数个(2

2013-09-29 16:41:39 1025

原创 COJ 1239集合set的简单应用

Input There are only one case, including two lines, the fist line only contain one integer N, stands for the amount of raom digits . The second line contains N integers, stand for random digits (stu

2013-09-29 16:28:17 575

原创 COJ 1064行编辑距离:STL栈的简单应用

【数据结构】行编辑程序Time Limit: 1000 ms     Memory Limit: 65536 KBTotal Submit: 22     Accepted: 14 Description对若干行字符进行编辑处理,并实现以下功能:当出现‘#’时,当作退格符处理(即删除前一个字符,#不保留)。当出现‘@’时,清除本行中'@'前的所有字符(@本身不保留)。

2013-09-28 21:45:36 702

原创 COJ 1065括号匹配:栈的简单应用

[STL]【数据结构】括号匹配Time Limit: 1000 ms     Memory Limit: 65536 KBTotal Submit: 43     Accepted: 11 Description数据有一行,由(,),[,],{,}六种字符构成。现在判断这行括号是否合法,合法条件如下:1、每个左括号都有对应的右括号匹配,不得有多余的括号,比如这样正确:{}(

2013-09-28 16:11:06 704

原创 POJ 1251 (2013.9.21周赛H题:MST最小生成树prim和kruskal算法)

题意:Lagrishan的一个热带岛屿上的行政长官有一个问题要解决。他决定把几年前得到的外国援助资金用于修建村庄之间的道路。但是丛林比道路多太多了,使道路网络的维护太过于昂贵了。理事会必须选择停止维修一些道路。上述左侧图显示当前所有使用中的道路,以及现在每月的维护费用。当然,村庄之间必需有一些公路能够相通,即使路线并不像以前一样短。行政长官想告诉理事会怎样才使每月的花费最小,并且所维持的道路,将连

2013-09-26 22:36:02 947

原创 CSDN博客贴代码如何快速排版规范

看别人的代码有时候真痛苦,要是自己会的算法肯定不会参考别人的代码;但是别人的代码不规范,看起来太麻烦了,不整齐,看起来都费劲。所以这里教菜鸟们如何最快的实现代码的工整,排版规范……首先:到你想贴代码的时候或者放入代码的时候,你可以先把光标放到编程语言那个图标,选择C++,然后在框里粘贴上你的代码,点确定就得了,如下图:(下一步往下看->)然后再点上面说的那个图标的往右数第二个图标,

2013-09-24 17:05:49 3549

原创 DFS专攻:HDU 1312与COJ 1061

简单的BFS……#include#includeint n,m,sum,a[50][50]={0};char b[50][50];using namespace std;void dfs(int i,int j){ sum++; a[i][j]=1; if(!a[i-1][j]&&i-1>=0&&b[i-1][j]==b[i][j]) dfs(i-1,j);

2013-09-23 23:30:28 655

原创 POJ 1915(与HDU 1372类似,BFS代码都差不多)

简单的BFS,因为做过HDU 1372,所以做这题没用几分钟,代码类似……#include#include#includeusing namespace std;int a,b,c,d,t,v[305][305],dist[8][2]={1,-2,2,-1,2,1,1,2,-1,2,-2,1,-2,-1,-1,-2};struct abc{ int x,y,p;};in

2013-09-23 21:54:04 573

原创 HDU 1372(2013.9.21周赛 i 题:较简单的BFS)

Knight MovesTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5162    Accepted Submission(s): 3164Problem DescriptionA friend of you i

2013-09-23 21:35:36 711

原创 POJ 2389大数乘法

两个超过64位的数相乘……数组模拟咯……#include#includeusing namespace std;int main(){ int la,lb,i,j,c[150]; char a[45],b[45]; while(cin>>a>>b) { la=strlen(a); lb=strlen(b); memset(c,0,size

2013-09-23 17:05:38 759

原创 POJ 2388 排序水题

排序后输出中间的数#include#includeusing namespace std;int main(){ int n,i; cin>>n; int *a=new int[n]; for(i=0;i<n;i++) cin>>a[i]; sort(a,a+n); cout<<a[n/2]<<endl; dele

2013-09-23 16:46:20 664

原创 POJ 2371排序水题

题意:将数组从小到大排序,输出指定位置的值;#include#includeint a[100010];using namespace std;int main(){ int n,m,i,j; char c[5]; cin>>n; for(i=0;i<n;i++) cin>>a[i]; sort(a,a+n); cin>

2013-09-23 16:33:36 657

原创 POJ 2370选举通过

水题……#include#includeusing namespace std;int main(){ int n,i,a[103],sum1=0,sum2=0; cin>>n; for(i=0;i<n;i++) { cin>>a[i]; sum1+=a[i]; } sum1=(sum1+1)/2;

2013-09-23 13:28:58 648

原创 POJ 2365 Rope

求各点连起来的周长再加上钉子的周长。#include#include#includeusing namespace std;inline double dist(double x1,double y1,double x2,double y2){ return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}int main(){ i

2013-09-23 13:12:53 663

原创 POJ 2363 Blocks

BlocksTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 6917 Accepted: 3337DescriptionDonald wishes to send a gift to his new nephew, Fooey. Donald is a b

2013-09-22 23:42:48 723

原创 POJ 2350水题(注意%的输出)

现在终于知道%的输出了,本来我想单独输出这个百分号的,但是有这个输出法就不用单独输出了,连续写两个%就得了#include#includedouble a[1010];using namespace std;int main(){ int t; cin>>t; while(t--) { int n,i,m=0; doub

2013-09-22 23:02:46 606

原创 POJ 2346 DP题

题意:求n位数一分为2,左边n/2和右边n/2中数字之和相等的数的个数。思路:DP不会,反正题目要求最多到10,所以一个一个算过去算了,算得了直接给答案。奇数不可能相等滴,位数都不一样不可能比较,所以当然为0.#includeusing namespace std;int main(){ int n; cin>>n; if(n&1) cout<<'0'<<

2013-09-22 22:36:55 693

原创 UVA 100(即POJ1207)

题意:题目首先给出一个循环公式,对于一个整数n,当n为奇数时,n=3n+1,当n为偶数时,n=n/2,如此循环下去直到n=1时停止。现题目要求对任意输入的两个整数i、j,输出i、j之间(包括i、j)的所有数进行上述循环时的最大循环次数(包括n和1)。#include#includeusing namespace std;int main(){ int i,j; whil

2013-09-22 22:06:39 598

原创 HDU 2544(2013.9.21周赛F题:最短路)

最短路Time Limit: 1000msMemory Limit: 32768KB在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗?Input输入包括多组数据。每组数据第一行是

2013-09-22 18:18:59 1758

原创 POJ 2492(2013.9.21周赛E题:并查集)

A Bug's LifeTime Limit: 10000msMemory Limit: 65536KBBackground Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two d

2013-09-22 17:13:03 616

原创 DFS专攻:POJ 2386 与HDU 1241相似题目

刚开始写的BFS好麻烦,还错了。因为我也还没会BFS,所以参考了一下别人的代码,才知道是自己想多了,别人才几行就搞定了,我写的BFS好多代码了还没搞定,真的是自己想多了,现在对BFS有点了解了,但是要再用几题加深难度,要掌握BFS才得!!!#include#includeint n,m;char b[103][103];using namespace std;void dfs(int

2013-09-22 09:41:08 677

原创 HDU 1282 (2013.9.21周赛C题:回文数)

水题,一次过,刚开始不想用另一个函数的,实在不行了就开了个函数,一次过……不废话了……#include#include#includeusing namespace std;int cmp(int n){ int i,a,b,m=0; i=-1; a=b=n; while(b) { i++; b/=10;

2013-09-22 09:35:20 507

原创 HDU 1219(2013.9.21周赛B题:统计字母)

水题……不过刚开始TLE了,后面直接一个一个字母输入,同时就处理,这效率快多了,还怕TLE???哈哈……如果一行一行的输入的话,循环里面不能直接用i<strlen(str),因为每次都要判断一次,计算一次,所以肯定TLE啦,现在终于知道了,在循环外面int lenth=strlen(str)这样就行了。不过我还是采取了一个一个字母输入,这效率更高……#include#include#inc

2013-09-22 09:33:34 542

原创 HDU 1071(2013.9.21周赛A题:抛物线面积)

题意:求阴影部分的面积……这题其实公式忘了,积分还有线代都不太懂,百度的公式……#include#includeusing namespace std;int main(){ int t; cin>>t; while(t--) { double x1,y1,x2,y2,x3,y3,a,b,c,d,e,sum; scan

2013-09-22 09:28:57 479

原创 POJ 1845(2013.9.15周赛A题数论或者二分)

题意:给你两个数n,m求出n^m的所有约数之和对9901取模的值(n,m本题需要运用的数学知识非常多,做完这题,学到的公式一堆。 由于n,m都非常大,所以一般的做法都不适合   需要运用到的数学知识: 1、 一个数n可化成n=p1^a1+p2^a2+p3^a3+….+pn^an; P1,p2,p3,p4均为素数。比如12=3*4=2^2*3。 那么n的约数之和=(1+p1+p1^2

2013-09-21 10:59:36 550

原创 POJ 2328每日一水

题意再明白不过了……只有真的猜数对了才老实,其他一切情况都不老实。#include#include#includeusing namespace std;int main(){ int n,h=15,l=-1; char a[10],c; while(scanf("%d%c",&n,&c)&&n) { gets(a);

2013-09-20 23:30:31 628

原创 hdu 1114完全背包问题

题意:给定t,t个用例;给定E,F,分别表示空的存钱罐的重量和装了钱之后的重量。给定价值和重量,求最少的价值。思路:这个和01背包相似,只不过内循环相反而已,可以转化为01背包,所以01背包的代码加以修改即可AC,但是注意,这里求的是最少的,所以改的还是挺多的;除了第一个为0外,其他的都设为比较大的值,以便确定最后比它小的值方可求出最小值……#includeusing namespa

2013-09-20 17:06:35 612

原创 hdu 2602(01背包问题)

简单的01背包应用……背包初步……#includeusing namespace std;int max(int a,int b){ return a>b?a:b;}int main(){ int t; cin>>t; while(t--) { int value[1010],volume[1010],a[1010]={0},

2013-09-20 16:08:58 563

原创 hdu 1896(2013.9.15周赛D题)优先队列

题意:某人走在路上会遇见一些石头,如果遇见第奇数个石子,则将它扔到前面,如果是偶数,则什么也不做,如果某一个位置上有多个石头,则先遇见扔的比较近的那个,现在给出一些石头的初始位置和能够扔的距离,问到最后最远处的石头离初始位置多远!思路:搞定了简单的队列,这优先队列也就简单多了,不过用到了重载,好点吃力的。刚开始会一点,所以看了学长们教的课件又百度好多资料才搞明白优先队列。不过还好,终于明白了。

2013-09-17 23:35:24 845

原创 hdu 1548(2013.9.15周赛F题BFS)

A strange liftTime Limit: 1000msMemory Limit: 32768KBThis problem will be judged on HDU. Original ID:154864-bit integer IO format: %I64d      Java class name: MainThere is a

2013-09-17 21:06:27 639

原创 POJ 2316

思路:因为每个字符串的长度相同,所以按位将输入的所有数据加起来,然后对10取模即是结果(即只取个位数,因为转过去它不会超过10的)。这里还学到了一个技巧,就是无限个输入时,不用判断输出了,因为你想结束时,按组合键即可退出,这是系统准备好的组合键退出,我们不用再去判断。#include#includeusing namespace std;int main(){ int a[11

2013-09-17 13:17:23 722

原创 POJ 2187 (2013.9.15周赛E题凸包)

Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the title 'Miss Cow World'. As a result, Bessie will make a tour of N (2 <= N <= 50,000) farms around the

2013-09-16 23:45:11 554

原创 hdu 1872(2013.9.15周赛C题)

C. 稳定排序Time Limit: 1000msCase Time Limit: 1000msMemory Limit: 32768KB64-bit integer IO format: %I64d      Java class name:Main SubmitStatus PID: 6021 Font Size:+- 大

2013-09-16 22:34:02 595

原创 POJ 2304水

转盘动,非指针动。#includeusing namespace std;int main(){ while(1) { int a,b,c,d,sum=1080; cin>>a>>b>>c>>d; if(!(a|b|c|d)) break; sum+=((a+40-b)%40)*9; sum+

2013-09-14 16:45:35 585

原创 POJ 2301水!!!题…………

刚开始竟然看了好久都不知道怎么意思,唉……英语太烂了!!!后面又看了别人的翻译才知道啥意思,罪过啊……#includeusing namespace std;int main(){ int n; cin>>n; while(n--) { int a,b; cin>>a>>b; if((a+b)%2||a<b)

2013-09-14 16:14:05 688

原创 POJ 2291水题

题意:给你几根绳子,每根最大承重能力都不同,从中选出几根,问最大承重力量是多少?(比如有1,10,15承重的3跟绳子,如果用一根的话,选15的,能承重15,用2根的话,用10和15的,能承重10*2=20,3根的话显然只能是1*3=3了,承重最大的当然是20),大大的水题啊……#include#includeusing namespace std;int main(){ int n

2013-09-14 16:01:08 716

空空如也

空空如也

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

TA关注的人

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