自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 题目1145:Candy Sharing Game

题目描述:    A number of students sit in a circle facing their teacher in the center. Each student initially has an even number of pieces of candy. When the teacher blows a whistle, each student simul

2017-02-21 15:41:14 272

原创 题目1143:Primary Arithmetic

题目描述:    Children are taught to add multi-digit numbers from right-to-left one digit at a time. Many find the "carry" operation - in which a 1 is carried from one digit position to be added to the

2017-02-21 12:33:49 379

原创 题目1142:Biorhythms

题目描述:    Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they

2017-02-21 11:15:07 239

原创 题目1153:括号匹配问题

题目描述:    在某个字符串(长度不超过100)中有左括号、右括号和大小写字母;规定(与常见的算数式子一样)任何一个左括号都从内到外与在它右边且距离最近的右括号匹配。写一个程序,找到无法匹配的左括号和右括号,输出原来字符串,并在下一行标出不能匹配的括号。不能匹配的左括号用"$"标注,不能匹配的右括号用"?"标注.输入:    输入包括多组数据,每组数据一行,包含一个字

2017-02-20 14:58:20 281

原创 题目1152:点菜问题

题目描述:    北大网络实验室经常有活动需要叫外买,但是每次叫外买的报销经费的总额最大为C元,有N种菜可以点,经过长时间的点菜,网络实验室对于每种菜i都有一个量化的评价分数(表示这个菜可口程度),为Vi,每种菜的价格为Pi, 问如何选择各种菜,使得在报销额度范围内能使点到的菜的总评价分数最大。    注意:由于需要营养多样化,每种菜只能点一次。输入:    输入的

2017-02-18 16:38:11 650

原创 题目1151:位操作练习

题目描述:给出两个不大于65535的非负整数,判断其中一个的16位二进制表示形式,是否能由另一个的16位二进制表示形式经过循环左移若干位而得到。循环左移和普通左移的区别在于:最左边的那一位经过循环左移一位后就会被移到最右边去。比如:1011 0000 0000 0001 经过循环左移一位后,变成 0110 0000 0000 0011, 若是循环左移2位,则变成 1100 00

2017-02-18 14:45:23 291

原创 题目1150:Counterfeit Dollar

题目描述:    Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishabl

2017-02-18 10:42:06 197

原创 题目1149:子串计算

题目描述:给出一个01字符串(长度不超过100),求其每一个子串出现的次数。输入:输入包含多行,每行一个字符串。输出:对每个字符串,输出它所有出现次数在1次以上的子串和这个子串出现的次数,输出按字典序排序。样例输入:10101样例输出:0 201 21 310 2101 2借鉴了大牛的博文(http

2017-02-17 16:50:52 348

原创 题目1148:Financial Management

题目描述:    Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Larry has decided that he needs to grab hold of his financial portfoli

2017-02-17 15:48:04 302

原创 题目1162:I Wanna Go Home

题目描述:    The country is facing a terrible civil war----cities in the country are divided into two parts supporting different leaders. As a merchant, Mr. M does not pay attention to politics but he

2017-02-17 15:14:43 251

原创 题目1161:Repeater

题目描述:Harmony is indispensible in our daily life and no one can live without it----may be Facer is the only exception. One day it is rumored that repeat painting will create harmony and then hundre

2017-02-16 17:12:44 312

原创 题目1160:放苹果

坦率地讲,刚开始递归策略并没有想明白,借鉴了网上的资料http://www.cnblogs.com/jasonJie/p/5757936.html和http://blog.csdn.net/carvin_zh/article/details/46490511最主要的思想就是分为两种情形:一种情形是有空盘,相当于f(m,n-1);另一种情形是无空盘,相当于先将n个盘子中放入#include

2017-02-16 10:37:20 317

原创 题目1159:坠落的蚂蚁

题目描述:    一根长度为1米的木棒上有若干只蚂蚁在爬动。它们的速度为每秒一厘米或静止不动,方向只有两种,向左或者向右。如果两只蚂蚁碰头,则它们立即交换速度并继续爬动。三只蚂蚁碰头,则两边的蚂蚁交换速度,中间的蚂蚁仍然静止。如果它们爬到了木棒的边缘(0或100厘米处)则会从木棒上坠落下去。在某一时刻蚂蚁的位置各不相同且均在整数厘米处(即1,2,3,…99厘米),有且只有一只蚂蚁A速度为0

2017-02-16 09:21:13 487

原创 题目1158:买房子

题目描述:    某程序员开始工作,年薪N万,他希望在中关村公馆买一套60平米的房子,现在价格是200万,假设房子价格以每年百分之K增长,并且该程序员未来年薪不变,且不吃不喝,不用交税,每年所得N万全都积攒起来,问第几年能够买下这套房子(第一年房价200万,收入N万)输入:    有多行,每行两个整数N(10输出:    针对每组数据,如果在第20年

2017-02-15 15:28:10 2500

原创 题目1157:中位数

题目描述:中位数定义:一组数据按从小到大的顺序依次排列,处在中间位置的一个数(或最中间两个数据的平均数).给出一组无序整数,求出中位数,如果求最中间两个数的平均数,向下取整即可(不需要使用浮点数)输入:该程序包含多组测试数据,每一组测试数据的第一行为N,代表该组测试数据包含的数据个数,1接着N行为N个数据的输入,N=0时结束输入输出:输出中位

2017-02-15 15:06:47 1223

原创 题目1156:谁是你的潜在朋友

题目描述:    “臭味相投”——这是我们描述朋友时喜欢用的词汇。两个人是朋友通常意味着他们存在着许多共同的兴趣。然而作为一个宅男,你发现自己与他人相互了解的机会并不太多。幸运的是,你意外得到了一份北大图书馆的图书借阅记录,于是你挑灯熬夜地编程,想从中发现潜在的朋友。    首先你对借阅记录进行了一番整理,把N个读者依次编号为1,2,…,N,把M本书依次编号为1,2,…,M。同时,按照

2017-02-15 14:56:33 241

原创 题目1155:鸡兔同笼

题目描述:一个笼子里面关了鸡和兔子(鸡有2只脚,兔子有4只脚,没有例外)。已经知道了笼子里面脚的总数a,问笼子里面至少有多少只动物,至多有多少只动物。输入:第1行是测试数据的组数n,后面跟着n行输入。每组测试数据占1行,每行一个正整数a (a 输出:输出包含n行,每行对应一个输入,包含两个正整数,第一个是最少的动物数,第二个是最多的动物数,两个正整数

2017-02-15 14:48:59 383

原创 题目1154:Jungle Roads

题目描述:       The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtake

2017-02-15 10:22:46 150

原创 题目1481:Is It A Tree?

题目描述:A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following properties

2017-02-14 16:02:33 221

原创 题目1486:False coin

题目描述:The "Gold Bar"bank received information from reliable sources that in their last group of N coins exactly one coin is false and differs in weight from other coins (while all other coins are e

2017-02-14 09:23:33 384

原创 题目1480:最大上升子序列和

题目描述:一个数的序列bi,当b1 你的任务,就是对于给定的序列,求出最大上升子序列和。注意,最长的上升子序列的和不一定是最大的,比如序列(100, 1, 2, 3)的最大上升子序列和为100,而最长上升子序列为(1, 2, 3)。输入:输入包含多组测试数据。每组测试数据由两行组成。第一行是序列的长度N (1 输出:对于每组测试数据,输出

2017-02-13 15:31:59 182

原创 题目1485:W's Cipher

题目描述:Weird Wally's Wireless Widgets, Inc. manufactures an eclectic assortment of small, wireless, network capable devices, ranging from dog collars, to pencils, to fishing bobbers. All these devic

2017-02-13 14:37:32 201

原创 题目1465:最简真分数

题目描述:给出n个正整数,任取两个数分别作为分子和分母组成最简真分数,编程求共有几个这样的组合。输入:输入有多组,每组包含n(n当n=0时,程序结束,不需要处理这组数据。输出:每行输出最简真分数组合的个数。样例输入:73 5 7 9 11 13 153 2 4 50样例输出:17 2该算法

2017-02-13 10:24:48 492

原创 题目1484:Mileage Bank

一直AC不过,但感觉逻辑上没有问题?实在不知错在何处。自己写的比较麻烦,找到一个网上的解法,写得比较简洁,而且四舍五入处值得借鉴。题目描述:Mileage program of ACM (Airline of Charming Merlion) is really nice for the travelers flying frequently. Once you co

2017-02-12 16:38:59 753

原创 题目1060:完数VS盈数

题目描述:一个数如果恰好等于它的各因子(该数本身除外)子和,如:6=3+2+1。则称其为“完数”;若因子之和大于该数,则称其为“盈数”。求出2到60之间所有“完数”和“盈数”。输入:题目没有任何输入。输出:输出2到60之间所有“完数”和“盈数”,并以如下形式输出:E: e1 e2 e3 ......(ei为完数)G: g1 g2 g3 .

2017-02-12 15:04:33 133

原创 题目1062:分段函数

#includeint main() { double n; double res; while (scanf("%lf", &n) != EOF) { if (n >= 0 && n < 2) res = -n + 2.5; if (n >= 2 && n < 4) res = 2 - 1.5 * (n - 3) * (n - 3); if (n >= 4 &&

2017-02-12 10:09:26 319

原创 题目1075:斐波那契数列

该算法时间性能并不是很好,但题目没有对输入的数据进行范围约束,并不好做提前的预处理。#includeint f(int n) { if (n == 1) return 0; if (n == 2) return 1; if (n > 2) { int tmp = f(n - 1) + f(n - 2); return tmp; }}int main() { i

2017-02-12 10:01:22 244

原创 题目1074:对称平方数

#includeint main() { for (int i = 0; i < 256; i++) { int tmp = i * i; int ans = 0; while (tmp != 0) { ans = tmp % 10 + ans * 10; tmp /= 10; } if (i * i == ans) printf("%d\n", i);

2017-02-11 20:40:00 172

原创 题目1073:杨辉三角形

题目中提到了递归函数,但我并没想到合适的递归策略,故直接利用规律存放到数组中。#includeint ans[10000];void f(int n) { if (n == 2) printf("1 1\n"); if (n > 2) { f(n - 1); }}int main() { int n; while (scanf("%d", &n) != EOF) {

2017-02-11 20:28:16 156

原创 题目1072:有多少不同的面值组合?

#includebool mark[200] = { false };int main() { for (int i = 1; i <= 5; i++) mark[i * 8] = true; for (int i = 1; i <= 4; i++) mark[i * 10] = true; for (int i = 1; i <= 6; i++) mark[i * 18]

2017-02-11 15:51:14 229

原创 题目1068:球的半径和体积

使用%lf获取double类型的数据内容,如果使用%f获取double类型的数据内容则会出错,使用%f获取float类型的数据也可。#include#includeint main() { double x0, y0, z0, x1, y1, z1; while (scanf("%lf%lf%lf%lf%lf%lf", &x0, &y0, &z0, &x1, &y1, &z1) !=

2017-02-11 15:27:50 209

原创 题目1077:最大序列和

动态规划,状态转移方程sum[i]=max(sum[i-1]+a,a)#include#include#includeusing namespace std;int main() { int n; long long sum, a, res; while (cin >> n) { cin >> a; sum = a; res = sum; for (int i =

2017-02-11 10:39:38 187

原创 题目1209:最小邮票数

0-1背包问题,具体知识点复习王道机试参考书。#include#define INF 0x7fffffffint getMin(int a, int b) { return a < b ? a : b;}int val[20];int dp[100];int main() { int m, n; while (scanf("%d", &m) != EOF) { scanf

2017-02-09 17:52:14 165

原创 题目1208:10进制 VS 2进制

#include#includestruct bigInteger { int digit[1000]; int size; bigInteger operator+(const bigInteger &A) const { bigInteger res; res.init(); int carry = 0; int tmp = 0; for (int i = 0;

2017-02-09 16:29:48 266

原创 题目1079:手机键盘

#include#includechar str[110];int main() { while (scanf("%s", str) != EOF) { int len = strlen(str); int time = 0; int num1, num2, cnt; if (str[0] == 's') { num1 = (str[0] - 'a' - 1) / 3

2017-02-08 19:27:27 276

原创 题目1081:递推数列

采用传统的方法会导致超时,故查阅资料使用矩阵的快速幂运算。下面注释掉的代码为传统方法。#include#define BIG 10000/* int main() { int a0, a1, p, q, k; while (scanf("%d%d%d%d%d", &a0, &a1, &p, &q, &k) != EOF) { int pre1 = a1; int pre2 =

2017-02-07 13:25:38 303

原创 题目1085:求root(N, k)

坦率地讲,这道题自己没能独立解出来,搜索网上资料,主要有两种方法。方法一:利用推倒的数学公式求解方法二:利用递归求解具体两种方法的原理及其分析过程参考下面的链接。下面一段代码主要是方法一的求解过程,与参考链接中的方法大体一致,只是部分数据类型有所改动。

2017-02-06 21:43:11 448

原创 题目1084:整数拆分

如果n为奇数,则n的拆分中一定有1,故f(n)=f(n-1)。如果n为偶数,则拆分的情形分为有1和无1两种情形,有1的情形为f(n)=f(n-1);无1的情形下,相当于拆分的每一项为偶数,而两部分是一样的,故f(n)=f(n/2)。代码实现中,使用预处理会提高执行速度。在本题中,即使不使用预处理也不会超时,满足题目要求。#include#define BIG 1000000000#

2017-02-06 14:38:58 243

原创 题目1083:特殊乘法

#includeint var1[15], var2[15];int main() { int a, b; while (scanf("%d%d", &a, &b) != EOF) { int len1 = 0, len2 = 0; do { var1[len1++] = a % 10; a /= 10; } while (a != 0); do { va

2017-02-06 10:31:06 156

原创 题目1088:剩下的树

所限定的数的范围较小,哈希即可#includebool mark[10001];int main() { int l, m; while (scanf("%d%d", &l, &m) != EOF) { for (int i = 0; i <= l; i++) mark[i] = true; int a, b; for (int i = 0; i < m; i++) {

2017-02-06 10:14:28 165

空空如也

空空如也

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

TA关注的人

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