05 2015 档案
摘要:问题:As an experienced ACMer, you must have known the importance of "code template library". With the help of pre-printed code library, you can implemen...
阅读全文
摘要:问题:In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people in...
阅读全文
摘要:问题:给出一个数,计算出其全排列结果。回答:方法一:#include #include #include #define maxN 4using namespace std; int main(){ int p[maxN] = {-1}; for(int i=0; i#include //#def...
阅读全文
摘要:问题:Biologists finally invent techniques of repairing DNA that contains segments causing kinds of inherited diseases. For the sake of simplicity, a DNA...
阅读全文
摘要:问题:Candy and his friends found a treasure map. With the help of the map, they successfully found the treasure inside an ancient cave, but just as they...
阅读全文
摘要:问题:John is going on a fishing trip. He has h hours available (1 = 0 ), is known. Each 5 minutes of fishing decreases the number of fish expected to be...
阅读全文
摘要:问题:Input输入的第一行是一个整数T( 1 #include #include #include #includeusing namespace std;#define M 2005int a[M][26],b[26];vectorQ;void main(){ int T; scanf("%d"...
阅读全文
摘要:问题:In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryptio...
阅读全文
摘要:问题:给定一个整数N,那么N的阶乘N!末尾有多少个0? 比如:N=10,N!=3628800,N!的末尾有2个0,写出算法。回答:int countZero(int N) { int ans = 0; int maxInt = 1000000000;//10^9 int tmpn = N; whil...
阅读全文
摘要:问题:在25匹马中,挑选最快的三匹马,每场比赛最多只能有5匹马一起参赛。请问最少需要进行多少场比赛?回答:至少需要进行7场比赛。给25匹马编号:A1 A2 A3 A4 A5 B1 B2 B3 B4 B5C1 C2 C3 C4 C5 D1 D2 D3 D4 D5E1 E2 E3 E4 E5按照A1-A...
阅读全文
摘要:问题:Tetris (Russian: Тeтрис) is a puzzle video game originally designed and programmed by Alexey Pajitnov in the Soviet Union. The Tetris game is a pop...
阅读全文
摘要:问题:打印出杨辉三角形的前n行(nint main() { int n; scanf("%d",&n); int arr[25][25]; int i,j; //计算每一行的值 arr[1][1] = 1; for( i=2; i<=20; i++){ arr[i][1] = arr[i][i] ...
阅读全文
摘要:问题:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will b...
阅读全文
摘要:问题:输入一个正整数(<10000),输出颠倒后的整数。【样例输入】1234【样例输出】4321回答:#include int main(){ int num ; scanf("%d",&num); int x,y,z,n,result; if(num > 999) { x = num / 1000...
阅读全文
摘要:问题:InputThe first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set consists of a...
阅读全文
摘要:问题:有一扇门, 一开始是好的, 一次来了n个人, 每个人有p的概率把门弄坏, 维修门的费用为a, 被一个人发现门坏的罚款为b, 求期望最小花费。回答:用f[i][0]表示第i个人来之前门坏, 到结束时的期望最小花费, f[i][1]则表示门好. 显然f[n][0] = min(a, b), f[n...
阅读全文
摘要:问题:设有n 个程序{1,2,…, n }要存放在长度为L的磁带上。程序i存放在磁带上的长度是i l , 1 ≤i ≤n。程序存储问题要求确定这n 个程序在磁带上的一个存储方案,使得能够在磁带上存储尽可能多的程序。对于给定的n个程序存放在磁带上的长度,编程计算磁带上最多可以存储的程序数。回答:题目要...
阅读全文
摘要:问题:输入:输入数据有多组,每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有S个,草儿想去的地方有D个; 接着有T行,每行有三个整数a,b,time,表示a,b城市之间的车程是time小时;(1=#include#include#includeusing namespace s...
阅读全文
摘要:问题:给定两个字符串,求它们前后重叠的最长子串的长度,比如”abcde”和“cdefg”是”cde”,长度为3。输入: 输入可能包含多个测试案例。 对于每个测试案例只有一行, 包含两个字符串。字符串长度不超过1000000,仅包含字符’a'-’z'。输出: 对应每个测试案例,输出它们前后重叠的最长子...
阅读全文
摘要:问题:写一个函数,求两个整数的之和,要求在函数体内不得使用+、-、×、÷。回答:这题本质是考察对位运算的理解和运用。首先我们可以分析人们是如何做十进制的加法的,比如是如何得出5+17=22这个结果的。实际上,我们可以分成三步的:第一步只做各位相加不进位,此时相加的结果是12(个位数5和7相加不要进位...
阅读全文
摘要:问题:我们经常会遇见这些问题比如给你一个容量为5升的杯子和一个容量为3升的杯子,水不限使用,要求精确得到4升水并写出算法。回答:1) 直接以简答的方式给定方案这个比较简单,即便是不知道什么原理,也可以很快凑出来。假设两个杯子分别为x 5升杯, y 3升杯 : 装满 x ; x -> y ;清空Y ;...
阅读全文
摘要:问题:把源字符串拷贝到目的字符串,如果指定关键字,则以该关键字结束(不包括关键字本身),如果拷贝失败,则得到空串。具体要求:实现如下函数原型SafeStrcpy2KeyWord(),并在代码中调用该函数实现上述功能。该函数的实现要考虑各种可能的参数取值,以确保程序不出现崩溃。int SafeStrc...
阅读全文
摘要:问题:将一个链表反转写出算法。回答:方法一:#include#include/* 链表节点 */struct node{ int data; struct node* next;};/* 反转单链表. 分别用3个指针,指向前一个,当前,下一个 */static void reverse(struct...
阅读全文
摘要:问题:通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。比如字符串“abacacde”过滤结果为“abcde”。要求实现函数:void stringFilter(const char *pInputStr, long l...
阅读全文
摘要:问题:给定一个十进制整数N,求出从1到N的所有整数中出现”1”的个数。 例如:N=2时 1,2出现了1个 “1” 。N=12时 1,2,3,4,5,6,7,8,9,10,11,12。出现了5个“1”。回答:#include#include#includelong long int Count(lon...
阅读全文
摘要:问题:There are n points in the plane. Your task is to pick k points (k>=2), and make the closest points in these k points as far as possible. 输入:For eac...
阅读全文
摘要:问题:输入三角形三边长,判断是否是直角三角形写出算法。InputThe inputs start with a line containing a single integer n. Each of the n following lines contains one test case. Each...
阅读全文
摘要:问题:在嵌入式系统开发中,Modbus协议是工业控制系统中广泛应用的一种协议。本题用来简单模拟Modbus协议,只需根据条件生成符合该协议的数据帧,并解析所获取的数据。假设设备使用的协议发送数据格式如下: 其中前四项将在输入条件中给出,最后一项为CRC校验和,需根据前四项的数据,按照CRC算法...
阅读全文
摘要:问题:Input输入数据有多组。每组数据的第一行有两个正整数n,m(0 #include #include #include #include #include using namespace std; const int MAX = 1003; const int dirx[5] =...
阅读全文
摘要:问题:给你一个字符串,然后让你把所有的前缀给找出来,并把它们在字符串中的出现次数相加,输出这个和写出算法。InputThe first line is a single integer T, indicating the number of test cases.For each case, the...
阅读全文
摘要:问题:When a number is expressed in decimal, the kth digit represents a multiple of 10k. (Digits are numbered from right to left, where the least signifi...
阅读全文
摘要:问题:给定一个数值,判断他是否等于一连串素数之和(这些素数必须是连续的)。输出满足条件的组合的个数。题解:预先求出连续的素数和。然后找到不大于n的最大素数,那么所有的组合(连续不断的素数)只可能在此范围内。一些正整数可以通过和一个或多个连续的素数表示。有多少这样的陈述是一个给定的正整数吗?例如,整数...
阅读全文
摘要:问题:给定两个正整数,计算这两个数的最小公倍数并写出算法。Input输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.Output对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。Sample Input10 14Sample Output70回答:#include ...
阅读全文
摘要:问题:Consider a three-parameter recursive function w(a, b, c):if a 20 or b > 20 or c > 20, then w(a, b, c) returns:w(20, 20, 20)if a #include cons...
阅读全文
摘要:问题:InputThe input consists of one or more sets of strings, followed by a final line containing only the value 0. Each set starts with a line containin...
阅读全文
摘要:问题: 有三个正整数a,b,c(0int gcd(int a,int b){ returnb==0?a:gcd(b,a%b);}intmain(){ int n;scanf("%d",&n); inta,b,c,i;while(n--){scanf("%d%d",&a,&b);for(i=2;i<=...
阅读全文
摘要:问题:InputThe input consists of n cases, and the first line consists of one positive integer giving n. The next n lines each contain 3 integers, r, e an...
阅读全文
摘要:问题:一个 n 阶方阵的元素是1,2,...,n^2,它的每行,每列和2条对角线上元素的和相等,这样的方阵叫魔方。n为奇数时我们有1种构造方法,叫做“右上方” ,例如下面给出n=3,5,7时的魔方.38 1 63 5 74 9 2517 24 1 8 1523 5 7 14 164 6 13 20 ...
阅读全文
摘要:问题:输入规格:每个输入文件包含一个测试用例。对于每一种情况下,有一行文字不超过长度1048576个字符的,由回车'\ N'终止。输入中包含的至少一个字母数字字符,即,从集合[0-9 AZ AZ]一个字符。输出规格:对于每一个测试的情况下,打印在一行中的输入文本最常发生的词,后跟一个空格和的时候,它...
阅读全文
摘要:问题:Excel可以对一组纪录按任意指定列排序。现请你编写程序实现类似功能算法。Input测试输入包含若干测试用例。每个测试用例的第1行包含两个整数 N ( #include #include #define maxn 100005 using namespace std; struc...
阅读全文
摘要:问题:完数的定义:如果一个大于1的正整数的所有因子之和等于它的本身,则称这个数是完数,比如6,28都是完数:6=1+2+3;28=1+2+4+7+14,本题的任务是判断两个正整数之间完数的个数。Input输入数据包含多行,第一行是一个正整数n,表示测试实例的个数,然后就是n个测试实例,每个实例占一行...
阅读全文
摘要:问题: 速算24点相信绝大多数人都玩过。就是随机给你四张牌,包括A(1),2,3,4,5,6,7,8,9,10,J(11),Q(12),K(13)。要求只用'+','-','*','/'运算符以及括号改变运算顺序,使得最终运算结果为24(每个数必须且仅能用一次)。游戏很简单,但遇到无解的情况往往让人...
阅读全文
摘要:问题:Cipher textA B C D E F G H I J K L M N O P Q R S T U V W X Y ZPlain textV W X Y Z A B C D E F G H I J K L M N O P Q R S T UInputInput to this probl...
阅读全文
摘要:问题:样例输入210:37:4900:00:01样例输出1 011001100010100011 001010100101110001 2 000000000000000001 000000000000000001题意:将时间按照题意竖向和横向输出回答:#include #include #in...
阅读全文
摘要:问题:读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值并写出算法。回答:#include#include#includeusing namespace std;char Precede(char a,char b);double operate(double a1,cha...
阅读全文
摘要:问题:比赛时间又一次开始,看到气球漂浮是多么令人兴奋啊!但是,要告诉你一个秘密,法官最喜欢的时间是猜测最受欢迎的问题。当测试结束后,他们将计数每一种颜色的气球,再找出结果。今年,他们决定把最“可爱”的问题留给你。输入: 输入多组测试用例,每个用例以一个数字N(0#include #includ...
阅读全文
摘要:问题:如题回答:#include #include int p(int n) { int ans,r; if(n==1) return 1; ans=0; r=(int)(sqrt(8*n+1)-1)/2; ans+=pow(2,r)-1; ans+=2*p(n-r); retur...
阅读全文
摘要:问题:1~n编号的彩票,要买全,等概率条件下平均要买几张要求写出算法。回答:已经买了m张时,买中剩下的概率为1-m/n,则要买的张数为1/(1-m/n)n=2,s=1+1/(1-1/2);n=3,s=1+1/(1-1/3)+1/(1-2/3)s=1+1/(1-1/n)+1/(1-2/n)+1/(1-...
阅读全文
摘要:问题: (n int main() { int f[10]={1,1,2,6,24,120,720,5040,40320,362880}; int n; double e; printf("n e\n"); printf("- -----------\n"); printf("%d %...
阅读全文
摘要:问题:SUM(n) = 1 + 2 + 3 + ... + n写个算法回答:#includeint main(){ int n,sum; while(scanf("%d",&n)!=EOF) { if(n%2==0) //oushu sum=n/2*(n+1); else sum=(n+1)/2*n...
阅读全文