三道题目

Q1. String to Integer

implement a similar atoi function to convert a string to integer(int type)

hint:
the string may start with continuous whitespaces, you should ignore them.

the string may end with continuous invalid characters, you should ignore them, too.

find the first valid integer you can find in this string as the result.

there may be some strings which can not be convertd to an intrger. in this case, return -1.

there may be some strings  which are out of the range of int.type, return -1.

Input
A single line of string.

output
A single integer

************************************************************************************************************

Q2.ZigZag

A sequence of number is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative. the first difference(if one exists)may be either positive or negative. A sequence with fewer than elements is trivially a zig-zag sequence.

For example, 1,7,4,9,2,5 is a zig-zag sequence because the differences(6,-3,5,-7,3)are alternately positive and negative. In contrast, 1,4,7,2,5 and 1,7,4,5,5 are not zig-zag sequences, the first because its first two differences are positive and second because its last difference is zero.

Given a sequence of integers, sequence, return the length of the longest subsequence of sequence that is a zig-zag sequense. A subsequence is obtained by deleting some number of elements(possibly zero) from the original sequence, leaving the remaining elements in their original order.
************
A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a zig-zag sequence.

For example, 1,7,4,9,2,5 is a zig-zag sequence because the differences (6,-3,5,-7,3) are alternately positive and negative. In contrast, 1,4,7,2,5 and 1,7,4,5,5 are not zig-zag sequences, the first because its first two differences are positive and the second because its last difference is zero.

Given a sequence of integers, sequence, return the length of the longest subsequence of sequence that is a zig-zag sequence. A subsequence is obtained by deleting some number of elements (possibly zero) from the original sequence, leaving the remaining elements in their original order.

Input
First line is the number of elements in the sequence.
second line contains the sequence of numbers split by whitespaces.
Each sequence contains between 1 and 50 elements.
Each element of sequence is between 1 and 1000.

Output
The length of the longest sequence.

Sample input 1:
6
1 7 4 9 2 5
Sample output 1:
6

Sample input 2:
1
44
Sample output 2:
1

************************************************************************************************************

Q3.Fibonacci Representation

We define Fibonacci number as follow:
F(1)=1
F(2)=2
F(i)=F(i-1)+F(i-2),(i>=3)
Given any onee number M, we can represent it by using the sum of some different
Fibonacci numbers.

For example:
Given "13",you can represent it as 3 ways:
they are
13 = 13
13 = 5 + 8
13 = 2 + 3 + 8
You cannot represent like this:
13 = 2 + 3 + 5 +3
Because there are two same "3".
It is easy for case of 13. Bur how many ways we can represent M by using the sum of different Fibonacci numbers when M is so large(for example 10^8)that we cannot enumerate?

Input
There is only line which containsone number that is smaller than 2^31.You should
give that how many ways we can represent this number by using the sum of different Fibonacci numbers.

Output
One line only with a number indicating the number of ways that the input number can be represented by the sum of different Fibonacci numbers.

Sample Input 1:
6
Sample Output 1:
2

Sample Input 2:
13
Samplr Output 2:
3

时间: 2024-11-10 20:18:05

三道题目的相关文章

The FLARE On Challenge

上周才开始做这个CTF,用一周左右的时间完成了全部7道题.算是为即将到来的找工作进行热身和学习,下面记录一下遇到的问题和学到的东西,具体的解题过程就不详细描述了. challenge1 这道题用IDA打开发现是一个.net程序,于是用.NET Reflector反编译定位 button的处理函数,就可以定位解码函数了. challenge2 通过邮件里的描述(We saw what looked like attacker activity to this site)猜测页面里面被嵌入了恶意代码

dp背包问题/01背包,完全背包,多重背包,/coin change算法求花硬币的种类数

一步一步循序渐进. Coin Change 具体思想:给你 N元,然后你有几种零钱S={S1,S2...,Sm} (每种零钱数量不限). 问:凑成N有多少种组合方式  即N=x1 * S1+x2*S2+...+xk*Sk (xk>=0,k=1,2..m) 设有f(x)中组合方式 有两种解答(自底向上回溯): 1.不用第m种货币   f(N,m-1) 2.用第m种货币 f(N-Sm,m) 总的组合方式为f(N,m)=f(N,m-1)+f(N-Sm,m) anything is nonsense,s

一维向量旋转算法 编程珠玑 第二章

看了编程珠玑第二章,这里面讲了三道题目,这里说一下第二题,一维向量旋转算法. 题目:将一个n元一维向量(例数组)向左旋转i个位置. 解决方法:书上讲解了5种方法,自己只想起来2种最简单方法(下面讲的前两种). 1.原始方法. 从左向右依次移动一位,对所有数据平移:这样循环i次,算法最坏时间复杂度达n^2.耗时不推荐. 2.空间换时间. 顾名思义,申请一个i长度的空间,把前i半部分放到申请空间中,再把后面的所有数据向左移动i个位置,最后把申请的空间中的数据放到后半部分.浪费空间,不推荐. 3.杂技

HDU 1828 Picture(线段树扫描线求周长)

Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4475    Accepted Submission(s): 2207 Problem Description A number of rectangular posters, photographs and other pictures of the same shap

ACM核武器

工欲善其事必先利其器,给大家介绍一下ACM里面经常使用的一些工具,平台,作为第一发福利. 详细看这里,我直接粘贴过来有些代码没贴过来  http://wuyiqi.net/house/acm_weapons 各种强大的编辑器 + codeforces平台 + topcoder平台 有什么问题欢迎留言. 问题一:假设发现arena打不开 那么打开控制面板->java->常规->设置.点击删除文件 或者下载这个,解压后点击run.bat执行就可以. 1:codeblocks   下载链接 网

湘潭比赛有感---铩羽之行

去之前,我们很自信,去之后,发现世界很大. 出发前,我们一直很自信,心理一直觉得:题目难点对我们还有优势,出现动态规划我和小黄能能较快的推出状态转移方程,出现裸水题,小孙立马能水了,没什么好担心. 湘潭大,最先感觉的是学校很大很气派(和nyist比),但学校门口出行的人流很小,往里面走有个类似小公园的地方,很漂亮但是也没什么人,心想:周末同学们估计都在寝室睡懒觉,没起来.往信息大楼走,发现这学校的楼很旧,甚至有点破,安静的很,尽然让人生出一种鄙夷的情绪,还不如我们自己的系楼. 热身赛 我们陆续进

【搬家】夏令营感想

无锡夏令营小结 大丰市高级中学  朱为开 回首 为期7天的无锡夏令营终于结束了,一路走来,有许多辛酸,也有许多甘甜.对于本次夏令营,做下面的一个简单的感想. 感受锡中 首先我要对本次的主办单位为我们提供了优质的服务表达我衷心的感谢,没有他们提供我们良好的学习和生活条件,我们是不会在本次夏令营中取的长足的进步的. 在夏令营之余,我也顺便感受了一下这所百年老校的气息与精神.江苏省无锡锡山高级中学是一所具有百年文化底蕴的名校,他大气磅礴,端庄秀丽,本次我们就是在此进行了我们的学习与交流的.我们在进行信

【转】[email protected]·ACM/ICPC 回忆录

转自:http://hi.baidu.com/ordeder/item/2a342a7fe7cb9e336dc37c89 2009年09月06日 星期日 21:55 初识ACM最早听说ACM/ICPC这项赛事是在大三上的算法课上张老师提到的,当时我们学校的组织参加这项活动才刚刚起步,我也没太在意,总觉得那是非常遥远的事,事实上当时我也从未相当如今我们能获得现在的成绩.真正踏入ACM/ICPC这个神奇的世界,不得不提到2004那一年我们学校的参赛队伍xmutank,正是听了pipo师兄的精彩演讲以

Google笔试(2015年8月)

华电北风吹 天津大学认知计算与应用重点实验室 日期:2015/8/21 这三道题目的PDF能够在这里下载 https://github.com/ncepuzhengyi/jobHuntingExam/tree/master/jobExam/Problem_20150815_google Problem 1: 问题1是眼下须要将阻止分成两块,因为组织内有些人之间有矛盾不能分到同一组内.问你是否存在这种划分. 问题一是二分图推断问题,仅仅须要推断无向图是否是二分图就可以. 最简单的方法是採用广度优先