Code in Java. Thank you. Mirko has N items (labeled with numbers from 1 to N) and L drawers (labeled with numbers from 1 to L). All items are currently scattered throughout his room, so he decided to clean them up. Each drawer can contain one item, and in order to make it easier for Mirko to find them later, he has determined in advance exactly two drawers (Ai and Bi) for each item i.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Code in Java. Thank you.

Mirko has N items (labeled with numbers from 1 to N) and L drawers (labeled with numbers from 1 to L). All items are currently scattered throughout his room, so he decided to clean them up. Each drawer can contain one item, and in order to make it easier for Mirko to find them later, he has determined in advance exactly two drawers (Ai and Bi) for each item i.

Output
For each item, respectively, output where it ends up. In case the item is stored
successfully, output "LADICA" (without quotes, Croatian word for drawer). In case
the item is thrown away, output "SMECE" (without quotes, Croatian word for
trash).
Sample Input 1
5 3
12
13
1 2
1 3
1 2
Sample Input 2
9 10
12
34
5 6
7 8
9 10
23
1 5
82
79
Sample Output 1
LADICA
LADICA
LADICA
SMECE
SMECE
Sample Output 2
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
Transcribed Image Text:Output For each item, respectively, output where it ends up. In case the item is stored successfully, output "LADICA" (without quotes, Croatian word for drawer). In case the item is thrown away, output "SMECE" (without quotes, Croatian word for trash). Sample Input 1 5 3 12 13 1 2 1 3 1 2 Sample Input 2 9 10 12 34 5 6 7 8 9 10 23 1 5 82 79 Sample Output 1 LADICA LADICA LADICA SMECE SMECE Sample Output 2 LADICA LADICA LADICA LADICA LADICA LADICA LADICA LADICA LADICA
Problem A
Ladice
E
Mirko has N items (labeled with numbers from 1 to N) and L drawers (labeled
with numbers from 1 to L). All items are currently scattered throughout his
room, so he decided to clean them up. Each drawer can contain one item, and in
order to make it easier for Mirko to find them later, he has determined in advance
exactly two drawers (A, and B;) for each item i.
Mirko stores the items in order from 1 to N using the first rule he can apply:
1. If the drawer A, is empty, he stores the item i in that drawer.
2. If the drawer B; is empty, he stores the item i in that drawer.
3. Try to move the item from A; to its other drawer; if that one's filled too, try
moving that item to its other drawer, and so on until you either succeed or
get back to a previously seen drawer. In case of success, store the item i in
the drawer A₁. In case of failure, continue to next rule.
4. Try moving the item from B; to its other drawer; if that one's filled too, try
moving that item to its other drawer, and so on until you either succeed or
get back to a previously seen drawer. In case of success, store the item i in
the drawer B₁. In case of failure, continue to next rule.
5. Give up and throw away the item i.
For given pairs of drawers for each item, determine which items will be stored
and which will be thrown away.
Input
The first line of input consists of two integers, N and L (1 ≤N, L≤ 300 000),
the number of items and the number of drawers.
Each of the following N lines contains two integers: A; and B¡ (1 ≤ A¡, B¡ ≤ L),
the pair of drawers corresponding to item i. The numbers A and B₁ will be
different.
Transcribed Image Text:Problem A Ladice E Mirko has N items (labeled with numbers from 1 to N) and L drawers (labeled with numbers from 1 to L). All items are currently scattered throughout his room, so he decided to clean them up. Each drawer can contain one item, and in order to make it easier for Mirko to find them later, he has determined in advance exactly two drawers (A, and B;) for each item i. Mirko stores the items in order from 1 to N using the first rule he can apply: 1. If the drawer A, is empty, he stores the item i in that drawer. 2. If the drawer B; is empty, he stores the item i in that drawer. 3. Try to move the item from A; to its other drawer; if that one's filled too, try moving that item to its other drawer, and so on until you either succeed or get back to a previously seen drawer. In case of success, store the item i in the drawer A₁. In case of failure, continue to next rule. 4. Try moving the item from B; to its other drawer; if that one's filled too, try moving that item to its other drawer, and so on until you either succeed or get back to a previously seen drawer. In case of success, store the item i in the drawer B₁. In case of failure, continue to next rule. 5. Give up and throw away the item i. For given pairs of drawers for each item, determine which items will be stored and which will be thrown away. Input The first line of input consists of two integers, N and L (1 ≤N, L≤ 300 000), the number of items and the number of drawers. Each of the following N lines contains two integers: A; and B¡ (1 ≤ A¡, B¡ ≤ L), the pair of drawers corresponding to item i. The numbers A and B₁ will be different.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education