算法学习

Tri Tiling

In how many ways can you tile a 3×n rectangle with 2×1 dominoes? Here is a sample tiling of a 3×12 rectangle. InputInput consists of several test cases followed by a line containing −1−1. Each test case is a line containing an integer 0≤n≤300≤n≤30.Output For each test case, output one integer number giving the number of possible tilings. #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace s ...

李白打酒

话说大诗人李白,一生好饮,幸好他从不开车。一天,他提着酒壶,从家里出来,酒壶中有酒 2 斗,他边走边唱:无事街上走,提壶去打酒。逢店加一倍,遇花喝一斗。这一路上,他一共遇到店 mm 次,遇到花 nn 次,已知最后一次遇到的是花,他正好把酒喝光了。请你计算李白遇到店和花的次序,可以把遇店记为 aa,遇花记为 bb。例如:这一路上,他一共遇到店 55 次,遇到花 1010 次,已知最后一次遇到的是花,他正好把酒喝光了。则:babaabbabbabbbb 就是合理的次序。像这样的答案 ...

B – Who’s in the Middle

  B – Who’s in the Middle FJ is surveying his herd to find the most average cow. He wants to know how much milk this ‘median’ cow gives: half of the cows give as much or more than the median; half give as much or less. Given an odd number of cows N (1 <= N < 10,000) and their milk output (1..1,000,000), find the median amount of milk given such that at least half the cows give the same amount of milk or more and at least half give the same or less. Input * ...

A – All in All

  A – All in All You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string. Given two strings s and t, you have to decide whethe ...

筛选法求素数

用筛法求素数的基本思想是:把从1开始的、某一范围内的正整数从小到大顺序排列, 1不是素数,首先把它筛掉。剩下的数中选择最小的数是素数,然后去掉它的倍数。依次类推,直到筛子为空时结束。 如有: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1不是素数,去掉。剩下的数中2最小,是素数,去掉2的倍数,余下的数是: 3 5 7 9 11 13 15 17 19 21 23 25 27 29 剩下的数中3最小,是素数,去掉3的倍数,如此下去直到所有的数都被筛完,求出的素数为: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 4 ...

c++折半查找

介绍 折半查找,又称作二分查找。这个查找的算法的特点,就是,要求数据要是有序的。 1 ,存储结构一定是顺序存储 2 ,关键字大小必须有序排列 然后,利用这组有序的数据之间的关系,来进行折半的查找。 比方说,这组数据是升序排列的。一开始,首先对比这组数据的中间的项与关键值(key)的关系。若是关键值(key)>中间值,则说明,关键值(key)在中间值的右侧,因此将这组数据的区间缩小为以中间值为最左侧的小区间。然后,继续用中间值进行比较,以此类推,最终肯定会找到在数组当中与之匹配的关键值,直到区间缩小为0还没找 ...

A+Bproblem(大数处理)

!!!!!杭电1002,错了七次!!,一直都不明白为啥错了,后来一字一字的读,才明白,,是大数计算。哭了。。应该用数组来做。   A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 448906    Accepted Submission(s): 87050 Problem Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.   Input The first line of the input contains an integer T(1<=T<=20) ...