UVa1260 - Sales
来源:互联网 发布:java enum valueof 编辑:程序博客网 时间:2024/05/17 07:02
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 letB = (b1, b2,...,bn-1) be another integer list maintained by Mr. Cooper, each value representing the number of such previous days. On thei-th day (2in), he calculates bi-1, the number of ak's such that akai (1k < 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 sincea1a4,a2a4, anda3 > a4. Therefore,b3 = 2. Similarly, b1, b2, andb4 can be obtained and it results inB = (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 then - 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 integern (2n1, 000), which represents the size of the list A . In the following line,n integers are given, each represents the daily sales amountsai (1ai5, 000 and 1in) for the test case.
Output
Your program is to write to standard output. For each test case, print the sum of then - 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
2538 111 102 111 1778276 284 103 439 452 276 452 398
Sample Output
920
#include <cstdio>using namespace std;const int N = 1010;int a[N], b[N];int n;void input();void solve();int main(){#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);#endifint 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);}
- UVa1260 - Sales
- Market-Sales
- Sales 案例
- Sales Document
- Sales Order
- app sales
- Sales Engineer
- Sales案例分析
- 出色的Sales什么样
- 体会SALES的“三个代表”
- 如何实施Sales工程
- ERP与Sales
- 出色的Sales什么样?
- Marketing and Sales
- Cross-Company Sales
- SALES ORDER所有出口
- Pass4Sure Cisco Sales Expert
- Sales and Distribution (SD)
- java 重新抛出异常 相关处理结果示例代码
- 国外著名大学(计算机,通信及电子方面学院)
- 2014 UESTC Training for Graph Theory Problem K WHITE ALBUM
- java多线程面试题
- CodeForces 7D Palindrome Degree 字符串hash
- UVa1260 - Sales
- OCP-1Z0-051 补充题库 第32题 ALL、ANY、IN
- listView懒加载解决快速拖动卡屏问题
- (2014.06.23-2014.06.29)七天的学习小记
- 二叉树的创建与前序中序后序遍历的递归实现
- 黑马程序员---网络编程
- python初学
- OCP-1Z0-051 补充题库 第33题 sql*plus命令
- 项目设计之一-------------策略模式应用