HDOJ 1020 1021 1022 1031 1032(water~)
2014-07-20 23:37
218 查看
今日继续水题之旅,共ac5个,下午的时候在1022 Train Problem I那里耽误时间较长,简要总结下。
1021
[align=left]Problem Description[/align]
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
[align=left]Input[/align]
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
[align=left]Output[/align]
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
这里,咋一看就想到了数论的知识,直接手算了余数和周期,简单一循环就OK了,数学知识能帮大忙。
1031 Design T-Shirt
可以不用动态建立二维数组,但是如果用,要用对格式。
补充利用vector建立动态数组的方法,比上边那个简洁。
<span style="font-family:Verdana;font-size:18px;">vector<vector<int> >arry(m,vector<int>(n))
</span>
注意<int> 后有一空格,头文件要包含vector。
1022 铁轨问题
给定栈的输入方式,判断能否以给定的方式输出,若能,给出方法(什么时候进,什么时候出)。自己想了想,参考了下别人的代码,核心如下。
按顺序来,输入进栈出栈顺序后,分别给予从0开始的指针,以出栈顺序作为根据,只需判断三种情况:
①相同,操作为进栈出栈,两指针都后移一位。
②栈非空且出栈顺序指针指向的那个元素正好为栈顶元素,出栈
③如果上述两种情况都没遇到,那么就该压栈了。
a[ ]这个数组顺便记录了何时进何时出,以01为标志,方便输出。
还有很长的路要走,每天尽量多ac一道题,加油!少年!
1021
[align=left]Problem Description[/align]
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
[align=left]Input[/align]
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
[align=left]Output[/align]
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
这里,咋一看就想到了数论的知识,直接手算了余数和周期,简单一循环就OK了,数学知识能帮大忙。
1031 Design T-Shirt
可以不用动态建立二维数组,但是如果用,要用对格式。
<span style="font-family:Verdana;font-size:18px;">int **a=new int * ; //动态建立a [m] for(int i=0;i<m;i++) { a[i]=new int [m]; }</span>
补充利用vector建立动态数组的方法,比上边那个简洁。
<span style="font-family:Verdana;font-size:18px;">vector<vector<int> >arry(m,vector<int>(n))
</span>
注意<int> 后有一空格,头文件要包含vector。
1022 铁轨问题
给定栈的输入方式,判断能否以给定的方式输出,若能,给出方法(什么时候进,什么时候出)。自己想了想,参考了下别人的代码,核心如下。
<span style="font-family:Verdana;font-size:18px;">while(k<n) { if(j[i]==c[k]) { a[f++]=1; a[f++]=0; i++;k++; } else if(!st.empty()&&c[k]==st.top()) { a[f++]=0; st.pop(); k++; } else if(i<n) { a[f++]=1; st.push(j[i++]); } else { ok=0; break; } }</span>
按顺序来,输入进栈出栈顺序后,分别给予从0开始的指针,以出栈顺序作为根据,只需判断三种情况:
①相同,操作为进栈出栈,两指针都后移一位。
②栈非空且出栈顺序指针指向的那个元素正好为栈顶元素,出栈
③如果上述两种情况都没遇到,那么就该压栈了。
a[ ]这个数组顺便记录了何时进何时出,以01为标志,方便输出。
还有很长的路要走,每天尽量多ac一道题,加油!少年!
相关文章推荐
- 关于杭州电子科技大学的acm1002, 1003, 1004, 1005, 1008, 1009, 1012, 1013,1014,1015,1016,1017,1019,1020,1021,1022
- HDOJ——简单题4(1020,1021)
- HDOJ1020 Encoding
- HDOJ 1032 The 3n+1 problem
- Hdoj 1032 The 3n+1 problem (看题目很重要)
- ACM--字母序列--HDOJ 1020--Encoding--字符串
- POJ 1207 HDOJ/HDU 1032 3n+1数链问题 绝对不水的解法
- HDOJ1021 Fibonacci Again
- C++ HDOJ 1020
- hdoj 5443 The Water Problem 【RMQ】
- hdoj 1022 Train Problem I
- HDOJ 4009-Transfer water最小树形图解题报告
- HDOJ1032 The 3n+1 problem
- ACM: 数学规律题 数论题 hdoj 1021
- HDOJ 1022 Train Problem I
- hdoj 1032 又一版 A+B
- hdoj1022 Train Problem I(栈的简单应用)
- HDOJ 1020解题报告
- 【HDOJ】1032 -> The 3n + 1 problem
- hdoj1021