TAG 水题 先找出大的count,比如A,组成A B A B .... A B A 这样,A包在外面,再把多余的A加塞进去,能塞多少是多少。 注意处理 max 0 的边界情况 #include <stdio.h> //#include <string.h> //const int N=205; int countA, countB, maxA, maxB, ans; int pieceA, pieceB; int max(const int &x, const int &y) { return x>y ? x :y; } int min(const int &x,const int &y) { return x<y ? x : y; } int cal() { int rest; if ( maxA == 0 ) return maxB > countB ? countB : maxB; if ( maxB == 0 ) return maxA > countA ? countA : maxA; if ( countA > countB ) { rest = countA - countB -1; return countB*2+1 + min( rest, (countB+1)*(maxA-1) ); } if ( countA < countB ) { rest = countB - countA -1; return countA*2+1 + min( rest, (countA+1)*(maxB-1) ); } return countA*2; } int main(int argc, char *argv[]) { while ( scanf("%d%d%d%d", &countA, &countB, &maxA, &maxB)!=EOF ) { ans = cal(); printf("%d/n", ans); } return 0; }