क्या यह एक वैध जुर्माना शूट-आउट उपसर्ग है?


14

में एसोसिएशन फुटबॉल (फुटबॉल के रूप में जाना जाता है), एक पेनल्टी शूट-आउट दूसरा टाई ब्रेकर उपाय है कि एक मैच जो बराबरी पर समाप्त नहीं हो सकता में इस्तेमाल किया जा सकता है, अतिरिक्त समय (यानी एसोसिएशन फुटबॉल अतिरिक्त समय) के बाद है।

पेनल्टी शूट-आउट में, मुख्य रेफरी एक सिक्के को निर्धारित करता है कि किस लक्ष्य पर शूट-आउट होता है, और फिर दूसरे सिक्के को निर्धारित करने के लिए कि कौन सी टीम पहले शुरू होती है। हालांकि, इस चुनौती के लिए प्रासंगिक एकमात्र बात यह है कि तब क्या होता है, नीचे वर्णित है।

प्रत्येक टीम में शुरू में 5 दंड उपलब्ध हैं, और जुर्माना स्कोर 0-0 है। यदि, किसी भी बिंदु पर, एक टीम के शेष दंड वर्तमान में जीतने वाली टीम को बदलने के लिए पर्याप्त नहीं हैं, तो शूट-आउट बंद हो जाता है।

यदि शेष दंड नहीं हैं, लेकिन दोनों टीमों के अंक समान हैं, तो दोनों टीमों को अतिरिक्त जुर्माना दिया जाता है। यह तब तक दोहराया जाता है जब तक कि अंक बराबर न हों।

शूट-आउट रुकने के बाद, सबसे बड़ा पेनल्टी स्कोर वाली टीम गेम जीतती है।

चुनौती

आपकी चुनौती यह है कि दो सूचियाँ दी जाएं Aऔर यह Bदर्शाया जाए कि कौन से दंड टीम ए और टीम बी ने क्रमशः स्कोर किया है, यह निर्धारित करने के लिए कि क्या वे एक वैध जुर्माना शूट-आउट का प्रतिनिधित्व करते हैं। एक शूट आउट वैध है अगर इनपुट द्वारा राज्य का प्रतिनिधित्व किया जा सकता है, भले ही विजेता टीम निर्धारित की जा सकती है। ध्यान दें कि आपको संभवतः दोनों परिदृश्यों के लिए परीक्षण करना होगा (टीम ए स्टार्टिंग, टीम बी स्टार्टिंग), यदि इनपुट में वर्णित राज्य कम से कम एक परिदृश्य के लिए उपलब्ध है, तो इनपुट मान्य है। यदि सूचियों की लंबाई अलग-अलग होती है, तो जो टीम सबसे पहले दिखाई देती है, वह पहले शुरू होती है (इसमें अन्य की तुलना में केवल एक अधिक तत्व हो सकता है, और छोटी सूची की टीम शुरू नहीं हो सकती है, तब से लंबी सूची की टीम दो दंडों को शूट करेगी। एक पंक्ति में, चूंकि छोटी सूची समय से पहले समाप्त हो जाएगी)।

विस्तृत उदाहरण

आप नीचे दिए गए नियम अनुभाग पर जा सकते हैं, ये केवल चुनौती को हल करने में मदद करने के लिए हैं।

मान लीजिए कि आपको यह शूट आउट इनपुट के रूप में मिलता है, -जिसका अर्थ है कि कोई गोल नहीं किया गया था और Xइसका मतलब है कि एक गोल किया गया था (यह अमान्य है):

Team A: - X X X X
Team B: - - - - X

Assuming team A starts first:

Team A: - (0 - 0) (max possible score 4 - 5)
Team B: - (0 - 0) (max possible score 4 - 4)
Team A: X (1 - 0) (max possible score 4 - 4)
Team B: - (1 - 0) (max possible score 4 - 3)
Team A: X (2 - 0) (max possible score 4 - 3)
Team B: - (2 - 0) (max possible score 4 - 2)
Team A: X (3 - 0) (max possible score 4 - 2)
Team A already has a higher score than B could ever have, but the input hasn't
ended yet, so it's invalid if team A is first.

Assuming team B starts first:

Team B: - (0 - 0) (max possible score 5 - 4)
Team A: - (0 - 0) (max possible score 4 - 4)
Team B: - (0 - 0) (max possible score 4 - 3)
Team A: X (1 - 0) (max possible score 4 - 3)
Team B: - (1 - 0) (max possible score 4 - 2)
Team A: X (2 - 0) (max possible score 4 - 2)
Team B: - (2 - 0) (max possible score 4 - 1)
Team A already has a higher score than B could ever have, but the input hasn't
ended yet, so it's invalid if team B stars first.

The input is invalid no matter which team starts first, so it's considered
invalid.

इसके विपरीत, यहाँ एक मान्य उदाहरण है:

Team A: X X X
Team B: - - -

Assuming team A starts first:

Team A: X (1 - 0) (max possible score 5 - 5)
Team B: - (1 - 0) (max possible score 5 - 4)
Team A: X (2 - 0) (max possible score 5 - 4)
Team B: - (2 - 0) (max possible score 5 - 3)
Team A: X (3 - 0) (max possible score 5 - 3)
Team B: - (3 - 0) (max possible score 5 - 2)
It can be determined that team A wins, however the input has ended, so it's
valid if team A starts first. Therefore, the input is valid.

एक और उदाहरण, इस बार अतिरिक्त दंड के साथ:

Team A: X - X - - - X -
Team B: - X X - - - X X

Assuming team A starts first:

Team A: X (1 - 0) (max possible score 5 - 5)
Team B: - (1 - 0) (max possible score 5 - 4)
Team A: - (1 - 0) (max possible score 4 - 4)
Team B: X (1 - 1) (max possible score 4 - 4)
Team A: X (2 - 1) (max possible score 4 - 4)
Team B: X (2 - 2) (max possible score 4 - 4)
Team A: - (2 - 2) (max possible score 3 - 4)
Team B: - (2 - 2) (max possible score 3 - 3)
Team A: - (2 - 2) (max possible score 2 - 3)
Team B: - (2 - 2) (max possible score 2 - 2)
First 5 penalties result in a tie, so we move on to extra penalties.
Team A: -, Team B: - (2 - 2)
Team A: X, Team B: X (3 - 3)
Team A: -, Team B: X (3 - 4)
It can be determined that team B wins, however the input has ended, so it's
valid if team A starts first. Therefore, the input is valid.

यहां एक मान्य इनपुट है जहां विजेता का निर्धारण करना जल्दबाजी होगी:

Team A: X X - -
Team B: - X - X

Assuming team A starts first:

Team A: X (1 - 0) (max possible score 5 - 5)
Team B: - (1 - 0) (max possible score 5 - 4)
Team A: X (2 - 0) (max possible score 5 - 4)
Team B: X (2 - 1) (max possible score 5 - 4)
Team A: - (2 - 1) (max possible score 4 - 4)
Team B: - (2 - 1) (max possible score 4 - 3)
Team A: - (2 - 1) (max possible score 3 - 3)
Team B: X (2 - 2) (max possible score 3 - 3)
The input has ended before the winner can be determined, so it's valid if team A
starts first. Therefore, the input is valid.

अंत में, यहां एक इनपुट है जहां सूचियों की लंबाई भिन्न होती है:

Team A: - - -
Team B: X X - X

Since team B shot more penalties, it starts first:

Team B: X (0 - 1) (max possible score 5 - 5)
Team A: - (0 - 1) (max possible score 4 - 5)
Team B: X (0 - 2) (max possible score 4 - 5)
Team A: - (0 - 2) (max possible score 3 - 5)
Team B: - (0 - 2) (max possible score 3 - 4)
Team A: - (0 - 2) (max possible score 2 - 4)
Team B: X (0 - 3) (max possible score 2 - 4)
It can be determined that team B wins, however the input has ended, so it's
valid.

नियम

  • जो टीम पहले शूट करती है, वह ए या बी हो सकती है, आप यह नहीं मान सकते कि कोई हमेशा पहले शूट करेगा।
  • सूचियों में या तो समान लंबाई होगी, या उनकी लंबाई एक से भिन्न होगी।
  • आप किसी भी दो अलग और सुसंगत मूल्यों का चयन कर सकते हैं ताकि स्कोर / अनसुनी दंड का प्रतिनिधित्व किया जा सके।
  • सूचियों को विशेषण आधार 2, स्ट्रिंग्स या आपकी भाषा के मूल सूची प्रारूप से परिवर्तित पूर्णांक के रूप में भी दर्शाया जा सकता है । यदि एक विशेषण आधार 2 प्रारूप चुना जाता है, तो इनपुट नियम द्विआधारी आधार 2 में परिवर्तित संख्याओं पर लागू होते हैं (इसलिए अंक 1और 2क्रमशः स्कोर किए जा सकते हैं और असंबद्ध या असंबद्ध और क्रमशः स्कोर किए जा सकते हैं)। नियमित बाइनरी की अनुमति नहीं है , क्योंकि कोई भी इरादा बाइनरी प्रतिनिधित्व में अग्रणी शून्य की उपस्थिति का निर्धारण नहीं कर सकता है।
  • यह , इसलिए सबसे छोटा समाधान जीतता है। हालाँकि, कृपया जवाब देने से हतोत्साहित न हों, भले ही ऐसा लगता हो कि आपकी भाषा "विशेषों को हरा नहीं सकती"।

परीक्षण के मामलों

इन परीक्षण मामलों में, एक 0वसीयत 1एक लक्ष्य का प्रतिनिधित्व करती है , और एक लक्ष्य का प्रतिनिधित्व करेगा।

प्रारूप:

[Team A], [Team B]

मान्य इनपुट:

[], []
[0], [0]
[0], [1]
[1], [1]
[0], []
[1, 1, 1, 1], [0, 0, 1, 1]
[0, 1, 1, 1, 1], [0, 1, 1, 0]
[0, 0, 0, 0, 1], [0, 0, 0, 1, 0]
[0, 0, 0, 0, 1], [0, 0, 0, 1]
[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]
[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1]
[0, 1, 1, 1, 1], [0, 1, 1, 0, 1]
[1, 1, 1], [0, 0, 0]
[1, 1, 1, 1], [0, 0, 1]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

अमान्य इनपुट:

[0, 1, 1, 1, 1], [0, 1, 1, 0, 0]
[0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1, 0]
[0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1]
[1, 1, 1, 0], [0, 0, 0]
[1, 1, 1, 1], [0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
[1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1]
[0, 0, 0, 0, 1], [0, 1, 1, 1, 0]

क्या मैं अमान्य के लिए 0 या झूठे, और वैध के लिए सही लौटा सकता हूं?
अज्ञानता

@EmbodimentofIgnorance "आप किसी भी दो अलग और सुसंगत मूल्यों का चयन कर सकते हैं ताकि स्कोर किए गए / बिना जुर्माने के दंडित किया जा सके।" सटीक मान मायने नहीं रखते हैं, लेकिन केवल दो मूल्य होने चाहिए।
आउटगोल्फर

मुझे लगता है [[0,0],[1,1]](या किसी भी परीक्षण के मामले में जहां दो आंतरिक सूचियों में से एक में 2 आइटम हैं) सत्य है, क्योंकि खेल अभी भी चल रहा है (जैसे कि परीक्षण मामलों के साथ [[0],[1]]या [[0],[]]अभी भी प्रगति पर है)?
केविन क्रूज़सेन

@KevinCruijssen हां, क्योंकि कोई भी यह निर्धारित नहीं कर सकता कि कौन जीतेगा, परिणाम 3-2 हो सकता है। ;-)
द एग्जॉफ़र आउट

जवाबों:


3

जावास्क्रिप्ट (ईएस 6),  117 112  109 बाइट्स

बिना इनपुट के और स्कोर के लिए(a)(b) का उपयोग करते हुए इनपुट लेता है । रिटर्न या ।1201

a=>b=>!(g=(a,b,P=Q=i=5)=>(p=a[5-i])|(q=b[5-i])&&(--i<0?P-Q:P-Q>i|Q+q-P-p>i&p<2)|g(a,b,P+p,Q+=q))(a,b)|!g(b,a)

इसे ऑनलाइन आज़माएं!

टिप्पणी की गई

a => b =>                   // given a[] and b[]
  !(g = (                   // g is a recursive function taking:
      a,                    //   the results a[] of the team that plays first
      b,                    //   the results b[] of the team that plays second
      P =                   //   the cumulated goals P of the 1st team (relative value)
      Q =                   //   the cumulated goals Q of the 2nd team (relative value)
      i = 5                 //   a counter i
    ) =>                    // and returning a truthy value if something goes wrong
      (p = a[5 - i]) |      // if either the first team
      (q = b[5 - i]) && (   // or the second team is playing this round:
        --i < 0 ?           //   decrement i; if we've played more than 5 penalties:
          P - Q             //     do we already have a goal difference?
        :                   //   else:
          P - Q > i |       //     was the 1st team already guaranteed to win?
          Q + q - P - p > i //     or is the 2nd team now guaranteed to win
          & p < 2           //     while the 1st team failed its last attempt?
      ) |                   //
      g(                    //   do a recursive call:
        a, b,               //     pass a[] and b[] unchanged
        P + p,              //     update P
        Q += q              //     update Q
      )                     //   end of recursive call
  )(a, b) |                 // try g(a, b)
  !g(b, a)                  // try g(b, a); return 1 if at least one of them is falsy

2

पायथन 2 , 176 169 171 169 बाइट्स

-2 बाइट्स @ केविन क्रूज़सेन को धन्यवाद

exec"h=lambda a,b,m:m-%s/2>abs(sum(a)-sum(b));f=lambda a,b:a[5#==b[5#and h(a[:5],b[:5],6)if %s>10else h(a,b,7)and h(a[#,b[#,6)".replace("#",":~-%s/2]")%(("len(a+b)",)*6)

इसे ऑनलाइन आज़माएं! (ऊपर सूचीबद्ध नहीं किए गए कुछ अतिरिक्त परीक्षण मामले शामिल हैं।)

एक फ़ंक्शन बनाता है fजो दो तर्क लेता है (स्कोर की दो सूचियां / बिना जुर्माने के दंड) और रिटर्न Trueअगर स्कोर संभवतः वैध और Falseअन्यथा हैं।

आंशिक विवरण:

सबसे पहले, execनिर्माण केवल एक len(a+b)बार से अधिक अभिव्यक्ति को दोहराने के लिए नहीं करके कुछ बाइट्स को बचाने का एक तरीका है । कोड का उपरोक्त टुकड़ा निम्नलिखित के बराबर है:

अद्यतन: नया और बेहतर उत्तर execचालबाजी के साथ या उसके बिना एक ही बाइट काउंट है , इसलिए सादगी के हितों में मैंने इसे हटा दिया है।

अद्यतन 2: नए बगिफ़ाइड संस्करण में प्रतिस्थापन के माध्यम से और भी अधिक स्ट्रिंग संपीड़न शामिल हैं और exec। हां, मैं %प्रारूपण और .replaceउसी स्ट्रिंग पर उपयोग करता हूं । उपरोक्त कोड इसके बराबर है:

h=lambda a,b,m:m-len(a+b)/2>abs(sum(a)-sum(b))
f=lambda a,b:a[5:(len(a+b)-1)/2]==b[5:~-len(a+b)/2]and h(a[:5],b[:5],6)if len(a+b)>10else h(a,b,7)and h(a[:(~-len(a+b)/2],b[:(len(a+b)-1)/2],6)

<=5not len(a+b)>10hm

हालांकि, स्कोर का एक वैध सेट होने के लिए, एक इनपुट को कड़ाई से जारी रखने की आवश्यकता नहीं है, लेकिन इसे अंतिम किक से पहले निरंतर होना चाहिए। यह शर्त यह कहने के बराबर है कि यह 1 होना चाहिए) पिछली बार दोनों पक्षों ने एक ही समय में और 2 की संख्या को अंतिम बार जारी रखा था) वर्तमान में निरंतर होने के दो आधे बिंदुओं के भीतर है - जो कि अंतिम तर्क में hआता है: h(a[:~-len(a+b)/2],b[:~-len(a+b)/2],6)परीक्षण की स्थिति 1) और h(a,b,7)( 7मार्जिन में एक अतिरिक्त दो स्वीकार्य आधे अंक का प्रतिनिधित्व करते हुए) परीक्षण की स्थिति 2)।

मामला जहां प्रत्येक टीम ने अधिकतम पांच बार किक मारी है, इस प्रकार सुलझा लिया गया है। (अन्य मामले के लिए स्पष्टीकरण जारी रखा जाएगा।)

निम्न-स्तरीय गोल्फिंग के संदर्भ में, मुझे संदेह है कि दाढ़ी बनाने के लिए बहुत अधिक है, लेकिन एल्गोरिदम संभवतः इसे थोड़ा और अधिक सरल रूप से किया जा सकता है।


1
आप 2 बाइट बचाने के (%s-1)/2लिए गोल्फ कर सकते हैं ~-%s/2
केविन क्रूज़सेन

@KevinCruijssen धन्यवाद!
एदान एफ। पियर्स

1

जेली , 62 54 49 बाइट्स

ṫ⁵Ṗm2¬Ạ
N§ỤḢƊ¦LÞṚZFĵ12R:2U_ṁḣ⁵ṫ-N<Ø.ẠaÇoL<3
ṚÇoÇ

इसे ऑनलाइन आज़माएं!

ṫ⁵Ṗm2¬Ạ # helper function to determine whether
        # even indices at or beyond 10 are zero
ṫ⁵      # tail - take every item from 10
  Ṗ     # remove last item
   m2   # take every second item
     ¬  # logical not, will return 1 for an empty list
      Ạ # all
# function to create cumulative score
# difference and check values
N§ỤḢƊ¦    # negate scores for team with lower score
          # (or one of them if both same score)
  LÞṚ     # sort by length, longest first
  ZF      # transpose lists and flatten
  Ä       # cumulative sum
  µ       # this cumulative score difference (CSD) 
          # now becomes left value
  12R:2U_ # subtract cumulative score difference from
          # 6,5,5,4,4,3,3,2,2,1
  ṁḣ⁵     # shorten to be no longer than 10 items
          # and no longer than CSD
  ṫ-N<Ø.Ạ # check last two values are greater than 0,-1
  aÇ      # check that helper function also TRUE
  oL<3    # handle very short scores
# main link that calls the above for scores in either order
ṚÇoÇ

ध्यान दें कि पाद लेख कोड tio में है बस कई परीक्षण मामलों को संभालने और आदानों के खिलाफ आउटपुट प्रिंट करने के लिए है।

8 बाइट बंद करने के लिए @EriktheOutgolfer का शुक्रिया


अच्छा प्रयास! यह बहुत तुच्छ चुनौती नहीं है। कुछ गोल्फ।
आउटगोल्फर

0

पर्ल 6 , 123 बाइट्स

{all map {@^b>@^a||[R,](map {abs(($+=$_)-++$ %2/2)>(5-++$ /2 max++$ %2)},flat roundrobin @a,-<<@b).skip.any},@^a,@^b,@b,@a}

इसे ऑनलाइन आज़माएं!

वैध शूट-आउट के लिए रिटर्न गलत है, अमान्य लोगों के लिए सत्य है।

व्याख्या

# Check whether block returns true (invalid shoot-out) for arguments (a, b) and (b, a)
{all map {...},@^a,@^b,@b,@a}
# Return true (invalid) if array b is longer than a
@^b>@^a||
# Return true (invalid) if any except the last value is true (shoot-out stopped)
[R,](...).skip.any
# Map values from a and negated b, interleaved
map {...},flat roundrobin @a,-<<@b
# Shoot out stopped?
abs(($+=$_)-++$ %2/2)>(5-++$ /2 max++$ %2)
    #     # Accumulator
           #        # Subtract 0.5 for first team
                      #                  # Sequence 4.5 4 3.5 3 2.5 2 1.5 1 1 0 1 0 1 0
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.