懂C语言、C++、JAVA编写程序的请进!!!!!!急!!!!!!

2025-03-04 13:21:12
推荐回答(2个)
回答1:

给你个提示好吧,代码我不想写了,可以将桌面扩展假设其碰到长边反弹,而到了短边就通过...
给个例子:
/*
Table Tennis

Time limit: 1s Memory limit: 32768
Total Submit : 8 Accepted Submit : 3

Problem
There is a rectangular pool table ABCD with side lengths m and n, where m and n are integers with mcue ball at corner A and shoot it at a 45 angle to the sides, and it reflects perfectly (at 45 degres) off all sides,
and never loses energy. The table has four pockets, one in each corner, and the ball will be sunk as soon as it hits a
corner. The question is : given the integers m and n, how do you tell which pocket the ball hits first, and how many
reflections will the ball make on the way?
Assume A,B,C,D is the lower left corner,upper left corner, upper right corner, lower right corner respectively. The
length of AB is m, and the length of AD is n.

B---------C
| |
| |
A---------D

Input
Input consist of mutiple cases. Each case include two integers m and n, both of which fits in 32-bit signed integer.
Output
For each case, you should find out which pocket (A,B,C,D) the ball first hit and how many reflections the ball make .

Sample input
6 10

Sample output
C 6

*/
#include

int gcd(int a,int b){
if(a==b) return a;
if(a>b) return gcd(a-b,b);
else return gcd(b-a,a);
}

int main(){
int m,n;
while(scanf("%d%d",&m,&n)!=EOF){
int a,b,L;
L=(m*n)/gcd(m,n);//经过的长度
a=L/m;//平行碰的次数+1
b=L/n;//垂直碰的次数+1
if(b%2==1){
if(a%2==1) printf("C ");
else printf("D ");
}
else{
if(a%2==1) printf("B ");
else printf("A ");
}
printf("%d\n",a+b-2);
}
return 0;
}

回答2:

可以翻译成汉语吗