早教吧作业答案频道 -->英语-->
急切求问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>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来存结果.
最好给出这些题的出处,好让回答者去试试呀~
2. while(scanf("%d",&n),n)这个是本来就有的语法错误还是你不小心弄错的.但题目其实表述得不是很完整,如果N的取值在10的6次方以内,那么最有可能错的是电梯有可能连续在同一层停多次(x==a)!否则就是得用long long来存结果.
最好给出这些题的出处,好让回答者去试试呀~
看了急切求问ACM的两道题!1>P...的网友还看了以下:
平方根一个面积为8的正方形一个面积为2的正方形如图13.1-1,由4个如图13.1-1②的小正方形 2020-04-27 …
问题1求a.b的值 问题2若九年级学生捐款解决了其余贫困中,小学生的学习费用,求九年级学生可资问题 2020-05-16 …
已知二次函数的图象过点A(-3,0)和点B(1,0),且与轴交于点C,D点在抛物线上且横坐标是-2 2020-06-08 …
已知命题:存在x∈{x|-11|,x^2-x-m=0是真命题.已知命题:存在x属于{x|-11|, 2020-08-01 …
几道高数题1.求和函数y=hx-x^2在Ox轴上相交的曲线方程2.求Z=arctanxy再第一个坐标 2020-11-01 …
求证一道求逆函数的题原题是这样的函数f(x)=3x^2-4(x>=0),回答以下问题1.求f(x)的 2020-11-20 …
第一题[1]f(x)=4x+7分之1[2]f(x)=√1-x+√x+3-1(√是根号)根号X+3减1 2020-12-31 …
大一高等数学题1,求二元函数z=x²y+xy²+1在(1,2)处的编导数.2,证明:球体的体大一高等 2021-01-13 …
数学帝进十万火急跪求了一次数学考试中有A.B.C三道填空题为选做题,规定每个考生必须也只需选做其中两 2021-01-22 …
y=x+1/x²+x+4的值域怎么求,急求答案啊啊啊!望大神再帮学渣解决两个问题.1.求y=x²+x 2021-02-18 …