1008 Elevator (20 分)
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.
Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.
For each test case, print the total time on a single line.
3 2 3 1
41
题目大意:给定一个电梯要停留的层数list,每层要停5s,每上一层要6s,下一层要4s。输出总秒数。一开始没看仔细,把第一个数字也算成指定停留层,还有一个坑是,如果层数相同,也就是不动,也要续5s。
解题思路:很简单的随便模拟一下就好了。
代码如下
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int n;
int cur = 0;
int stay = 0;
int sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> cur;
if (cur >= stay) {
sum += 6 * (cur - stay) + 5;
}
else {
sum += 4 * (stay - cur) + 5;
}
stay = cur;
}
cout << sum << endl;
return 0;
}
1009.
1009 Product of Polynomials (25 分)
This time, you are supposed to find A×B where A and B are two polynomials.
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:
K N1 aN1 N2 aN2 ... NK aNK
where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10, 0≤NK<⋯ For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place. 题目大意:很容易理解,模拟一下多项式的乘法。保留一位小数的系数和次数从大到小输出一下就好了。 解题思路:没想到什么高效的算法,可能和矩阵链乘法的方法相关,看题目要求数据不高就随便搞个暴力的三重循环算了。要注意一点就是如果结果为0的话直接输出0. 代码如下: Output Specification:
Sample Input:
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output:
3 3 3.6 2 6.0 1 1.6
#include