自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(34)
  • 收藏
  • 关注

原创 hdoj 1042 N!(还是对大数的处理)

初略估计10000!的阶乘会有将近3000位数。用二维数组每个单元保存一位数最后会内存溢出,所以我们每个单元保存4位数,减少数组的大小。注意输出时的细节,每个单元保存4位数,如果数是0的话,要以%04输出。#include using namespace std;#define M 10001#define N 10001int a[N][M]={0};int len[N];

2017-05-31 10:05:03 511

原创 hdoj1041Computer Transformation(大整数处理)

找到规律。你会发现a(n)的值是a(n-2)中的1和00确定的。因为01->1001,而1->01,00->1010。故列出a(n)=a(n-2)+2^(n-3),再推出a(n)=a(n-1)+2*a(n-2)。注:这题的大数处理有点步骤可以省略,因为我们的递推式只是乘2。有包含完整的乘和加的大数步骤的本题链接http://blog.csdn.net/lishuhuakai/artic

2017-05-30 09:55:30 329

原创 hdoj 1040 As Easy As A+B(zz)

我只能说作者你做到了,真的和A+B一样简单。。没有用sort(),重新回想了一下冒泡排序。。不知道这题目是怎能排的,前面有几道巨难的,后面就连续的送分。。。。老师,我应该早刷的。。太惭愧了。。#include#includeusing namespace std;int a[2500];int main(){ int t,n,i,j,temp,k; scanf("%d

2017-05-29 20:35:27 346

原创 hdoj 1039 Easier Done Than Said?(水水的)

简单题。不过觉得自己做复杂了,用简单的dp来判断是否有连续的3个元音或辅音,可以直接分模块判断是否满足条件,代码也会更简洁。#include#include#includeusing namespace std;int main(){ char str[22]; int dp1[22],i,k,dp2[22],flag,len; while(~scanf("%s",str))

2017-05-29 20:15:29 259

原创 hdoj1038 Biker's Trip Odometer(zz)

小学数学题#include#includeusing namespace std;#define p 3.1415927int main(){ double d,v,len,t1; int zs,t;t=1; while(~scanf("%lf%d%lf",&d,&zs,&t1)&&zs!=0) { len=(p*d*zs)/(12*5280); v=3600*len

2017-05-29 19:10:12 256

原创 hdoj 1037 Keep on Truckin'(zz)

这题目让我无言以对。。。#include using namespace std;int main(){ int a[3]; int i,f;f=0; for(i=0;i<3;i++) { cin>>a[i]; if(a[i]<=168){cout<<"CRASH "<<a[i]<<endl;f=1;} if(f==1)continue; } i

2017-05-29 18:44:52 295

原创 hdoj 1036Average is not Fast Enough!(格式格式!)

头昏脑涨,图书馆的空调太给力了。。。主要考察格式,基本没有算法。其中一个小细节就是判断flag==1成立时continue,不用break是为了确保还能继续输入数据。#includeusing namespace std;int main(){ int n,t,i,sum,flag; double d; char s,m1,m2,s1,s2; scanf("%d%lf",

2017-05-28 20:24:44 410

原创 hdoj 1035 Robot Motion(简单题)

我在输入字符二维数组的地方卡了一下以后得习惯只用一个循环将每行看成一个字符串输入。而且最好不用scanf("\n"),容易卡住!求从哪一步开始绕圈圈,设了b[11][11],每经过一个点(x,y)就将当前step赋给b[x][y]。b[x][y]也起到判断该点是否被访问过的作用。#includeusing namespace std;int main(){ char a[11]

2017-05-28 17:11:42 464

原创 hdoj1034 Candy Sharing Game(简单题)

这种类型的题目只要理解了题意就很容易写出代码。题意:n个人绕成一个圈,每个人手上都有偶数个糖果,每一轮的规则是:每个人同时把自己一半的糖果分给自己右边的人,那些一轮下来手里的糖果数变成奇数的同学会多给一颗糖。再进行下一轮分享,直到每个人手里的糖果都一样多,要求输出进行的轮数和最后每个人手上的糖果数。#include #includeusing namespace std;int

2017-05-28 15:49:44 383

原创 hdoj 1033Edge(考验英文功底)

看题目看了半天,最后是看输出勉强理解了题目。。。。A是指右转,V指左转。每次转向固定走10步。好好一个简单的问题被描述成xxxxxxxxxxxxxxxxxxxxxxk的取值代表4个方向。#include#includeusing namespace std;int main(){ char str[205]; int i,k,len,x,y; while(cin>>s

2017-05-28 11:36:47 401

原创 hdoj 1032 The 3n + 1 problem(细节细节)

题目很简单。但有3个细节我觉得得注意1.题目没说明I,j谁大谁小,这个需要判断2.如果直接循环i到j之间的每个数,会超时(血的教训),这时你观察题目,会发现求最大值的话,肯定是奇数的cycle length比与其相邻的偶数的cycle length大,所以我们只需要判断i与j之间的奇数就行了。3.注意i还可以和j相等。#include using namespace std;

2017-05-28 10:35:24 346

原创 hdoj 1031 Design T-Shirt(排序)

这题不难,用好排序函数就ok。有个细节就是我在cmp1函数里讨论a.sum和b.sum相等的情况是根据index的大小进行排序的。其实事实上,不用这个处理也行,因为如果存在sum值相同,index不同的情况,默认排序就是index更小的在前面。。。#include#includeusing namespace std;typedef struct py{ double sum

2017-05-27 21:00:16 377

原创 hdoj 1030 Delta-wave(3坐标)

观察题目给的图,你会发现可以用3个坐标值唯一确定一个点,这3个坐标值如图:(图侵删。。。)而且在进一步观察下,你会发现两个点的最短距离就是两个点对应坐标差的绝对值之和。所以问题就简单啦#include #includeusing namespace std;void loc(int a,int &x,int &y,int &z){ int b,spr,spl; b=

2017-05-27 16:54:54 592

原创 hdoj1028 Ignatius and the Princess III(母函数,生成函数)

硬想了大半天还是不会。一开始想找规律看看有没有什么递推式,无果。。。后面在网上看代码,了解到有关母函数的问题。大神帅气闪闪的讲解入口http://blog.163.com/lyt9469@126/blog/static/17044235820108203120482/在这里列个本题解法和母函数的模板。#include int main() { int i,j,k

2017-05-26 20:51:19 545

原创 hdoj1029 Ignatius and the Princess IV(对题目的观察?)

这道题以前在408统考的卷子上做过。首先这道题数据量大,容易报超时。其次我们通过理解题意,知道是要找到出现次数超过一半的数,而且关键在于输入的是奇数个数这意味着出现次数最多的那个数起码会连着出现两次。我们用count来筛选,初始值为0,结果变量设为temp,输出当count不为0时的temp值。注:此题用cin输入也会超时。#includeint main(){ int

2017-05-26 17:48:38 277

原创 hdoj1027 Ignatius and the Princess II(全排列)

要是真的是我去救公主,感觉公主应该早被吃了。。。。关键就是有个全排列的函数next_permutation()知道这个函数,问题就特别简单了。#include#include#includeusing namespace std;int a[1005];int main(){ int i,n,m; while(cin>>n>>m) { for(i=1;i<=n;i++

2017-05-25 20:47:54 213

原创 hdoj1026 Ignatius and the Princess I(图bfs+栈)

感觉自己还有好长好长的路要走。。考察:bfs时用到队列找到最优路线,用栈存储经过的点并输出。#include #include #include using namespace std; typedef struct Node{ int x, y, cost; int prex, prey;}Node; int N, M;char maze[105][105];

2017-05-25 19:31:03 519

原创 hdoj1024 Max Sum Plus Plus(DP!DP!)

参考的链接http://blog.csdn.net/sdjzping/article/details/8645031关键还是那两点1.dp[i]的含义2.转移方程怎么写#include #include#includeusing namespace std;#define M 1000005#define Max 0x7fffffff int a[M],dp[M],mx[M]

2017-05-24 23:27:28 213

原创 hdoj1025 Constructing Roads In JGShining's Kingdom(DP+二分法)

第一次提交超时了。借鉴了一下别人的代码,发现dp的思路都错了。。。而且还得用到二分法来减小时间复杂度。dp+二分法。好题呀。#includeusing namespace std;int p[500005],dp[500005]; int search(int num,int low,int high){ int mid; while (low <= high)

2017-05-24 20:44:25 287

原创 hdoj1023 Train Problem II(卡特兰数,对大数据的处理)

由火车序列这个实际问题引出卡特兰数问题。c(0)=1;(n+2)*c(n+1)=c(n)*(4n+2)这题是在理解别人代码的基础上,自己又重新敲了一遍,按照自己的理解注释了些地方。//c(0)=1;(n+2)*c(n+1)=c(n)*(4n+2)#includeusing namespace std;int main(){ int i,j,len,r,temp,k,n;

2017-05-23 20:50:51 280

原创 hdoj1022 Train Problem I(栈的简单应用)

题目很长,大意是给你两个序列,要你判断是否能够通过入栈出栈操作将第一个序列变为第二个序列。考察栈的简单运用。#include using namespace std;int main(){ char s1[12],s2[12],stack[12]; int top,n,i,j,k; int gg[22]; while(cin>>n>>s1>>s2) { top=-1;j

2017-05-23 16:58:30 356

原创 hdoj1021 Fibonacci Again

如果直接按照公式递归的求f(n),求不到那么大的数。题目要求是判断是否能被3整除,这种题目可以试试找找规律。列出前20个f(n),试试mod3求余数,发现余数以8为周期。分别为1 2 0 2 2 1 0 1。所以只需要先将输入的n对8求余,判断所得余数是否为2或者6。#includeusing namespace std;int main(){ int i; while(

2017-05-22 21:10:56 280

原创 hdoj1020 Encoding

思路很简单。但始终想不明白自己第一次写的代码哪里有问题。先贴第一次的代码。#include#include#includeusing namespace std;int main(){ int t,i; string str; cin>>t; int abc[26]={0};getchar(); while(t--) { memset(abc,0,sizeof(

2017-05-22 20:39:11 268

原创 hdoj1019 Least Common Multiple(一组数的最小公倍数)

求一组数的最小公倍数。注意题目并没有限制一组输入数的个数,所以尽量不要先将输入的数存储在定义好的数组里。(第一次没ac的原因。。。)简单题。#includeusing namespace std;int lcm(int a,int b){ int c,i,d; c=(a>b)?a:b;i=2;d=c; while(1) { if(c%a==0&&c%b==0)br

2017-05-22 19:46:03 348

原创 hdoj1018(取对数)

求一个数阶乘的位数。题目规定n最大能取到10的7次方,10的7次方的阶乘肯定表示不了。但题目仅要求输出位数,取对数的方法就呼之欲出。简单题。#include #includeusing namespace std;int main(){ double t,n,i,j; double index; int sum; cin>>t; while(t--) { i

2017-05-22 18:58:02 424

原创 hdoj1017(格式)

简单题。感觉主要考察的又是格式问题。(改了2遍。。。。)#includeusing namespace std;int main(){ int t,n,m,a,b,test,count; cin>>t; while(t--) { test=1; while(cin>>n>>m&&n!=0) { count=0; for(a=1;a<n;a++)

2017-05-21 11:52:41 334

原创 hdoj1016(深度遍历)

考察深度遍历。(visited[]数组)#include#includeusing namespace std;int n,a[21];bool vis[21];int prime_sum[12]={2,3,5,7,11,13,17,19,23,29,31,37};bool prime(int x){ for(int i=0;i<12;i++) { if(prime_su

2017-05-20 21:41:07 338

原创 hdoj1015(暴力破解方程式)

题意大致是在1到26整数之中找到不重复的五个整数满足一个等式。暴力破解!#include#include#include#include #includeusing namespace std;int main(){ char str[30]; char outstr[6]; long t,v,w,x,y,z,i,flag; long r[26]; while(cin>

2017-05-19 19:11:11 523

原创 hdoj1014(输出格式)

这题感觉主要考察输出格式的要求,顺便用到了典型的空间换时间的“设缓存”方法。输出格式我是用字符串输出的。简单题。#include #include#include#define For(i,m,n) for(i=m;i<n;i++)using namespace std;int seed[100005];void change(char s[],int n){ int

2017-05-19 15:54:36 357

原创 hdoj1003(DP)

动态规划。要求出和最大的字段,可列出两种状态,得到相应的转移方程。#include #include #include #include #include #define For(i,n,m) for(i=n;i<m;i++)using namespace std;int b[100005];int c[100005];int s1,s2,z1,z2;int main(

2017-05-19 15:49:17 392

原创 hdoj1013(简单题)

Digital RootsProblem DescriptionThe digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital ro

2017-05-18 21:01:19 468

原创 hdoj1010 Tempter of the Bone(迷宫问题dfs,奇偶剪枝)

迷宫问题。这类问题接触的少,但仔细审题就能看出要用dfs。欢天喜地写出代码,结果超时了。百度了一下,惊讶的发现差了从没听过的奇偶剪枝操作。代码有借鉴的地方。#include#include #include using namespace std;int n,m,t;char maze[8][8];int v[8][8];int d[4][2]={-1,0,1,0,0

2017-05-18 20:13:31 394

原创 杭电oj1012

简单题#include #include#define For(i,m,n) for(i=m;i<n;i++)using namespace std;int main() { double a[10]; double sum=1; int i; a[0]=1; For(i,1,10) { sum

2017-05-17 20:43:44 440

原创 杭电oj1009(贪心算法)

典型贪心算法的运用。#include #include#define For(i,m,n) for(i=m;i<n;i++)using namespace std;typedef struct room{ double j,f;}room;room r[1005];//double rio[1005];bool cmp(const room &a,const room &b)

2017-05-17 19:58:02 870

空空如也

空空如也

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

TA关注的人

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