UVa1260 - Sales

本文探讨了CozyWalk公司CEO使用每日销售报告进行趋势分析的方法,并通过算法计算过去销售金额低于或等于当前金额的天数,从而形成趋势列表。通过分析这个列表,可以总结出销售趋势并进行预测。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mr. Cooper, the CEO of CozyWalk Co., receives a report of daily sales every day since the company has been established. Starting from the second day since its establishment, on receiving the report, he compares it with each of the previous reports in order to calculate the number of previous days whose sales amounts are less than or equal to it. After obtaining the number of such days, he writes it in a list.

This problem can be stated more formally as follows. Let A = (a1, a2,..., an) denote the list of daily sales amounts. And let B = (b1, b2,..., bn-1) be another integer list maintained by Mr. Cooper, each value representing the number of such previous days. On the i-th day (2$ \le$i$ \le$n), he calculates bi-1, the number of ak's such that ak$ \le$ai (1$ \le$k < i).

For example, suppose that A = (20, 43, 57, 43, 20). For the fourth day's sales amount, a4 = 43, the number of previous days whose sales amounts are less than or equal to it is 2 since a1$ \le$a4, a2$ \le$a4, and a3 > a4. Therefore, b3 = 2. Similarly, b1, b2, and b4 can be obtained and it results in B = (1, 2, 2, 1).

Given an array of size n for the list of daily sales amounts, write a program that prints the sum of the n - 1 integers in the list B.

Input 

Your program is to read the input from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case starts with a line containing an integer n (2$ \le$n$ \le$1, 000), which represents the size of the list A . In the following line, n integers are given, each represents the daily sales amounts ai (1$ \le$ai$ \le$5, 000 and 1$ \le$i$ \le$n) for the test case.

Output 

Your program is to write to standard output. For each test case, print the sum of the n - 1 integers in the list B which is obtained from the list A.

The following shows sample input and output for two test cases.

Sample Input 

2
5
38 111 102 111 177
8
276 284 103 439 452 276 452 398

Sample Output 

9
20
#include <cstdio>

using namespace std;

const int N = 1010;

int a[N], b[N];
int n;

void input();
void solve();

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("d:\\OJ\\uva_in.txt", "r", stdin);
	#endif
	
	int t;
	scanf("%d", &t);
	
	while (t--) {
		input();
		solve();
	}
	
	return 0;
}

void input()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
}

void solve()
{
	for (int i = 1; i < n; i++) {
		int cnt = 0;
		for (int j = 0; j < i; j++) {
			if (a[j] <= a[i]) cnt++;
		}
		b[i - 1] = cnt;
	}
	
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		ans += b[i];
	}
	
	printf("%d\n", ans);
}



内容概要:本文详细探讨了基于阻尼连续可调减振器(CDC)的半主动悬架系统的控制策略。首先建立了CDC减振器的动力学模型,验证了其阻尼特性,并通过实验确认了模型的准确性。接着,搭建了1/4车辆悬架模型,分析了不同阻尼系数对悬架性能的影响。随后,引入了PID、自适应模糊PID和模糊-PID并联三种控制策略,通过仿真比较它们的性能提升效果。研究表明,模糊-PID并联控制能最优地提升悬架综合性能,在平顺性和稳定性间取得最佳平衡。此外,还深入分析了CDC减振器的特性,优化了控制策略,并进行了系统级验证。 适用人群:从事汽车工程、机械工程及相关领域的研究人员和技术人员,尤其是对车辆悬架系统和控制策略感兴趣的读者。 使用场景及目标:①适用于研究开发基于CDC减振器的半主动悬架系统的工程师;②帮助理解不同控制策略(如PID、模糊PID、模糊-PID并联)在悬架系统中的应用及其性能差异;③为优化车辆行驶舒适性和稳定性提供理论依据和技术支持。 其他说明:本文不仅提供了详细的数学模型和仿真代,还通过实验数据验证了模型的准确性。对于希望深入了解CDC减振器工作原理及其控制策略的读者来说,本文是一份极具价值的参考资料。同时,文中还介绍了多种控制策略的具体实现方法及其优缺点,为后续的研究和实际应用提供了有益的借鉴。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值