From 0483d457f15f5c0a0228c9ad1036c738a3c09367 Mon Sep 17 00:00:00 2001 From: Denis Costa Date: Tue, 24 Sep 2024 12:48:26 -0300 Subject: [PATCH] Solve Laser Sculpture in python --- solutions/beecrowd/1107/1107.py | 18 + solutions/beecrowd/1107/generate_in.sh | 21 + .../beecrowd/1107/imgs/UOJ_1107_a_en.webp | Bin 0 -> 3056 bytes solutions/beecrowd/1107/imgs/UOJ_1107_b.png | Bin 0 -> 3814 bytes solutions/beecrowd/1107/in.txt | 2001 +++++++++++++++++ solutions/beecrowd/1107/out.txt | 1000 ++++++++ solutions/beecrowd/1107/problem.md | 50 + solutions/beecrowd/1107/tags.txt | 1 + 8 files changed, 3091 insertions(+) create mode 100644 solutions/beecrowd/1107/1107.py create mode 100755 solutions/beecrowd/1107/generate_in.sh create mode 100644 solutions/beecrowd/1107/imgs/UOJ_1107_a_en.webp create mode 100644 solutions/beecrowd/1107/imgs/UOJ_1107_b.png create mode 100644 solutions/beecrowd/1107/in.txt create mode 100644 solutions/beecrowd/1107/out.txt create mode 100644 solutions/beecrowd/1107/problem.md create mode 100644 solutions/beecrowd/1107/tags.txt diff --git a/solutions/beecrowd/1107/1107.py b/solutions/beecrowd/1107/1107.py new file mode 100644 index 00000000..6ea0b5c6 --- /dev/null +++ b/solutions/beecrowd/1107/1107.py @@ -0,0 +1,18 @@ +import sys + +for line in sys.stdin: + if line.strip() == '0 0': + break + + height, length = map(int, line.split()) + blocks_heights = list(map(int, input().split())) + + count_laser_moves = height - blocks_heights[0] + previous_height = blocks_heights[0] + + for current_height in blocks_heights[1:]: + if current_height < previous_height: + count_laser_moves += previous_height - current_height + previous_height = current_height + + print(count_laser_moves) diff --git a/solutions/beecrowd/1107/generate_in.sh b/solutions/beecrowd/1107/generate_in.sh new file mode 100755 index 00000000..3abe4bc0 --- /dev/null +++ b/solutions/beecrowd/1107/generate_in.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -euo pipefail + +TESTCASES=1000 +MAX_HEIGHT=1000 +MAX_LENGTH=1000 + +for _ in $(seq "${TESTCASES}"); do + height="$((RANDOM % MAX_HEIGHT + 1))" + length="$((RANDOM % MAX_LENGTH + 1))" + echo "${height} ${length}" + for i in $(seq "${length}"); do + if [[ ${i} -ne 1 ]]; then + echo -n " " + fi + echo -n "$((RANDOM % (height + 1)))" + done + echo +done +echo "0 0" diff --git a/solutions/beecrowd/1107/imgs/UOJ_1107_a_en.webp b/solutions/beecrowd/1107/imgs/UOJ_1107_a_en.webp new file mode 100644 index 0000000000000000000000000000000000000000..3a95ef3f8e1b82d9149f34ced50178f1c1b8d881 GIT binary patch literal 3056 zcmVCNk&HK3jhFDMM6+kP&iE63jhEwF+y4Z=fNnFBt^AMr-5JV-_hPVU_Kjc zBimMTzJH_zC;t6cKqW6Ebcbzh+osNY-^#62{rsMP70zt``H%nqLj!6EfCWqlKm%$c z4Jx35La9iJ5#Bd(U6=E`%=6@ZTFc6Mp4ao-_G8Bn`*GN|)%SkZb+zpqp>zTdI0hU& z0H$^Tu+*KY?f^1V^N6`D<}zt0A4DOOgiMlCC}xtX)Kn<|9=hDnL0?0jQc5#WU>#2x z21h~LHcY~wcDutMA|?PkLy>Ca)q0_=51fOnRj`5z;1v0$Xj@wwZF%k8NJK>xdm{)u zcGTSeg(ZZ{*D~b!%S7~F7G&FP+bj$kV#}kAk=axr=1ZEb?M>q_y@0a>nF$e2{Y7lj z_P;RnzVG)T9BfTVBKi*rZ6ryOXSZQaoJ-Eh(o{_TgfQvmzyJPo^B=`s?qhXvc)FPh znB}D&LVNqX!o{I0-ObEHv)wII%u;0d6O=3UP^>f|Y(MgmP5Ur}2r{9oDiXLjgmg=I zq#h=Req!@H9)tXj6U7)WV%_ILb zdT-;pi)Lt52p@d=#&$vXZR2S=IUNzXrw$o@^X3C|mN0%?ZdD6HF@V^@`DD)_6{cYJ*qXvDp|}*TAdEV(PjCnxK~;2{!gax8k~7 zJG5n_kH3ARxuAO?wtfH&_3owq|N82ixBhP0?tZDO&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quQ0&e~* z5nkj>CqDV>5k!Z5?nR?{a`kl2H5h}QCYPA~mdbrwRo*#qf%rAV#eI+C;j*1el`%rd zG){+W%zld>uiSIu0&%%9ofrD#@HE}H+|#U-jGVU{esJ>7iOa-xE?Gp3(^z57TO%Z_ z;bKh7$i{RoSLB4+#&j~zeoMo1;+l={D_zoA#x%J^$VzhqhuIt9{P&UJn`G@u6aiL6 zzrEZ?2a`({z^{aXoWNt~L^@nC`z_IJa!y<>R9sx?w=9n`-p&NCdE(f~bhr%)aJT6> zak-FjaXaC>LY$;Cxn3_Ja^o6d05^KPX5xm?nOwFcx&WYkCX3A#j11HegD+*&dmq+x zbGE>tNnxsgXs-EW6=&=U5rQw{wtCvdP?m)Dw>!!>YMdk0mK@6FqwI!TsM1R3>BE^H zw5u!VP<)8H6=d zOGyE`kEfrM1f-5@1IBs%4IjD!;I}?5rDC^Nef8jZtm(fFE_n@@ z`ElGIJbBS=E+$L&j=$ZSIdXd$n7dX`fLY%$&%tYEt91Ieyzb`sH8i-I6Ow zvm3s()3 z@EV;QojZh6&JPXV2234*z21f1fmnD_mN5iOCAe_aP!DTFwk}GiXm1@G=I+qm+LF|L znZ^*{-MDI4r;WiR{b9TFoqV}hCtvQLZcIsPr%YoA&?ThaMO-zk(#Zp6=??r>saG$9 z<>kf*?bU>6Nvee>Wf?<&oHsx^o!$;QYDj|XbF~RddIT=`kv|7&#M9YEd=3P?WJ!vJ zC*>PMKK!zq^qFPG5O5-xF-xaeW()zR zf#kGYPraBlB3lF$VGHXrTX=Y33u}cfJUm@kD{L{r)5YjATO-8ad*<*0=>}^UHb~;uHI{}*JE(znx*JQSds4|bOM{DICH;) yhuZ1yW+}S%6_|VvRev{2(Xp>U_C3%WecdcY_kIV-_X31TH~-!Ick|y%PzV4liqp0L literal 0 HcmV?d00001 diff --git a/solutions/beecrowd/1107/imgs/UOJ_1107_b.png b/solutions/beecrowd/1107/imgs/UOJ_1107_b.png new file mode 100644 index 0000000000000000000000000000000000000000..87cf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WTINAmSl#k1DJs1psfig!NJodU{v(|NznHhpLrpnpAntQi-WSh;?)HG(}Nnz2uk z_~pWz-GcCK4TEn&qrCbyknACW(;%S{sqZzf3iuS?ANrP~FRRNo`~n)$LtIQJ;|C^6 zhEm3`As?;@L!4VX{<*}PxF`F3qLYT#56$vv_Kzi?;c8O=2#dH~4 zfP`)D%zLkhKq$Ud<#ip#L6;-XJn|U;Z9UJHmtGp?(#rVv;yxyWvu#QjgKtMaIOgA|J52p}%PD{S;%s%qDlJm$#ZP8UqLA6BI@`)i7rvo2L=#Two}A%VwCj_P-aZi&C*N~qTLAE`cS zcu-+2Y~Wnt3~W3xOAP;rInud)KZrdtxol$|u)5x!AxhF~51R1Wo0^03&v68UUR3sv z`+B!N(MbqFqwzEidPV1BzpM?+@FuTr3hjh`NQXxQ + +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 specific width layer 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 ($1 \leq A \leq 10^4$)$ and +the length ($1 \leq C \leq 10^4$) of the block to be sculpted, in milimeters. +The second line contains $C$ integers $X_i$, each one indicating the final +height, in milimeters of the block between the positions $i$ and $i + 1$ through +the length ($0 \leq X_i \leq A$, for $0 \leq i \leq C - 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. diff --git a/solutions/beecrowd/1107/tags.txt b/solutions/beecrowd/1107/tags.txt new file mode 100644 index 00000000..e07a45e3 --- /dev/null +++ b/solutions/beecrowd/1107/tags.txt @@ -0,0 +1 @@ +ad-hoc