UVa11683 - Laser Sculpture(很有技巧)
来源:互联网 发布:大数据的应用案例 编辑:程序博客网 时间:2024/05/16 14:27
Since its invention, in 1958, the laser has been used in a huge variety of applications, like electronic equipment, cirurgical instruments, weapons, and much more.
The image above shows a diagram of an equipment to sculpt, with a laser, a block of some solid material. In the figure we can see a laser emitter that moves horizontally to the right and left with a constant speed. When the emitter is turned on when moving, a layer a specific width is removed from the block, being vaporized by the laser.
The image below illustrates the process of sculpting with a laser, showing an example of (a) a block, with a height of 5 mm and a length of 8 mm, at the start of the process, (b) the format that we want the sculpted block to be, and (c) the sequence of layer removals during the process, considering that in each step, a layer with 1 mm of width is removed. In the first step, the piece numbered 1 is removed; in the second, the one numbered with 2; and so it goes on. During the process of sculpting, the laser was turned on 7 times, in total, once for each removed piece of the block.
Write a program that, given the height and the length of the block, and its final format, find out the total number of times the laser must be turned on.
Input
The input contains several test cases. Each test case is composed by two lines. The first line of a test case contains two integers A and C, separated by a blank space, indicating, respectively, the height ( 1A104) and the length ( 1C104) of the block to be sculpted, in milimeters. The second line contains Cintegers Xi, each one indicating the final height, in milimeters of the block between the positions i and i+ 1 through the length ( 0XiA, for 0iC - 1). Consider that on each step, a layer of width 1 mm is removed on the parts of the block where the laser is turned on.
The end of the input is indicated by a line that contains only two zeros, separated by a blank space.
Output
For each test case, your program must print a single line, containing an integer, indicating the number of times that the laser must be turned on to sculpt the block in the indicated format.
Sample Input
5 81 2 3 2 0 3 4 53 31 0 24 34 4 10
Sample Output
733
思路:将当前的输入数据与上一次的作比较,如果小于前一个,就加上它们之间的差
#include <cstdio>using namespace std;int a, c;bool input(){scanf("%d%d", &a, &c);if (a == 0 && c == 0) return false;return true;}void solve(){int prev = a;int ans = 0;for (int i = 0; i < c; i++) {int num;scanf("%d", &num);if (num < prev) {ans += prev - num;}prev = num;}printf("%d\n", ans);}int main(int argc, char **argv){#ifndef ONLINE_JUDGEfreopen("e:\\uva_in.txt", "r", stdin);#endifwhile (input()) {solve();}return 0;}
- UVa11683 - Laser Sculpture(很有技巧)
- laser
- bronze sculpture
- Glass Sculpture
- 12171 - Sculpture
- UVa12171 Sculpture
- Laser designer
- UVa 12171 Sculpture
- 离散化--uva12171 Sculpture
- UVa12171 Sculpture 离散化+搜索
- pku1184很有技巧的广搜
- Laser Applications Lab
- laser treatment for rosacea
- Understanding The Laser Engraver
- Laser Spectroscopy Group
- Codeforces 15B Laser
- CSU 1533 Laser Cutting
- Laser-induced CVD
- 5.5 函数值
- const char*, char const*, char*const的区别
- 用uitextfield写xxx xxx xxx格式的电话号码输入框
- 2014/10/23——记一次新生账号注册的问题吧
- 黑马程序猿_C语言之循环结构
- UVa11683 - Laser Sculpture(很有技巧)
- 第二章:理解DispatcherServlet ——深入浅出学Spring Web MVC
- java基础--数组概念
- linq中jion查询
- mybatis源代码分析之datasource包
- 我的异常01
- jCarousel jQuery下的滚动切换传送插件
- mapreduce配置调优
- 2014鞍山现场赛C题HDU5072(素筛+容斥原理)