ΕΛΛΗΝΙΚΗ ΕΤΑΙΡΕΙΑ ΕΠΙΣΤΗΜΟΝΩΝ ΚΑΙ ΕΠΑΓΓΕΛΜΑΤΙΩΝ ΠΛΗΡΟΦΟΡΙΚΗΣ ΚΑΙ ΕΠΙΚΟΙΝΩΝΙΩΝ GREEK COMPUTER SOCIETY

Σχετικά έγγραφα
24ος ΠΑΝΕΛΛΗΝΙΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ

ΕΛΛΗΝΙΚΗ ΕΤΑΙΡΕΙΑ ΕΠΙΣΤΗΜΟΝΩΝ ΚΑΙ ΕΠΑΓΓΕΛΜΑΤΙΩΝ ΠΛΗΡΟΦΟΡΙΚΗΣ ΚΑΙ ΕΠΙΚΟΙΝΩΝΙΩΝ ΜΕΛΟΣ IFIP, IOI

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 24/3/2007

HY150a Φροντιστήριο 3 24/11/2017

Φροντιςτήριο. Linked-List

ΛΥΣΕΙΣ ΘΕΜΑΤΩΝ ΤΕΛΙΚΗΣ ΦΑΣΗΣ Οι παρακάτω λύσεις είναι απολύτως ενδεικτικές

17TimeThis.h function returns reference pointer to same object { return *this; }

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 6/5/2006

2 Composition. Invertible Mappings

Dynamic types, Lambda calculus machines Section and Practice Problems Apr 21 22, 2016

ΕΝΔΕΙΚΤΙΚΕΣ ΛΥΣΕΙΣ ΠΡΟΒΛΗΜΑΤΟΣ Β ΦΑΣΗΣ

Εντολές εισόδου - εξόδου. Εισαγωγή στη C++

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007

Η εντολή if-else. Η απλή μορφή της εντολής if είναι η ακόλουθη: if (συνθήκη) { Η γενική μορφή της εντολής ifelse. εντολή_1; εντολή_2;..

Overview. Transition Semantics. Configurations and the transition relation. Executions and computation

ΘΕΜΑ Α ΦΑΣΗΣ. Υπολογιστικά Νέφη Ενδεικτικές Απαντήσεις

HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:

24ος ΠΑΝΕΛΛΗΝΙΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ

Μηχανική Μάθηση Hypothesis Testing

Πρόβλημα 1: Αναζήτηση Ελάχιστης/Μέγιστης Τιμής

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 11/3/2006

2. THEORY OF EQUATIONS. PREVIOUS EAMCET Bits.

Πανεπιστήμιο Πελοποννήσου. Σχολή Θετικών Επιστημών & Τεχνολογίας. Τμήμα Επιστήμης & Τεχνολογίας Υπολογιστών. Προγραμματισμός Ι Εργαστήριο

Lab 1: C/C++ Pointers and time.h. Panayiotis Charalambous 1

Other Test Constructions: Likelihood Ratio & Bayes Tests

Π. Σταθοπούλου ή Οµάδα Α (Φοιτητές µε µονό αριθµό Μητρώου ) ιδασκαλία : Παρασκευή 11πµ-13µµ ΗΛ7

ΛΥΣΕΙΣ ΘΕΜΑΤΩΝ ΤΕΛΙΚΗΣ ΦΑΣΗΣ

Problem Set 3: Solutions

Srednicki Chapter 55

PARTIAL NOTES for 6.1 Trigonometric Identities

Το πρόγραμμα θα τυπώνει και τους τρεις πίνακες.

Models for Probabilistic Programs with an Adversary

Section 8.3 Trigonometric Equations

Homework 3 Solutions

Physical DB Design. B-Trees Index files can become quite large for large main files Indices on index files are possible.

The Simply Typed Lambda Calculus

Lab 1: C/C++ Pointers and time.h. Panayiotis Charalambous 1

Ένα απλό πρόγραμμα C

EE512: Error Control Coding

Π. Σταθοπούλου ή Οµάδα Α (Φοιτητές µε µονό αριθµό Μητρώου ) ιδασκαλία : Παρασκευή 11πµ-13µµ ΗΛ7

Προγραμματισμός Ι. Πίνακες, Δείκτες, Αναφορές και Δυναμική Μνήμη. Δημήτρης Μιχαήλ. Τμήμα Πληροφορικής και Τηλεματικής Χαροκόπειο Πανεπιστήμιο

Διάλεξη 6: Δείκτες και Πίνακες

ΓΡΑΜΜΙΚΟΣ & ΔΙΚΤΥΑΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ

CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS

Απαντήσεις στο μάθημα Δομημένος Προγραμματισμός ΕΠΑΛ

ΕΛΛΗΝΙΚΗ ΕΤΑΙΡΕΙΑ ΕΠΙΣΤΗΜΟΝΩΝ ΚΑΙ ΕΠΑΓΓΕΛΜΑΤΙΩΝ ΠΛΗΡΟΦΟΡΙΚΗΣ ΚΑΙ ΕΠΙΚΟΙΝΩΝΙΩΝ ΜΕΛΟΣ IFIP, IOI Org. GREEK COMPUTER SOCIETY MEMBER OF IFIP, IOI Org.

A ΜΕΡΟΣ. 1 program Puppy_Dog; 2 3 begin 4 end. 5 6 { Result of execution 7 8 (There is no output from this program ) 9 10 }

Second Order RLC Filters

Ανάπτυξη Μεγάλων Εφαρµογών στη Γλώσσα C (2)

Math221: HW# 1 solutions

Lecture 2. Soundness and completeness of propositional logic

Matrices and Determinants

ΚΥΠΡΙΑΚΟΣ ΣΥΝΔΕΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY 21 ος ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ Δεύτερος Γύρος - 30 Μαρτίου 2011

Fractional Colorings and Zykov Products of graphs

DESIGN OF MACHINERY SOLUTION MANUAL h in h 4 0.

Section 7.6 Double and Half Angle Formulas

ΕΡΓΑΣΤΗΡΙΟ 1 - ΣΗΜΕΙΩΣΕΙΣ

ΔΟΜΕΣ ΔΕΔΟΜΕΝΩΝ & ΑΛΓΟΡΙΘΜΟΙ ΕΡΓΑΣΤΗΡΙΟ

3.4 SUM AND DIFFERENCE FORMULAS. NOTE: cos(α+β) cos α + cos β cos(α-β) cos α -cos β

ΕΛΛΗΝΙΚΗ ΕΤΑΙΡΕΙΑ ΕΠΙΣΤΗΜΟΝΩΝ ΚΑΙ ΕΠΑΓΓΕΛΜΑΤΙΩΝ ΠΛΗΡΟΦΟΡΙΚΗΣ ΚΑΙ ΕΠΙΚΟΙΝΩΝΙΩΝ GREEK COMPUTER SOCIETY

Στοίβες - Ουρές. Στοίβα (stack) Γιάννης Θεοδωρίδης, Νίκος Πελέκης, Άγγελος Πικράκης Τµήµα Πληροφορικής

Προαπαιτούμενες Ασκήσεις 5 ου Εργαστηρίου. Dose stoixeio (integer) : 25 Found stoixeio in position 7 Dose stoixeio (integer) :94 Value not found

ΑΛΓΟΡΙΘΜΟΙ Άνοιξη I. ΜΗΛΗΣ

Εισαγωγή στον Προγραµµατισµό. Διάλεξη 8 η : Συναρτήσεις Χειµερινό Εξάµηνο 2011

Ασκήσεις σε Επαναληπτικούς Βρόχους και Συναρτήσεις. Επανάληψη για την ενδιάμεση εξέταση. (Διάλεξη 13)

2 η Διάλεξη C++ Δρ. Χρήστος Δρόσος ΑΕΙ ΠΕΙΡΑΙΑ ΤΤ ΤΜΗΜΑ ΑΥΤΟΜΑΤΙΣΜΟΥ

ΕΡΓΑΣΤΗΡΙΟ 5 ΣΗΜΕΙΩΣΕΙΣ

1) Formulation of the Problem as a Linear Programming Model

Τμήμα Πληροφορικής & Επικοινωνιών

ΑΡΧΕΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΥ

Α' Εξάμηνο ΕΙΣΑΓΩΓΗ ΣΤΟ ΔΟΜΗΜΕΝΟ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟ

Εργαστήριο 7: Ο αλγόριθμος ταξινόμησης Radix Sort

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Ψηφιακή Οικονομία. Διάλεξη 10η: Basics of Game Theory part 2 Mαρίνα Μπιτσάκη Τμήμα Επιστήμης Υπολογιστών

24ος ΠΑΝΕΛΛΗΝΙΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ

Εισαγωγή στον Προγραμματισμό

Συμβολοσειρές ΣΥΜΒΟΛΟΣΕΙΡΕΣ. Γεώργιος Παπαϊωάννου ( )

ΕΙΣΑΓΩΓΗ ΣΤΗ ΣΤΑΤΙΣΤΙΚΗ ΑΝΑΛΥΣΗ

Instruction Execution Times

Οντοκεντρικός Προγραμματισμός

i M-1 1. ij f(i, j) N-1. (pixel) 2. M N (x, y) (x, y ) = 256. R(x, y), G(x, y), B(x, y)

Bounding Nonsplitting Enumeration Degrees

Διάλεξη 9η: Πίνακες (arrays)

Προγραμματισμό για ΗΜΥ

Ψηφιακή Οικονομία. Διάλεξη 11η: Markets and Strategic Interaction in Networks Mαρίνα Μπιτσάκη Τμήμα Επιστήμης Υπολογιστών

Εισαγωγή στη Fortran. Μάθημα 3 ο. Ελευθερία Λιούκα

Εισαγωγή στον Προγραμματισμό

Ει αγωγή η Fortran.

Προγραμματισμός Η/Υ (ΤΛ2007 )

Ταξινόµηση και Αναζήτηση

Areas and Lengths in Polar Coordinates

Τμήμα Πληροφορικής & Επικοινωνιών

b. Use the parametrization from (a) to compute the area of S a as S a ds. Be sure to substitute for ds!

Συστήματα Διαχείρισης Βάσεων Δεδομένων

Στόχοι και αντικείμενο ενότητας. Πέρασμα Πίνακα σε Συνάρτηση (συν.) Πέρασμα Πίνακα σε Συνάρτηση. #8.. Ειδικά Θέματα Αλγορίθμων

TMA4115 Matematikk 3

The challenges of non-stable predicates

ΤΕΧΝΟΛΟΓΙΑ ΚΑΙ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΥΠΟΛΟΓΙΣΤΩΝ ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΑΤΡΩΝ ΠΟΛΥΤΕΧΝΙΚΗ ΣΧΟΛΗ ΤΜΗΜΑ ΜΗΧΑΝΙΚΩΝ Η/Υ ΚΑΙ ΠΛΗΡΟΦΟΡΙΚΗΣ

ΕΙΣΑΓΩΓΗ ΣΤΟN ΠΡΟΓΡΑΜΜΑΤΙΣΜΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΑΤΡΩΝ ΠΟΛΥΤΕΧΝΙΚΗ ΣΧΟΛΗ ΤΜΗΜΑ ΜΗΧΑΝΙΚΩΝ Η/Υ ΚΑΙ ΠΛΗΡΟΦΟΡΙΚΗΣ

CHAPTER 48 APPLICATIONS OF MATRICES AND DETERMINANTS

Προσομοίωση BP με το Bizagi Modeler

Transcript:

27 ος ΠΑΝΕΛΛΗΝΙΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ ΕΝΔΕΙΚΤΙΚΕΣ ΛΥΣΕΙΣ Β ΦΑΣΗΣ ΛΥΚΕΙΟ «Η μοιρασιά» PASCAL ΟΡΦΑΝΟΠΟΥΛΟΣ ΧΡΗΣΤΟΣ Π.Π. ΓΕΛ ΕΥΑΓ. ΣΧ. Ν. ΣΜΥΡΝΗΣ [60%] program ishare; var share:text; sum,i,n,mo:longint; kerdos: array[1.. 1000000] of longint; elegxos:boolean; assign(share,'share.in'); reset(share); readln(share,n); for i:=1 to n do readln(share,kerdos[i]); sum:=sum+kerdos[i]; end; close(share); mo:=round(sum/3); if mo<sum/3 then mo:=mo+1; repeat elegxos:=true; i:=1; sum:=0; Σελίδα 1 από 10

while ((sum+kerdos[i])<=mo) and (n-i>=2) do sum:=sum+kerdos[i]; i:=i+1; end; sum:=0; while ((sum+kerdos[i])<=mo) and (n-i>=1) do sum:=sum+kerdos[i]; i:=i+1; end; sum:=0; if (i<n) then for i:=i to n do sum:=sum+kerdos[i]; end; end else if kerdos[n]>mo then mo:=kerdos[n]; if sum>mo then elegxos:=false; mo:=mo+1; end. until elegxos=true; mo:=mo-1; assign(share,'share.out'); rewrite(share); write(share,mo); close(share); halt(0); Σελίδα 2 από 10

ΒΟΛΙΚΑΣ ΜΑΡΚΟΣ / USER: u1732 LANG: C++ TASK: share / CPP Π.Π. ΓΕ.Λ. ΙΩΝΙΔΕΙΟΥ ΣΧΟΛΗΣ ΠΕΙΡΑΙΑ // Volikas Markos # include <cstdio> # include <algorithm> using namespace std; int N,cum[1000005]; bool can(int m) { int first_cut=lower_bound(cum,cum+n,m)-cum; if (first_cut==n cum[first_cut]>m) first_cut--; if (first_cut>=n-1) return true; int second_cut=lower_bound(cum+first_cut+1,cum+n,cum[first_cut]+m)- cum; if (second_cut==n cum[second_cut]>cum[first_cut]+m) second_cut--; if (second_cut<=first_cut) return false; if (second_cut>=n-1) return true; if (cum[n-1]-cum[second_cut]>m) return false; return true; inline void fastscan(int &x) { register int c=getc_unlocked(stdin); x=0; for (; (c<48 c>57); c=getc_unlocked(stdin)); for (; (c>47 && c<58); c=getc_unlocked(stdin)) { x=(x<<1) + (x<<3) + c- 48; int main() { freopen("share.in","r",stdin); Σελίδα 3 από 10

freopen("share.out","w",stdout); int i,a,lo,hi,mid,tmp,ans; fastscan(n); fastscan(cum[0]); lo=cum[0]; for (i=1; i<n; ++i) { fastscan(a); cum[i]=cum[i-1]+a; lo=max(lo,a); hi=cum[n-1]; while (lo<hi) { mid=(lo+hi)>>1; if (can(mid)) hi=mid; else lo=mid+1; printf("%d\n",hi); return 0; Σελίδα 4 από 10

C ΓΚΑΣΔΡΟΓΚΑΣ ΓΕΩΡΓΙΟΣ ΕΝΙΑΙΟ ΛΥΚΕΙ ΠΛΑΤΥΚΑΜΠΟΥ / PDP 2015-2nd Stage: Senior Contestant Name : Gkasdrogkas Georgios (user: u1778) Problem Name : Share Language : C This program finds the minimum profit that can collect the most favored of the three brothers, given the days (N) and the profit of each day (Vi). Max execution time : <= 1 s in worst case (n = 1.000.000) Compexity : O(N), sooner exit possible using values check (Subroutines 1 & 2) This program use a simple logic. Using two pointers pa and pb pointed to array[0] and array[n-1] respectively, and using three integers, each for one brother, we check the next values of the array both for BrotherA and BrotherB. Then we add the minimum of that two sums to correct brother and proceed the correct pointer. Then make again the check so in the end to have the result we want. Subroutine 1 : When we pass the numbers, if the maximum number in the file is greater or equal to all the other sums, then that number is the result we want. Subroutine 2 : If all the profits, in the current state, are equal then we can safely exit the program. / #include <stdio.h> #include <stdlib.h> #include <limits.h> #include <stdbool.h> / Define the min macro and the IO error / #define min(profita, ProfitB, ProfitC) ProfitA > (ProfitB > ProfitC? ProfitB : ProfitC)? ProfitA : (ProfitB > ProfitC? ProfitB : ProfitC) Σελίδα 5 από 10

#define IOERROR 5 // 'Input/Output Error' FILE ReadInput(const char filename_r); int CountDays(FILE input); long PassProfit(FILE input, long array, const int N, const char filename_w); long FindProfit(long array, int N, const char filename_w); long SumArray(long array, int N); void CheckEqual(const long ProfitA, const long ProfitB, const long ProfitC, const char filename_w); long ProcessMin(const long ProfitA,const long ProfitB,const long ProfitC, long currentmin, long bestmin, const char filename_w); void WriteOutput(const long total, const char filename_w); int main() { const char filename_r = "share.in"; const char filename_w = "share.out"; FILE input = ReadInput(filename_r); int N = CountDays(input); long array = malloc(n sizeof array); if (array==null) { exit(1); PassProfit(input, array, N, filename_w); fclose(input); long bestmin = FindProfit(array, N, filename_w); free(array); WriteOutput(bestMin, filename_w); return 0; FILE ReadInput(const char filename_r) { FILE input = fopen(filename_r, "r"); Σελίδα 6 από 10

if (input == NULL) { exit(ioerror); return input; int CountDays(FILE input) { int days = 0; fscanf(input, "%d", &days); return days; long PassProfit(FILE input, long array, const int N, const char filename_w) { long sum = 0, max = 0; for (int i = 0; i < N; i++) { fscanf(input, "%ld", &array[i]); sum += array[i]; if (array[i] > max) { max = array[i]; if (max >= sum - max) { / If the maximum profit is greater or equal / WriteOutput(max, filename_w); / of the other sums (except the max profit) / exit(0); / then that value is what we want! / return array; long FindProfit(long array, int N, const char filename_w) { int pa = 0, pb = N - 1; long pa, pb; pa = &array[0]; pb = &array[n-1]; Σελίδα 7 από 10

long bestmin = LONG_MAX; long ProfitA = array[0]; long ProfitC = array[n-1]; long ProfitB = SumArray(array, N); long currentmin = min(profita, ProfitB, ProfitC); if (currentmin < bestmin) { bestmin = currentmin; bool flag = true; // use of 'stdbool.h' header long check_l = 0, check_r = 0; while ((pb - pa!= 1) && (flag == true)) { flag = false; (pa++); / We try to find what are the sums adding / (pb--); / the next index of the array / check_l = ProfitA + pa; check_r = ProfitC + pb; (pa--); // Return the pointers to the previous state (pb++); / Find the minimum of the two sums and add it to correct brother / if (check_l <= check_r) { (pa++); ProfitA += pa; ProfitB -= pa; pa++; flag = true; else if (check_l > check_r) { (pb--); ProfitC += pb; ProfitB -= pb; pb--; flag = true; check_r = 0, check_l = 0; // zero the check values Σελίδα 8 από 10

bestmin = ProcessMin(ProfitA, ProfitB, ProfitC,currentMin, bestmin, filename_w); return bestmin; long SumArray(long array, int N) { long ProfitB = 0; for (int i = 0; i < N; i++) { ProfitB += array[i]; ProfitB = (ProfitB - array[0]) - array[n-1]; // sum of all numbers except the first and the last element return ProfitB; void CheckEqual(const long ProfitA, const long ProfitB, const long ProfitC, const char filename_w) { if (ProfitA == ProfitC ) { if (ProfitB == ProfitA) { WriteOutput(ProfitA, filename_w); exit(0); long ProcessMin(const long ProfitA,const long ProfitB,const long ProfitC, long currentmin, long bestmin, const char filename_w) { CheckEqual(ProfitA, ProfitB, ProfitC, filename_w); // check if the three brothers have the same profit currentmin = min(profita, ProfitB, ProfitC); // find the minimum of the three sums in current state if (currentmin < bestmin) { bestmin = currentmin; // check if the 'currentmin' is less that the best so far return bestmin; Σελίδα 9 από 10

void WriteOutput(const long total, const char filename_w) { FILE output = fopen(filename_w, "w"); if(output == NULL) { exit(ioerror); fprintf(output, "%ld\n", total); fclose(output); Σελίδα 10 από 10