การจัดการสินค้าคงคลัง Minecraft


11

การจัดการสินค้าคงคลัง Minecraft เป็นเรื่องยาก คุณมี 17 เพชร แต่คุณต้องมี 7 เพื่อสร้างตารางเสริมเสน่ห์, เสียมและดาบ คุณหยิบมันขึ้นมาแล้วคลิกขวา 7 ครั้ง? หรือคุณคลิกขวาหนึ่งครั้งและคลิกขวาสองครั้งแล้วเลี้ยวซ้าย 7 ครั้ง? มันช่างสับสนจริงๆ!

สำหรับบรรดาของคุณที่กำลังสับสนไม่ต้องกังวลฉันจะอธิบายทั้งหมดในไม่กี่วินาที

ท้าทาย

กำหนดขนาดของสแต็คของรายการและจำนวนที่ต้องการกำหนดจำนวนคลิกน้อยที่สุดเพื่อให้ได้จำนวนนั้น คุณต้องจัดการได้ถึง 64 สำหรับอินพุตทั้งสองและคุณอาจคิดว่าคุณมีช่องโฆษณาที่ไม่มีที่สิ้นสุด คุณไม่สามารถใช้เคล็ดลับลากเพื่อกระจาย

คำนิยาม

สินค้าคงคลังเป็นคอลเลกชันของช่องที่คุณสามารถจัดเก็บรายการ

สล็อตเป็นพื้นที่จัดเก็บในคลังของคุณที่คุณสามารถวางได้ถึงหนึ่งในประเภทของรายการ

สแต็คเป็นจำนวนรายการที่วางอยู่ในกลุ่มเดียวกัน สำหรับจุดประสงค์ของการท้าทายสแต็กนั้นเป็นเพียงไอเท็มจำนวนมากในที่เดียวกัน (ดังนั้นอย่าสนใจขนาดสแต็ก)

เคอร์เซอร์เป็น thingy แหลมของคุณ เคอร์เซอร์นั่น มันสามารถมีรายการ "กับมัน"; กล่าวอีกนัยหนึ่งถ้าคุณคลิกที่ช่องแล้วหยิบรายการรายการที่คุณเลือกคือ "ที่เคอร์เซอร์" จนกว่าคุณจะวางลง

ข้อมูลจำเพาะ

มีสี่สถานการณ์ที่เป็นไปได้ ไม่ว่าคุณจะมีรายการบนเคอร์เซอร์หรือไม่และคุณคลิกซ้ายหรือคลิกขวา

หากคุณไม่มีรายการที่เคอร์เซอร์ของคุณและคุณคลิกซ้ายที่ช่องคุณจะได้รับสแต็กทั้งหมด

หากคุณไม่มีรายการที่เคอร์เซอร์ของคุณและคุณคลิกขวาที่ช่องคุณจะได้ครึ่งหนึ่งของกองซ้อนปัดเศษขึ้น

หากคุณมีรายการที่เคอร์เซอร์ของคุณและคุณคลิกซ้ายที่ช่องคุณวางรายการทั้งหมดลงในช่องนั้น (สำหรับผู้เล่น Minecraft ทุกคนคุณจะไม่มี> 64 รายการสำหรับความท้าทายนี้และพวกเขาทั้งหมด 64- ซ้อนกันได้และคุณมีเพียงประเภทเดียวดังนั้นการสลับไอเท็มจะไม่สามารถใช้ได้ที่นี่)

หากคุณมีรายการที่เคอร์เซอร์ของคุณและคุณคลิกขวาที่ช่องคุณวางรายการหนึ่งลงในช่องที่

ดังนั้นคุณเริ่มต้นด้วยรายการทั้งหมดที่ได้รับ (อินพุตแรกหรือวินาทีคุณสามารถเลือกคำสั่งซื้อ) ในช่องและคุณต้องการจบด้วยจำนวนที่ต้องการ (อินพุตอื่น) ในเคอร์เซอร์ของคุณ

ลองทำตัวอย่าง สมมติว่าคุณเริ่มต้นด้วย 17 รายการและคุณต้องการ 7. ก่อนอื่นคุณคลิกขวาบนสแต็กซึ่งหมายความว่าคุณได้รับ 9 และมี 8 ในช่องนั้น จากนั้นถ้าคุณคลิกขวาบนสแต็กอีกครั้งคุณวางหนึ่งไอเท็มกลับเข้าไปในช่องทำให้คุณมี 8 และช่องที่มี 9 ในที่สุดคุณคลิกขวาอีกครั้งและคุณมี 7 และช่องมี 10 ดังนั้น คุณจะกลับมา3(จำนวนคลิก)

หากคุณจัดการเพื่อออกคลิกกอล์ฟฉันโปรดบอกฉันและฉันจะแก้ไขตัวอย่าง: P

กรณีทดสอบ

สิ่งเหล่านี้สร้างขึ้นเองดังนั้นโปรดบอกฉันว่ามีข้อผิดพลาดใด ๆ หรือไม่ ฉันจัดการสินค้าคงคลังด้วยการคลิกที่กระวนกระวายใจคลิกขวาดังนั้นฉันจึงไม่มีประสบการณ์ในการจัดการสินค้าคงคลังที่ดีที่สุด: P

Given, Desired -> Output
17, 7 -> 3
64, 8 -> 5
63, 8 -> 5
10, 10 -> 1
10, 0 -> 0 # note this case
25, 17 -> 7

คำอธิบาย

ความท้าทายนี้อาจเป็นเรื่องยากสำหรับผู้เล่นที่ไม่ใช่ Minecraft ผมไม่มีความคิด นี่คือคำอธิบายบางอย่าง

64, 8 -> 5 เนื่องจากคุณรับ 32 โดยใช้คลิกขวาวางลงหยิบ 16 วางลงแล้วหยิบ 8

63, 8 -> 5 ด้วยเหตุผลเดียวกัน

25, 17 -> 7 เนื่องจากคุณรับ 13 วางลงหยิบ 6 จากซ้าย 12 วาง 2 กลับเข้าไปในสแต็กที่เหลือจากนั้นวาง 4 ในเคอร์เซอร์ลงใน 13 แล้วเลือกที่ขึ้น

กฎระเบียบ

  • ช่องโหว่มาตรฐานใช้
  • คุณอาจคิดว่า 0 <= desired <= given <= 64
  • คุณสามารถป้อนข้อมูลตามลำดับและทำ I / O ในรูปแบบที่เหมาะสม



2
ดังนั้นจึงเป็นเหมือนรัฐเครื่องซึ่งเริ่มต้นด้วยสถานะของ0,[n]อาจเปลี่ยน (1) จาก0,[a,b,...]การa,[b,...], b,[a,...], ceil(a/2),[floor(a/2),b,...]หรือceil(b/2),[a,floor(b/2),...]; หรือ (2) จากx,[a,b,...]( x>0) เพื่อx-1,[a+1,b,...], x-1,[a,b+1,...], x-1,[a,b,...,1], 0,[a+x,b,...], ,0,[a,b+x,...] 0,[a,b,...,x]ความท้าทายคือแล้วเพื่อหาสิ่งที่เปลี่ยนไปได้น้อยจาก0,[g]ที่กรัมให้กับt,Lที่tเป็นเป้าหมายที่ต้องการและLเป็นรายการใด ๆ
Jonathan Allan

คำตอบ:


2

C ++ , 498 482 457 ไบต์

หากฟังก์ชั่นนี้ถูกเรียกเพียงครั้งเดียวมันสามารถเป็น 455 ไบต์

ผมพบว่าเกือบทุกคอมไพเลอร์ GCC ออนไลน์ (รวม TIO) fห้ามฉันจะละเว้นชนิดของฟังก์ชั่น อย่างไรก็ตาม GCC ในคอมพิวเตอร์ของฉันอนุญาตและฉันไม่รู้ว่าทำไม

อันนี้สามารถจัดการอินพุตที่มีขนาดใหญ่ได้หากสล็อตสามารถมีจำนวนไอเท็มนั้น (แม้ว่าจะต้องมีอาร์เรย์ที่ใหญ่กว่าและอาจจะหมดเวลา)

#import<bits/stdc++.h>
#define t N.first
#define X n.erase(n.find
#define p(c){if(c==r)return l;if(L.emplace(w={n,c},l).second)Q[U++]=w;}
#define T(S,C)n.insert(S);p(C)X(S));
using m=std::multiset<int>;using s=std::pair<m,int>;s Q[99999];int x,l,B,U;int f(int a,int r){if(!r)return 0;std::map<s,int>L;s f({a},B=0),w,N;L[Q[U=1]=f];for(;;){l=L[N=Q[B++]]+1;x=N.second;t.insert(0);for(int i:t){m n=t;X(i));if(x){T(i+x,0)T(i+1,x-1)}if(!x&&i){p(i)T(i/2,i-i/2)}}}}

Ungolfed:

#include <map>
#include <set>
#include <queue>
#include <iostream>

using namespace std;

struct state {
    multiset<int> t; int q;
    bool operator<(const state& i) const { return make_pair(t, q) < make_pair(i.t, i.q); }
};

int f(int a, int target) {
    if (target == 0) return 0;

    map<state, int> len;
    queue<state> qu;
    state first = {{a}, 0};
    qu.push(first);
    len[first] = 0;

    #define push(c) { state a = {n, c}; auto t = len.insert({a, l + 1}); if (t.second) { \
        if (a.q == target) return l + 1; qu.push(a); \
    } } // push new state into queue and check for termination
    #define next(stk, cur) { n.insert(stk); push(cur); n.erase(n.find(stk)); }
    // insert new stack, push new state, erase the stack (for another use)

    while (qu.size()) { // BFS cycle
        state now = qu.front();
        qu.pop();

        int q = now.q;
        int l = len[now];

        multiset<int> n(now.t);
        for (int i : now.t) { // click on non-empty stack
            n.erase(n.find(i));
            if (!q) { // nothing on cursor
                push(i); // click left
                next(i / 2, (i + 1) / 2); // click right
            }
            else { // item on cursor
                next(i + q, 0); // click left
                next(i + 1, q - 1); // click right
            }
            n.insert(i);
        }
        if (q) { // click on empty stack
            next(q, 0); // click left
            next(1, q - 1); // click right
        }
    }
}

1

เยลลี่ , 74 ไบต์

Ẏċ⁴¬
HĊ,$Ḟµ€1¦€F€;⁸Ḣ,$€
‘1¦€ṭ€⁹’¤
+1¦€⁹ṭ€0;ç
⁹Ȧ‘Ḥ¤ŀ
Ṫ;0ṙJ$çḢ
Wṭ0WÇ€Ẏ$ÑпL’

โปรแกรมเต็มรูปแบบที่มีอินพุตแรก (อาร์กิวเมนต์ที่ 3) สแต็กปัจจุบันและอินพุตที่สอง (อาร์กิวเมนต์ที่ 4) เคอร์เซอร์ที่ต้องการ

ลองออนไลน์! เนื่องจากการใช้งานจะทำให้เวลา TIO หมดไป 60 วินาทีสำหรับ25, 17กรณีทดสอบ สิ่งนี้อาจแก้ไขได้โดยการลบความซ้ำซ้อนที่เหลืออยู่สำหรับ golfiness โดยใช้ 84 byter (ซึ่งกรองสแต็คขนาดศูนย์และเรียงลำดับส่วนที่เหลือด้วยḟ€Ṣ¥0¦€0ในตอนท้ายของลิงค์ 6 และรักษาสถานะเฉพาะในแต่ละขั้นตอนด้วยการใช้Q$หลัก link)

อย่างไร?

โปรแกรมใช้เครื่องสถานะที่กำหนด
มันจะสร้างสภาพเดิม[0, [argument 1]]
จากนั้นขั้นตอนที่ผ่านไปทุกรัฐที่เป็นไปได้ต่อไปซ้ำ ๆจนกว่าจะมีใครพบการจับคู่
[argument 2, [...]]

หมายเหตุ: รายการโปรแกรมอยู่ที่ "ลิงค์หลัก" ซึ่งเป็นส่วนที่หนึ่ง ( Wṭ0WÇ€Ẏ$ÑпL’)

Ẏċ⁴¬ - Link 1, test a list of states for not having the desired cursor
Ẏ    - tighten by one
  ⁴  - program's fourth argument (second input) - desired cursor
 ċ   - count occurrences (the stack list will never match, so just inspecting the cursors)
   ¬ - logical negation

HĊ,$Ḟµ€1¦€F€;⁸Ḣ,$€ - Link 2, next states given a 0 cursor: list, rotatedStacks; number currentCursor (unused)
     µ€1¦€         - for each rotation of rotatedStacks apply to the first element:
H                  -   halve
   $               -   last two links as a monad
 Ċ                 -     ceiling
  ,                -     pair
    Ḟ              -   floor (vectorises) -- i.e. n -> [floor(ceil(n/2)),floor(n/2)]
                                                     = [ceil(n/2),floor(n/2)]
          F€       - flatten each -- i.e. each [[c1,f1],s2, s3,...] -> [c1,f1,s2,s3,...]
             ⁸     - chain's left argument, rotatedStacks
            ;      - concatenate -- i.e. [[c1,f1,s2,s3,...],[c2,f2,s3,...,s1],...,[s1,s2,s3,...],[s2,s3,...,s1],...]
                $€ - last two links as a monad for each:
              Ḣ    -   head
               ,   -   pair -- i.e. [c1,f1,s2,s3,...] -> [c1,[f1,s2,s3,...]]

‘1¦€ṭ€⁹’¤ - Link 3, next states given a non-0 cursor and a right-click: list, rotatedStacks; number currentCursor
 1¦€      - for each rotation of rotatedStacks apply to the first element:
‘         -   increment -- i.e. place an item into the first stack of each rotation
        ¤ - nilad followed by link(s) as a nilad:
      ⁹   -   chain's right argument -- currentCursor
       ’  -   decrement
    ṭ€    - tack each -- i.e. [s1-1,s2,s2,...] -> [currentCursor-1,[s1-1,s2,s2,...]]

+1¦€⁹ṭ€0;ç - Link 4, next states given a non-0 cursor: list, rotatedStacks; number currentCursor
 1¦€       - for each rotation of rotatedStacks apply to the first element:
    ⁹      -   chain's right argument -- currentCursor
+          -   add
     ṭ€0   - tack each to zero -- i.e. [s1+currentCursor,s2,s3,...] -> [0,[s1+currentCursor,s2,s3,...]]
         ç - call the last link (3) as a dyad -- get the right-click states
        ;  - concatenate

⁹Ȧ‘Ḥ¤ŀ - Link 5, next states: list, rotatedStacks; number currentCursor
     ŀ - call link at the given index as a dyad...
    ¤  -   nilad followed by link(s) as a nilad:
⁹      -     chain's right argument -- currentCursor
 Ȧ     -     any & all -- for our purposes zero if zero, one if not
  ‘    -     increment
   Ḥ   -     double
       - -- i.e. call link 2 if currentCursor is zero else call link 4

Ṫ;0ṙJ$çḢ - Link 6, next states: currentState  e.g. [cc, [s1, s2, s3, ...]]
Ṫ        - tail -- get the stacks, [s1, s2, s3, ...]
 ;0      - concatenate a zero - add an empty stack to the options for use
     $   - last two links as a monad for each:
    J    -   range(length)
   ṙ     -   rotate left by -- i.e. [[s2,s3,0,...,s1],[s3,0,...,s1,s2],[0,...,s1,s2,s3],[...,s1,s2,s3,0],...[s1,s2,s3,0,...]]
       Ḣ - head -- get the currentCursor, cc
      ç  - call the last link (5) as a dyad

Wṭ0WÇ€Ẏ$ÑпL’ - Main link: initialStack, requiredCursor
W             - wrap -- [initialStack]
 ṭ0           - tack to zero -- [0, [initialStack]]
   W          - wrap -- [[0, [initialStack]]]
         п   - loop while, collecting the results:
        Ñ     - ...condition: call next link (1) as a monad -- cursor not found
       $      - ...do: last two links as a monad:
    ǀ        -   call the last link (6) as a monad for each
      Ẏ       -   flatten the resulting list by one level
           L  - length
            ’ - decremented (the collect while loop keeps the input too)
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.