Giải thích bài giải thuật bằng tiếng Anh

Chào mọi người, chả là mình đang học giải thuật trên coursera có điều Anh Văn mình gà quá, gặp cái đề này, dù đã cố gắng google dịch nhưng vẫn không hiểu hết ý nghĩa của nó, post lên đây ae giải thích hộ mình cái đề nó muốn mình làm gì với, cám ơn mọi người.
Bài 1:

  • Problem Introduction:
    In this problem you will simulate a program that processes a list of jobs in parallel. Operating systems such as Linux, MacOS or Windows all have special programs in them called schedulers which do exactly this with the programs on your computer.
  • Problem Description:
    Task. You have a program which is parallelized and uses 𝑛 independent threads to process the given list
    of 𝑚 jobs. Threads take jobs in the order they are given in the input. If there is a free thread,
    it immediately takes the next job from the list. If a thread has started processing a job, it doesn’t
    interrupt or stop until it finishes processing the job. If several threads try to take jobs from the list
    simultaneously, the thread with smaller index takes the job. For each job you know exactly how long
    will it take any thread to process this job, and this time is the same for all the threads. You need to
    determine for each job which thread will process it and when will it start processing.
    Input Format. The first line of the input contains integers 𝑛 and 𝑚.
    The second line contains 𝑚 integers 𝑡𝑖 — the times in seconds it takes any thread to process 𝑖-th job.
    The times are given in the same order as they are in the list from which threads take jobs.
    Threads are indexed starting from 0.
    Constraints. 1 ≤ 𝑛 ≤ 105; 1 ≤ 𝑚 ≤ 105; 0 ≤ 𝑡𝑖 ≤ 109.
    Output Format. Output exactly 𝑚 lines. 𝑖-th line (0-based index is used) should contain two spaceseparated integers — the 0-based index of the thread which will process the 𝑖-th job and the time in
    seconds when it will start processing that job.
    Time Limits. C: 1 sec, C++: 1 sec, Java: 4 sec, Python: 6 sec. C#: 1.5 sec, Haskell: 2 sec, JavaScript:
    6 sec, Ruby: 6 sec, Scala: 6 sec.
    Memory Limit. 512Mb.
    Sample 1.
    Input:
    2 5
    1 2 3 4 5
    Output:
    0 0
    1 0
    0 1
    1 2
    0 4
    Explanation:
  1. The two threads try to simultaneously take jobs from the list, so thread with index 0 actually
    takes the first job and starts working on it at the moment 0.
  2. The thread with index 1 takes the second job and starts working on it also at the moment 0.
  3. After 1 second, thread 0 is done with the first job and takes the third job from the list, and starts
    processing it immediately at time 1.
  4. One second later, thread 1 is done with the second job and takes the fourth job from the list, and
    starts processing it immediately at time 2.
    5
  5. Finally, after 2 more seconds, thread 0 is done with the third job and takes the fifth job from the
    list, and starts processing it immediately at time 4.
    Sample 2.
    Input:
    4 20
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    Output:
    0 0
    1 0
    2 0
    3 0
    0 1
    1 1
    2 1
    3 1
    0 2
    1 2
    2 2
    3 2
    0 3
    1 3
    2 3
    3 3
    0 4
    1 4
    2 4
    3 4
    Explanation:
    Jobs are taken by 4 threads in packs of 4, processed in 1 second, and then the next pack comes. This
    happens 5 times starting at moments 0, 1, 2, 3 and 4. After that all the 5×4 = 20 jobs are processed.

Bài 2:
Problem Introduction
In this problem, your goal is to simulate a sequence of merge operations with tables in a database.
Problem Description
Task. There are 𝑛 tables stored in some database. The tables are numbered from 1 to 𝑛. All tables share
the same set of columns. Each table contains either several rows with real data or a symbolic link to
another table. Initially, all tables contain data, and 𝑖-th table has 𝑟𝑖 rows. You need to perform 𝑚 of
the following operations:

  1. Consider table number 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖. Traverse the path of symbolic links to get to the data. That
    is, while 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖 contains a symbolic link instead of real data do 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖 ← symlink(𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖)
  2. Consider the table number 𝑠𝑜𝑢𝑟𝑐𝑒𝑖 and traverse the path of symbolic links from it in the same
    manner as for 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖.
  3. Now, 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖 and 𝑠𝑜𝑢𝑟𝑐𝑒𝑖 are the numbers of two tables with real data. If 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖 ̸=
    𝑠𝑜𝑢𝑟𝑐𝑒𝑖, copy all the rows from table 𝑠𝑜𝑢𝑟𝑐𝑒𝑖 to table 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖, then clear the table 𝑠𝑜𝑢𝑟𝑐𝑒𝑖
    and instead of real data put a symbolic link to 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖 into it.
  4. Print the maximum size among all 𝑛 tables (recall that size is the number of rows in the table).
    If the table contains only a symbolic link, its size is considered to be 0.
    See examples and explanations for further clarifications.
    Input Format. The first line of the input contains two integers 𝑛 and 𝑚 — the number of tables in the
    database and the number of merge queries to perform, respectively.
    The second line of the input contains 𝑛 integers 𝑟𝑖 — the number of rows in the 𝑖-th table.
    Then follow 𝑚 lines describing merge queries. Each of them contains two integers 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖 and
    𝑠𝑜𝑢𝑟𝑐𝑒𝑖 — the numbers of the tables to merge.
    Constraints. 1 ≤ 𝑛,𝑚 ≤ 100 000; 0 ≤ 𝑟𝑖 ≤ 10 000; 1 ≤ 𝑑𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛𝑖, 𝑠𝑜𝑢𝑟𝑐𝑒𝑖 ≤ 𝑛.
    Output Format. For each query print a line containing a single integer — the maximum of the sizes of all
    tables (in terms of the number of rows) after the corresponding operation.
    Time Limits. C: 2 sec, C++: 2 sec, Java: 14 sec, Python: 6 sec. C#: 3 sec, Haskell: 4 sec, JavaScript: 6
    sec, Ruby: 6 sec, Scala: 14 sec.
    Memory Limit. 512Mb.
    7
    Sample 1.
    Input:
    5 5
    1 1 1 1 1
    3 5
    2 4
    1 4
    5 4
    5 3
    Output:
    2
    2
    3
    5
    5
    Explanation:
    In this sample, all the tables initially have exactly 1 row of data. Consider the merging operations:
  5. All the data from the table 5 is copied to table number 3. Table 5 now contains only a symbolic
    link to table 3, while table 3 has 2 rows. 2 becomes the new maximum size.
  6. 2 and 4 are merged in the same way as 3 and 5.
  7. We are trying to merge 1 and 4, but 4 has a symbolic link pointing to 2, so we actually copy
    all the data from the table number 2 to the table number 1, clear the table number 2 and put a
    symbolic link to the table number 1 in it. Table 1 now has 3 rows of data, and 3 becomes the new
    maximum size.
  8. Traversing the path of symbolic links from 4 we have 4 → 2 → 1, and the path from 5 is 5 → 3.
    So we are actually merging tables 3 and 1. We copy all the rows from the table number 1 into
    the table number 3, and now the table number 3 has 5 rows of data, which is the new maximum.
  9. All tables now directly or indirectly point to table 3, so all other merges won’t change anything.
    Sample 2.
    Input:
    6 4
    10 0 5 0 3 3
    6 6
    6 5
    5 4
    4 3
    Output:
    10
    10
    10
    11
    Explanation:
    In this example tables have different sizes. Let us consider the operations:
  10. Merging the table number 6 with itself doesn’t change anything, and the maximum size is 10
    (table number 1).
    8
  11. After merging the table number 5 into the table number 6, the table number 5 is cleared and has
    size 0, while the table number 6 has size 6. Still, the maximum size is 10.
  12. By merging the table number 4 into the table number 5, we actually merge the table number 4
    into the table number 6 (table 5 now contains just a symbolic link to table 6), so the table number
    4 is cleared and has size 0, while the table number 6 has size 6. Still, the maximum size is 10.
  13. By merging the table number 3 into the table number 4, we actually merge the table number 3
    into the table number 6 (table 4 now contains just a symbolic link to table 6), so the table number
    3 is cleared and has size 0, while the table number 6 has size 11, which is the new maximum size.

Câu 2 dễ nhất.

Đại loại ntn: Bảng thứ i có r[i] dòng hoặc một liên kết đến bảng khác. Thao tác merge bảng i với j đc định nghĩa như sau: nếu bảng i và j đều có dữ liệu và i!=j thì r[i] += r[j] và bảng j chỉ có “vết” trỏ đến bảng i, ngược lại truy vết cho đến khi nào có dữ liệu thì ngừng.

1 Like

cám ơn bạn nhiều, giúp mình câu 1 luôn với :3 tiếng Anh mình gà quá, thực sự không hiểu ý nó muốn gì nữa

Input n thread và m công việc.
In ra m dòng, với dòng thứ i là công việc thứ i với thông tin là thread nào thực hiện công việc này và thời gian bắt đầu công việc. Mỗi công việc sẽ tốn 1s thời gian và thread đc đếm từ 0.
Vd:
input:
2 3
output:
0 0
1 0
0 1

Giải thích: ở giây 0, thread 0 làm công việc 1, thread 1 làm công việc 2
Khi sang giây 1 thì thread 0 lúc này xong việc 1 nên làm công việc 3. Thì lúc này ko còn thread nào nữa nên coi như hết công việc.

2 Likes

Cám ơn bạn đã giải thích, nhưng dòng input ngoài n thread và m job còn dòng thứ 2 nữa mà bạn, nó có ý nghĩa gì vậy?
Ps: năm mới chúc diễn đàn năm mới vui vẻ, thành công trong học tập và công việc.
Ak mình đã hiểu rồi, cám ơn diễn đàn và mọi người. Năm mới ráng cày thêm ngoại ngữ thôi :3

Ặc, đọc thiếu đề :))
Dòng thứ 2 là m dãu số, với số thứ i là tgian hoàn thành công việc thứ i. chứ ko phải 1s như mình nói ~~

Sr bạn nhiều nhé :smiley:
Chúc mừng năm mới vui vẻ nha.

3 Likes

Tên khóa học là gì vậy bạn. Có sub việt không

Bài 2 tối đa là n/2 + O(1) truy cập vào mem cho mỗi truy vấn. Liệu có thể xuống còn O(logn) ko :slight_smile: Vì sao và làm thế nào :smiley:

1 Like

cái này là phần 2 của khóa Data Structures
by University of California, San Diego & Higher School of Economics đó bạn.
không có sub Việt, có sub Anh thôi hehe.

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?