diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-10-31 14:54:29 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-10-31 14:54:29 +0100 |
commit | 9c061b8b28b48612b8abbf5209783fdd2bc04fb8 (patch) | |
tree | 38bbdb46988c9ed70fa115dab3c680ebf86192aa | |
parent | cv (diff) | |
download | r-9c061b8b28b48612b8abbf5209783fdd2bc04fb8.tar r-9c061b8b28b48612b8abbf5209783fdd2bc04fb8.tar.gz r-9c061b8b28b48612b8abbf5209783fdd2bc04fb8.tar.bz2 r-9c061b8b28b48612b8abbf5209783fdd2bc04fb8.tar.lz r-9c061b8b28b48612b8abbf5209783fdd2bc04fb8.tar.xz r-9c061b8b28b48612b8abbf5209783fdd2bc04fb8.tar.zst r-9c061b8b28b48612b8abbf5209783fdd2bc04fb8.zip |
-rwxr-xr-x | skripti/fienta_availability.sh | 44 | ||||
-rw-r--r-- | šola/aps1/dn/osvetlitev/Makefile | 4 | ||||
-rw-r--r-- | šola/aps1/dn/osvetlitev/in.txt | 9 | ||||
-rw-r--r-- | šola/aps1/dn/osvetlitev/resitev.cpp | 46 |
4 files changed, 103 insertions, 0 deletions
diff --git a/skripti/fienta_availability.sh b/skripti/fienta_availability.sh new file mode 100755 index 0000000..79018ee --- /dev/null +++ b/skripti/fienta_availability.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -e +if [ x$1 = x ] +then + echo uporaba: $0 spoznavni-zur-fri [sekund] >&2 + echo če je 2. argument nastavljen, program ne exita in v neskončnost piše timestampane podatke o zasedenosti, sicer outputa samo enkrat podatke o zasedenosti brez timestampov >&2 + echo če sta prvi argument dve mali črki, se izpišejo prosta mesta za vse evente v državi s to kodo države >&2 + exit 1 +fi +fienta_availability() { + p=`rev <<<$0 | cut -d/ -f1 | rev` + t=`mktemp -p "" $p.XXX` + page=`curl --no-progress-meter --fail-with-body --cookie $t --cookie-jar $t https://fienta.com/$1` + token=`tr '<' $'\n' <<<$page | grep _token | cut -d\" -f6` + items=`grep -o 'data-id="[0-9]*"' <<<$page | cut -d \" -f2` + postbody=`for item in $items; do echo -n "&qty%5B$item%5D=1000000"; done` + curl --no-progress-meter --cookie $t --cookie-jar $t https://fienta.com/$1 -X POST -H 'X-Requested-With: XMLHttpRequest' --data-raw "_token=$token$postbody" | tr ']' $'\n' | grep "availability has been changed" | sed -E 's/.*"qty.([0-9]*)":."Sorry, \\"(.*)\\" availability has been changed meanwhile. We only have ([0-9]*) places* left.*/\1\t\2\t\3/g' + rm $t +} +fienta_all() { + all=`curl --no-progress-meter --fail-with-body https://fienta.com/?country=$1 | grep ?utm_source=fienta-search | grep -v /s/ | cut -d/ -f4 | cut -d? -f1 | tr $'\n' ' '` + for slug in $all + do + fienta_availability $slug | sed -e "s/^/$slug\t/" + done +} +fienta_entry() { + if [ `wc -c <<<$1` -eq 3 ] + then + fienta_all $1 + else + fienta_availability $1 + fi +} +if [ x$2 = x ] +then + fienta_entry $1 +else + while : + do + fienta_entry $1 | sed -e "s/^/`date +%s`\t/" + sleep $2 + done +fi diff --git a/šola/aps1/dn/osvetlitev/Makefile b/šola/aps1/dn/osvetlitev/Makefile new file mode 100644 index 0000000..2d78386 --- /dev/null +++ b/šola/aps1/dn/osvetlitev/Makefile @@ -0,0 +1,4 @@ +program: resitev.cpp + g++ -Wall -Wextra -pedantic -Wformat-security -std=c++20 -o$@ $< +clean: + rm program diff --git a/šola/aps1/dn/osvetlitev/in.txt b/šola/aps1/dn/osvetlitev/in.txt new file mode 100644 index 0000000..76b90fe --- /dev/null +++ b/šola/aps1/dn/osvetlitev/in.txt @@ -0,0 +1,9 @@ +30 +7 +10 2 +23 2 +14 1 +4 1 +14 4 +11 5 +1 2 diff --git a/šola/aps1/dn/osvetlitev/resitev.cpp b/šola/aps1/dn/osvetlitev/resitev.cpp new file mode 100644 index 0000000..0a17f31 --- /dev/null +++ b/šola/aps1/dn/osvetlitev/resitev.cpp @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +struct event { + int pos; + bool tip; // true za začetek, false za konec +}; +int compar_events (const void * a, const void * b) { + if (((struct event *) a)->pos == ((struct event *) b)->pos) + return 0; + if (((struct event *) a)->pos < ((struct event *) b)->pos) + return -1; + return 1; +} +int main (void) { + struct event events[20000]; + int M, N, x, d; + scanf("%d %d", &M, &N); + for (int i = 0; i < N; i++) { + scanf("%d %d", &x, &d); + events[2*i].pos = x-d >= 0 ? x-d : 0; + events[2*i].tip = true; + events[2*i+1].pos = x+d <= M ? x+d : M; + events[2*i+1].tip = false; + } + qsort(events, 2*N, sizeof events[0], compar_events); + int osv = 0; + int depth = 0; + int start; + for (int i = 0; i < 2*N; i++) { + // fprintf(stderr, "pos=%d\ttip=%d\n", events[i].pos, events[i].tip); + if (events[i].tip == true) { + if (depth == 0) + start = events[i].pos; + depth++; + } + if (events[i].tip == false) { + depth--; + if (depth == 0) + osv += events[i].pos - start; + } + } + if (depth != 0) + fprintf(stderr, "depth == %d\n", depth); + printf("%d\n", M-osv); +} |