早教吧 育儿知识 作业答案 考试题库 百科 知识分享

急切求问ACM的两道题!1>ProblemDescriptionTheleastcommonmultiple(LCM)ofasetofpositiveintegersisthesmallestpositiveintegerwhichisdivisiblebyallthenumbersintheset.Forexample,theLCMof5,7and15is105.InputInputwi

题目详情
急切求问ACM的两道题!
1>Problem Description
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.
Input
Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 ... nm where m is the number of integers in the set and n1 ... nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.
Output
For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.
Sample Input
2
3 5 7 15
6 4 10296 936 1287 792 1
Sample Output
105
10296
我的答案总是显示wrong answer!求教:
#include
int gcd(int da,int xiao)
{ int temp;
while (xiao!=0)
{
temp=da%xiao;
da=xiao;
xiao=temp;
}
return(da);
}
void main()
{
int x,m,n,n1,t,i,j;
scanf("%d",&n);
for(i=0;i
Elevator
Problem Description
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.
Input
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.
Output
Print the total time on a single line for each test case.
Sample Input
1 2
3 2 3 1
0
Sample Output
17
41
我的答案:#include
void main()
{
int n,a,t,x,i;
while (scanf("%d",&n),n){
a= 0;
t =0;
for (i=0; ia)
t+= (x-a)*6+5;
if (x
▼优质解答
答案和解析
1. 虽然题目说所有结果都在32bit(unsigned int)以内,但是中间结果x*s可能会超出这个范围,用unsigned int都表示不了,所以得用long long或者用高精度.
2. while(scanf("%d",&n),n)这个是本来就有的语法错误还是你不小心弄错的.但题目其实表述得不是很完整,如果N的取值在10的6次方以内,那么最有可能错的是电梯有可能连续在同一层停多次(x==a)!否则就是得用long long来存结果.
最好给出这些题的出处,好让回答者去试试呀~