杭电 ACM Steps解题报告 #include<iostream>
using namespace std;
int p[70];
int biaoji[4];
int num;
int check( int m , int pos , int Now ) {
if(m == 0 ) return true; if(p[m] == pos || p[m] == Now ) { memset(biaoji, 0 , sizeof(biaoji)); biaoji[pos] = 1; biaoji[Now] = 1; int i; for( i = 1 ; i <= 3 ; i++ ) { } if(!biaoji[i]) break;
}
} check( m - 1 , i , p[m]); else return false;
void slove(int n) {
}
int main() {
int test; scanf("%d" , &test ); int flag = 1; if(!check( n , 3 , 1)) if(!flag) printf("false\n"); flag = 0; else printf("true\n");
} while(test -- ) { } return 0; int i , j , n , temp; scanf("%d" , &n); memset( p , 0 , sizeof(p) ); for( i = 1 ; i <= 3 ; i++ ) { } slove(n); scanf("%d" , &num); for( j = 0 ; j < num ; j++ ) { } scanf("%d" , &temp); p[temp] = i;
这是一个汉诺塔问题,要求将A柱上的n个盘子原样移动到C盘,每次只能移动一个盘子,且盘子可以插在A,B,C任意一个盘子上。且任何时刻都不能将较大的盘子压
在较小的盘子上。那么如何实现移动圆盘的操作呢?我们可以用递归函数求解,在执行函数时,多次进行自我调用。再断实际移动与输入相比是否正确,如是就返回ture,否则返回false。
第二篇:杭电ACM_1002解题报告
A + B Problem II1.链接地址http://acm./showproblem.php?pid=10022.问题问题描述I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.输入数据The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.输出要求For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.输入样例21 2112233445566778899 998877665544332211输出样例Case 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 11xxxxxxxxxxxx11103.解题思路简单的基础题,是大数相加问题。问题可以分解为IO模块和计算模块,核心为大数表示和记法。经过权衡,以10为基,每一个数字使用一个字节来存储,这样可以最大程度的简化输入和输出问题;存储大数的顺序采用低字节在前,高字节在后的方式,这样可以避免数位对齐和进位的问题;已明确输入数据均为正整数,所以不必考虑符号。4.源代码#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>typedef unsigned int UINT;typedef unsigned char Byte;UINT GetN(Byte *a){UINT i, ch, t, sz = 0;while((ch = getchar()) != EOF && isdigit(ch)){a[sz++] = ch - '0';}for(i = 0; i < sz / 2; i++){t = a[i];a[i] = a[sz - 1 - i];a[sz - 1 - i] = t;}return sz;}void PutN(Byte *a, UINT s){UINT i;for(i = s - 1; i > 0; i--){putchar(a[i] + '0');}putchar(a[0] + '0');}int main(){UINT n, i, j, sa, sb, ss;int ch;Byte A[1000], B[1000], c;scanf("%d\n", &n);for(i = 1; i <= n; i++){memset(A, 0, 1000);memset(B, 0, 1000);c = 0;printf("Case %d:\n", i);sa = GetN(A);PutN(A, sa);printf(" + ");sb = GetN(B);PutN(B, sb);printf(" = ");//calculatess = (sa > sb) ? sa : sb;for(j = 0; j < ss; j++){ch = A[j] + B[j] + c;A[j] = (ch) % 10;c = (ch) / 10;}if(c > 0)A[ss++] = c;PutN(A, ss);printf("\n");if(i < n)printf("\n");}return 0;}