AutoAdjust
TCCC05 Round 3 · 2005-01-10 · by lars2520
Problem Statement
In this problem, we will consider a greyscale image, where each pixel is represented by an ASCII character between 32 and 95, inclusive. Grey is indicated by 63.5 (hence no pixel is exactly grey). Your task is to adjust the brightness and contrast of an image so that the darkest pixels in the image are black (32), and the brightest pixels in the image are white (95). To do this, you may adjust the brightness by any integer value between -100 and 100, inclusive, and you may adjust the contrast by any integer value between 100 and 20,000, inclusive. When a pixel's value is not an integer after the adjustment, round its value to the nearest integer (0.5 rounds up). To prevent loss of detail, you should adjust the brightness and contrast in such a way that the contrast is adjusted as little as possible. If there are multiple ways to do this with the minimum contrast adjustment, you should pick the one with the smallest absolute brightness adjustment. You should return a
Notes
- There will always be a way to perform the adjustment.
Constraints
- image will contain between 1 and 50 elements, inclusive.
- Each element of image will contain between 1 and 50 characters, inclusive.
- Each element of image will contain the same number of characters.
- There will be at least two different color values in image.
- Each character in image will have ASCII value between 32 and 95, inclusive.
{"------------",
"--TTT--CCC--",
"---T---C----",
"---T---CCC--",
"------------"}
Returns: { " ", " ___ CCC ", " _ C ", " _ CCC ", " " }
'-', 'C', and 'T' have ASCII values of 45, 67, and 84, respectively. By decreasing the brightness by 1, and then adjusting the contrast by 159, these three values are transformed as follows: (45 - 1 - 63.5) * 159 / 100 + 63.5 = 32.495 (67 - 1 - 63.5) * 159 / 100 + 63.5 = 67.475 (84 - 1 - 63.5) * 159 / 100 + 63.5 = 94.505 Rounding these values, we get 32, 67 and 95.
{" ",
" ___ CCC ",
" _ C ",
" _ CCC ",
" "}
Returns: { " ", " ___ CCC ", " _ C ", " _ CCC ", " " }
The minimum and maximum values are already 32 and 95, so nothing needs to be done (brightness = 0, contrast = 100).
{"AB"}
Returns: { " _" }
{"_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^",
"_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^",
"_^_^_^_^_^_^_^_^_^_^_^_^_^_^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 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " }
{"LKJEBGLKJBGRDE"}
Returns: { "JFB- 5JFB 5_)-" }
{"29/903A#,8%+A6:$(20='0?23>?0:'5;70>52>0A","&8>;2?5?2A&3+01@'*,6.)=46+<#)*;8(-<35&(&","0&8+(0/903$4;@$+'3-=(#1?%*7A4%%/?;*/15$,","4',#5-23.398=@)@8856*(:1,38&<*%$4%A&2+6;",".,1?3%6+:<##7930#9@1A2=+5A*12(*,/-,=5-0:","<;0.6;(+#+?4*=A//8/8<.45:?1'86?(-*93/382","@*?5%,<)0&0-:=$++9,@62:-*0=?;","6<8;7%:?08+?%.?,'.@A)/3&%>(.&-;+A1&","#$&@9@#@%8(0-%%>/<.A83>2+)2@3%9>2$,5A)+8","*&8*@.1/0,)75%#,?53A@3?>-89.>5@-+(A?)A<<","(=<=@42<$AA1#;:&&2:#(&,..8>?..9.;#)+*9A=",";%=@-6$#*70(#+)+'4&73>)+'A<)#$.'&>1*?,$,",":$,''*,621%?#A'/16*'%>;9*7*=(>1&55#?%,$(","'#2#A2'<609?*-@02;#*&7,.,80:<@=99:@3.//A","#0&3A-0..**962'>,64,6:*74#67+8/0A:<859(9","+66$5>$347-6>7*.A++12A-%'%@+577?(-6#@711","=8-AA;.(-9;9;@'<;0-(;;$,25#=??-''%",">'@(,%0%#@A291#701*;8%","?;-5%)$.5'*#;,<3A+-%(,>58.'62=9*0@<*@%,*","$3@%>>>0>)(;<2:7/?)6'?0+0+984%(((&A,2)$'","$*-.29,++-:9$7(9)477$,=0)A,(@/*=*4.+)3?9","41:$->A94&A64,.0+.>6,$;:-,(#(8-5;'8=(3;-$","./&43:5')/%3,.(-=066(.*<0)=<3/-277/144*.","6<:%@/;@'>'/10-)0:,7%+,1-86:;;,.#A-(;7<$","*?9.9%*$'**<+->07%52%:@&1#&29?)7875/(96@","#%'95233>,A#)099@+1*6,::#..;,@.7)3<><:9@","&6$62,<30-$3A9-A%,#.+7;495@:;7>:$#?@<#;1",".<@*)'<)76@$7+18+A3%>9?.+<%@=5#7@@-6-158","87>/51=%36394/#$1%.(2)'8.6$&A'162,?+:/(*","<>=5-?63.A<@9/)6:=73#264=86:$)5.?/%>>'5-?.1;+%:&-","%%#;78<&8&5@+00.>&5#<6,:%A?+0*>8=@?;:''#","5$$$?4>?67#(4+9)4,.-,#);)#160421:+,2&2:>",";)$@7$(A39,<:16*82=>;?4+236&*6/=?","5,*$$6:'+/4?-9$@@),93,@=2#7*%:;$+.7>9/A$","A#.A..%+A(@4,:0<.,2-4?:(70*&58'+>0%.;<57",",&%'8/9$61>>3#?65?(8<*54#'(8&=8:84>.#2.#","-9>&*'*38-.*-+<.+(102.?=3904(:<(9$:>9<(:","A*:;%';1(*+$@%5'A:;&58.@@8+)3092;4A>)$,5","3/:*)#':;.&,'-4',1@*$+*2A*&3$*'7A1&1%8,(","('#,31($>6@@A84.&:;<0>-,A%45$'0<1?1*&;'(","/0?&2'-/43#A'+;>@<;)=#>//%$801(=67;862:?","+02$.A7@/0.$+%'7#=;-5&#&@5-:*);>,)9;&/::","?5:,..%@'>(,5=.7#>2#(((&1?5<%$9))<8)0)'&","<&;=:*$(*(#3*;,6()**=$A-8$><1;5@;.3%%>(4"}
Returns: { ">M8M:A_ 2K#/_GP )>:V':Z>AXZ:P'ERI:XE>X:_", "%KXR>ZEZ>_%A/:<\\'-2G6+VCG/T +-RK)4TAE%)%", ":%K/):8M:A CR\\ /'A4V) A6AMKV\\+\\KKEG-)P<2AK%T-# C#_%>/GR", "62V/E_-<>)-2842VE4:P", "TR:6GR)/ /ZC-V_88K8KT6CEPZ<'KGZ)4-MA8AK>", "\\-ZE#T_K)AA2%>)X2T+:%:4PV //M2\\G>P4-:VZR", "GTKRI#PZ:K/Z#6Z2'6\\_+8A%#X)6T866X%4R/_<%", " %\\M\\ \\#K):4##X8T6_KAX>/+>\\A#MX> 2E_+/K", "-%K-\\6<8:2+IE# 2ZEA_\\AZX4KM6XE\\4/)_Z+_TT", ")VTV\\C>T __< RP%%>P )%266KXZ66M6R +/-M_V", "R#V\\4G -I:) /+/'C%IAX+/'_T+ 6'%X<-Z2 2", "P 2''-2G><#Z _'8 _>'TG:MZ-4\\:>R -%I262K:PT\\VMMP\\A688_", " :%A_4:66--MG>'X2GC2GP-IC GI/K8:_PTKEM)M", "/GG EX ACI4GXI-6_//<>_4#'#\\/EIIZ)4G \\I<<", "VK4__RTZ<%PX6)4MRMR\\'TR:4)RR 2>E VZZ4''#", "XTZCK>K4GM% )%):MR: _#E VC4>KK)TM AIC M#", "K#R /P P+A+I:TI4C'X'\\)2#:# \\_>M< I:<-RK#", "ZR4E#+ 6E'- R2TA_/4#)2XEK6'G>VM-:\\T-\\#2-", " A\\#XXX:X+)RT>PI8Z+G'Z:/:/MKC#)))%_2>+ '", " -46>M2//4PM I)M+CII 2V:+_2)\\8-V-C6/+AZM", "C
)'#)G I <", "2#- :+A'4-6I+:2#8-'MR-RP>X )K4ER'KV)AR4 ", "68%CAPE'+8#A26)4V:GG)6-T:+VTA84>II8#P\\%< %>MZ+IKIE8)MG\\", " #'ME>AAX2_ +:MM\\/<-G2PP 66R2\\6I+ATXTPM\\", "%G G>2TA:4 A_M4_#2 6/IRCME\\PRIXP Z\\T R<", "6T\\-+'T+IG\\ I/+'K6G %_'2Z/P8)-", "TXVE4ZGA6_T\\M8+GPVIT8-P-:+#> 2/-_V#XA >GCVKGP +E6Z8#XX'E4Z6 %>PX", "R+ \\I )_AM2TPVXRZC/>T8+__8XAG%-G8VZ", "E2- GP'/8CZ4M \\\\+2MA2\\V> I-#PR /6IXM8_ ", "_ 6_66#/_)\\C2P:T62>4CZP)I:-%EK'/X:#6RTEI", "2%#'K8M G6 ", "4MX%-'-AK46-4/T6/)<:>6ZVAM:C)PT)M PXMT)P", "_-PR#'R<)-/ \\#E'_PR%EK6\\\\K/+A:M>RC_X+ 2E", "A8P-+ 'PR6%2'4C'2<\\- /->_-%A -'I_<%<#K2)", ")' 2A<) XG\\\\_KC6%PRT:X42_#CE ':T'48CA _'/RX\\TR+V X88# K:<)VGIRKG>PZ", "/:> 6_I\\8:6 /#'I VR4E% %\\E4P-+RX2+MR%8PP", "ZEP266#\\'X)2EV6I X> )))%
Submissions are judged against all 62 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AutoAdjust with a public method vector<string> adjust(vector<string> image) · 62 test cases · 2 s / 256 MB per case