Skip to content

[Dana] Linemarket program#47

Merged
kostis merged 9 commits intokostis:masterfrom
feezz8:master
Feb 26, 2025
Merged

[Dana] Linemarket program#47
kostis merged 9 commits intokostis:masterfrom
feezz8:master

Conversation

@feezz8
Copy link
Contributor

@feezz8 feezz8 commented Feb 19, 2025

This is an implemenation of my solution for the first exercise in
the first coding exercises set for the Algorithms course during the
2024-2025 winter Semester @ ECE/NTUA. The full description of 
the problem can be found in the web page of the course in Helios.

Input: The program reads from the standard input two positive integers, N amount of stores and M amount of spaces to place them. After that for the next M lines it reads from the standard input two non-negative integers defining the begining and the end of each space.
We assume the spaces are given in a random order and their total length is not shorter than N.

Output: Our program prints in the standard output a positive integer, the minimum required distance between two consecutive stores in a placement of all stores such as that minimum distance is maximized.

The complete problem description in greek from the official course site

Άσκηση 1: Υπαίθρια Αγορά
Εν όψει των εορτών, σχεδιάζετε την υπαίθρια Χριστουγεννιάτικη αγορά που θα στηθεί στον κεντρικό πεζόδρομο, στην πρωτεύουσα της χώρας των Αλγορίθμων. Πρόκειται να εγκατασταθούν N υπαίθρια καταστήματα κατά μήκος του πεζόδρομου και έχουν ήδη εντοπισθεί M μη-επικαλυπτόμενες περιοχές, ανάμεσα στα παρτέρια που κοσμούν τον πεζόδρομο, που είναι κατάλληλες για την εγκατάσταση των καταστημάτων. Κάθε τέτοια περιοχή i του πεζόδρομου προσδιορίζεται από ένα διάστημα φυσικών αριθμών
[si, fi], όπου το si ορίζει την αρχή και το fi το τέλος του διαστήματος. Υπαίθρια καταστήματα μπορούν να εγκατασταθούν σε οποιοδήποτε (ακέραιο) σημείο αυτών των περιοχών, χωρίς φυσικά να επιτρέπεται η εγκατάσταση περισσότερων του ενός καταστήματος στο ίδιο σημείο. Ο χώρος που θα έχουν στη διάθεσή τους οι πελάτες ενός καταστήματος είναι ανάλογος της απόστασής του από το πλησιέστερο γειτονικό κατάστημα. Για να μεγιστοποιηθεί ο διαθέσιμος χώρος για τους πελάτες όλων των καταστημάτων, ο Δήμαρχος πρότεινε τον υπολογισμό μιας τοποθέτησης όλων των N καταστημάτων στις επιλεγμένες περιοχές [s1, f1], . . . , [sM, fM] του πεζόδρομου ώστε να μεγιστοποιηθεί η ελάχιστη απόσταση ενός καταστήματος από το πλησιέστερό του γειτονικό κατάστημα. Αποφασίζετε λοιπόν να γράψετε ένα πρόγραμμα που θα υπολογίζει, εύκολα και γρήγορα, μια τέτοια τοποθέτηση των καταστημάτων.
Δεδομένα Εισόδου: Το πρόγραμμά σας αρχικά θα διαβάζει από το standard input δύο θετικούς ακεραίους, το
πλήθος N των καταστημάτων και το πλήθος M των περιοχών. Σε καθεμία από τις επόμενες M γραμμές, θα δίνονται δύο μη-αρνητικοί ακέραιοι si και fi, χωρισμένοι με ένα κενό μεταξύ τους, που προσδιορίζουν την αρχή και το τέλος της i-οστής περιοχής. Οι περιοχές [si, fi] θα δίνονται με αυθαίρετη σειρά και θα είναι ανά δύο ξένες μεταξύ τους, ενώ το συνολικό τους μήκος δεν θα υπολείπεται του N.
Δεδομένα Εξόδου: Το πρόγραμμά σας πρέπει να τυπώνει στο standard output έναν θετικό ακέραιο, την ελάχιστη απόσταση μεταξύ δύο διαδοχικών καταστημάτων σε μια τοποθέτηση όλων των N καταστημάτων που μεγιστοποιεί αυτή την ελάχιστη απόσταση

feezz8 and others added 2 commits February 19, 2025 13:57
    This is an implemenation of my solution for the first exercise in
    the first coding exercises set for the Algorithms course during the
    2024-2025 winter Semester @ ECE/NTUA. The full description of the 
    problem can be found in the web page of the course in Helios.
@kostis
Copy link
Owner

kostis commented Feb 25, 2025

Thanks for your contribution.

This is a very nice program, but I would prefer it if (the most important part of) the problem description appears as a comment, preferably translated into English, at the top of the file, so that the program code is self-contained.

Can you please do this change? Then I will merge this.

Added problem description as a comment
@feezz8
Copy link
Contributor Author

feezz8 commented Feb 26, 2025

Tried my best to add a short but meaningful description of the problem as a comment, along with a small example. I hope this is good enough!

fixed typo in problem desc
@kostis
Copy link
Owner

kostis commented Feb 26, 2025

The program looks good., thanks.

However, the linemarket.input file should only contain one set of inputs (with no comment line above it) and the output should be in a file named linenumber.result (again with no comments). Can you also do this change?

Since the program already has an example input/output in its comments, perhaps you can use the other pair in the .input and .result files.

@kostis kostis changed the title [Dana]: Linemarket dana implementation [Dana] Linemarket program Feb 26, 2025
@kostis
Copy link
Owner

kostis commented Feb 26, 2025

Looks good now - merging.

@kostis kostis merged commit b2ca5c3 into kostis:master Feb 26, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants