算法学习
小步舞曲
这个作者很懒,什么都没留下…
展开
-
算法练习_003 鸡兔同笼
/* 已知鸡和兔的总数量为n,总腿数为m。输入n和m,依次输出鸡的数目和兔子的数目 如果无解,则输出“No answer” 样例输入:14 32 样例输出:12 2 样例输入:10 16 样例输出:No answer*/#include int main(void){ int a, b, m, n; scanf("%d%d", &n,&m); a = (a*n-m)/原创 2011-10-19 23:41:04 · 881 阅读 · 0 评论 -
10361 - Automatic Poetry
Problem IAutomatic PoetryInput: standard inputOutput: standard outputTime Limit: 2 secondsMemory Limit: 32 MB “Oh God”, Lara Croft exclaims, “it’s one of these dumb riddles again!”原创 2012-05-28 23:57:52 · 970 阅读 · 0 评论 -
537 - Artificial Intelligence?
Artificial Intelligence? Physics teachers in high school often think that problems given as text are more demanding than pure computations. After all, the pupils have to read and understan原创 2012-05-29 01:33:11 · 863 阅读 · 0 评论 -
10878 - Decode the tape
Problem ADecode the tapeTime Limit: 1 second"Machines take me by surprise with great frequency."Alan TuringYour boss has just unearthed a roll of old computer tapes. The tape原创 2012-05-30 01:44:16 · 1087 阅读 · 0 评论 -
414 - Machined Surfaces
Machined Surfaces An imaging device furnishes digital images of two machined surfaces thateventually will be assembled incontact with each other. The roughness of this final contact is to原创 2012-05-14 20:34:41 · 4448 阅读 · 0 评论 -
10300 Ecological Premium
Problem AEcological PremiumInput: standard inputOutput: standard outputTime Limit: 1 secondMemory Limit: 32 MBGerman farmers are given a premium depending onthe conditions at their farmyar原创 2012-05-14 18:38:37 · 1591 阅读 · 0 评论 -
445 - Marvelous Mazes
Marvelous Mazes Your mission, if you decide to accept it, is to create a mazedrawing program. A maze will consist of the alphabeticcharactersA-Z, * (asterisk), and spaces.Input and O原创 2012-05-14 22:39:15 · 1571 阅读 · 0 评论 -
488 - Triangle Wave
Triangle Wave In this problem you are to generate a triangular wave form according to a specified pair ofAmplitude and Frequency.Input and OutputThe input begins with a single positive i原创 2012-05-15 14:40:28 · 2360 阅读 · 0 评论 -
458 - The Decoder
The Decoder Write a complete program that will correctly decode a set ofcharacters into a valid message. Your program shouldread a given file of a simple coded set of characters and print原创 2012-05-14 18:57:14 · 675 阅读 · 0 评论 -
494 - Kindergarten Counting Game
Kindergarten Counting Game Everybody sit down in a circle. Ok. Listen to me carefully.``Woooooo, you scwewy wabbit!''Now, could someone tell me how many words I just said?Input and原创 2012-05-14 19:14:30 · 913 阅读 · 0 评论 -
勇士Hashmat 100055
Problem AHashmat the brave warriorInput: standard inputOutput: standard output Hashmat is a brave warrior who with his group of young soldiers moves from one place to another to fight agains原创 2012-05-14 17:05:52 · 1471 阅读 · 0 评论 -
401 - Palindromes
Palindromes A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string"ABCDEDCBA" is apalindrome because it is the same when the原创 2012-05-17 11:29:27 · 838 阅读 · 0 评论 -
489 - Hangman Judge
Hangman Judge In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the转载 2012-05-20 22:53:22 · 843 阅读 · 0 评论 -
给定一串数字求连续的最大和
题目描述:有31,-41,59,26,-53,58,97,-93,-23,84十个数。SUM(N,M)表示从第N个数到到第M个数的和。例如:SUM(2,3)=-41+59=18。问:最大的和是多少?对应的N和M是多少?算法思想:数组中的数字可以看做用负数分割开的一段一段正数,先找出这几段正数中和最大的那段(这题的结果的那串数字必定包括和最大的那串正数)然后慢慢的向两边扩散。文字功底不是原创 2012-01-19 14:33:56 · 3596 阅读 · 3 评论 -
阶乘的精确值
#include #include #define MAXN 3000int f[MAXN];int main(void){ int i, j, n; int s, c; //s为积 c为进位值 scanf("%d", &n); memset(f, 0, sizeof(f)); f[0] = 1; for (i=2; i<=n; ++i) { c = 0; f转载 2011-12-05 23:06:48 · 688 阅读 · 0 评论 -
算法练习_002 变量交换
/* 输入两个整数a和b,交换二者的值,然后输出 输入: 11 22 输出: 22 11*/#include int main(void){ int a, b; scanf("%d%d", &a, &b); printf("%d %d\n", b, a); return 0;}原创 2011-10-19 23:26:05 · 754 阅读 · 0 评论 -
算法练习_001 三位数反转
/* 三位数反转 输入一个三位数,分离出它的百位,十位和个位,反转后输出。 样例输入:127 样例输出:721*/#include int main(void){ int n; scanf("%d", &n); printf("%d%d%d\n", n%10, n/10%10, n/100); return 0;}#include int main(voi原创 2011-10-19 23:23:17 · 3761 阅读 · 0 评论 -
算法练习_004 查找第一个不重复的字符
题目:在一个字符串中找到第一个只出现一次的字符。如输入abaccdeff,则输出b#include #define MaxSize 255int FirstDChar(char a[], int n){ int i=0, j=n; //flag数组记录该元素是否被比较过 初始值都为0 int flag[MaxSize] = {0}; while (i < j) {原创 2011-10-31 00:04:46 · 697 阅读 · 0 评论 -
三天打鱼两天晒网
中国有句俗语叫 “ 三天打鱼两天晒网 ” 。某人从 1990 年 1 月 1 日起开始 “ 三天打鱼两天晒网 ” , 问这个人在以后的某一天中是 “ 打鱼 ” 还是 “ 晒网 ” 。#include #include int main(void){ int M[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31}; int Y[原创 2011-12-05 00:54:49 · 1568 阅读 · 1 评论 -
要发就发
请将不超过 1993 的所有素数从小到大排成第一行,第二行上的每个素 数都等于它右肩上的素数之差。编程求出:第二行数中是否存在这样的若干个连续的整数, 它们的和恰好是 1898 ?假好存在的话,又有几种这样的情况?第一行: 2 3 5 7 11 13 17......1979 1987 1993第二行: 1 2 2 4 2 4...... 8 6#include #include原创 2011-12-05 00:57:07 · 1069 阅读 · 0 评论 -
黑与白
有 A 、 B 、 C 、 D 、 E 五人,每人额头上都帖了一张黑或白的纸。五人对坐,每人都可以看到其它人额头上的纸的颜色。五人相互观察后,A 说: “ 我看见有三人额头上帖的是白纸,一人额头上帖的是黑纸。 ”B 说: “ 我看见其它四人额头上帖的都是黑纸。 ”C 说: “ 我看见一人额头上帖的是白纸,其它三人额头上帖的是黑纸。 ”D 说: “ 我看见四人额头上帖的都是白纸。原创 2011-12-05 00:59:09 · 1602 阅读 · 0 评论 -
谁家孩子
一天,三家的九个孩子在一起比赛短跑,规定不分年龄大小, 跑第一得 9 分,跑第 2 得 8 分,依此类推。比赛结果各家的总分相同,且这些孩子没有同时到达终点的,也没有一家的两个或三个孩子获得相连的名次。已知获第一名的是李家的孩子, 获得第二的是王家的孩子。问获得最后一名的是谁家的孩子?#include int main(void){ int l1, l2, w1, w2, o1, o2原创 2011-12-05 01:00:39 · 807 阅读 · 0 评论 -
评委评分
在歌星大奖赛中,有 10 个评委为参赛的选手打分,分数为 1~100 分。选手最后得分为:去掉一个最高分和一个最低分后其余 8 个分数的平均值。请编写一个程序实现。题目条件不变,但考虑同时对评委评分进行裁判,即在 10 个评委中找出最公平和最不公平 …#include #define MAXN 10int main(void){ float score[MAXN] = {0.0};原创 2011-12-05 00:53:55 · 2918 阅读 · 0 评论 -
谁在说谎
张三说李四在说谎,李四说王五在说谎,王五说张三和李四都在说谎。现在问:这三人中 到底谁说的是真话,谁说的是假话?分析题目,每个人都有可能说的是真话,也有可能说的是假话,这样就需要对每个人所说的话进行分别判断。#includevoid main(){ int a,b,c; for(a=0;a<=1;a++) for(b=0;b<=1;b++)原创 2011-12-05 00:57:44 · 940 阅读 · 0 评论 -
委派任务
某侦察队接到一项紧急任务,要求在 A 、 B 、 C 、 D 、 E 、 F 六个队员中尽可能多地挑若干人,但有以下限制条件:1)A 和 B 两人中至少去一人;2)A 和 D 不能一起去;3)A 、 E 和 F 三人中要派两人去;4)B 和 C 都去或都不去;5)C 和 D 两人中去一个;6) 若 D 不去,则 E 也不去。问应当让哪几个人去?#include原创 2011-12-05 00:58:26 · 800 阅读 · 0 评论 -
新娘和新郎
三对情侣参加婚礼,三个新郞为 A 、 B 、 C ,三个新娘为 X 、 Y 、 Z 。有人不知道谁和谁结婚 ,于是询问了六位新人中的三位,但听到的回答是这样的: A 说他将和 X 结婚; X 说她的未婚夫是 C ; C 说他将和 Z 结婚。这人听后知道他们在开玩笑,全是假话。请编程找出谁将和谁 结婚。#include int main(void){ int a, b, c = 'y';原创 2011-12-05 00:59:59 · 1141 阅读 · 0 评论 -
求车速
一辆以固定速度行驶的汽车,司机在上午 10 点看到里程表上的读数是一个对称数 ( 即这个数从左向右读和从右向左读是完全一样的 ) ,为 95859 。两小时后里程表上出现了一个新的对称数。问该车的速度是多少?新的对称数是多少?#include #include int main(void){ int n, n1, n2; int temp; n = n1 = n2 = 95859原创 2011-12-05 00:56:19 · 1186 阅读 · 0 评论 -
捕鱼分鱼
A 、 B 、 C 、 D 、 E 五个人在某天夜里合伙去捕鱼,到第二天凌晨时都疲惫不堪,于是各自找地方睡觉。日上三杆, A 第一个醒来,他将鱼分为五份,把多余的一条鱼扔掉,拿走自己 的一份。 B 第二个醒来,也将鱼分为五份,把多余的一条鱼扔掉,保持走自己的一份。 C 、 D 、E 依次醒来,也按同样的方法拿走鱼。问他们合伙至少捕了多少条鱼?#include int main(void)原创 2011-12-05 00:55:41 · 1273 阅读 · 0 评论 -
10010 - Where's Waldorf?
Where's Waldorf? Given a m by n grid of letters, ( ), and a list of words, find the location in the grid at which the word can be found. A word matches a straight, uninterrupted line o原创 2012-05-25 23:00:25 · 1865 阅读 · 0 评论