WordPress adatbázis hiba: [Unknown column 'pn.profile_name' in 'field list']
SELECT n.*, pn.title, pn.text, pn.tooltip, pn.text_format, pn.use_short_url, pn.icon_image, pn.profile_name, pn.mail_to_default FROM `wp_supsystic_ss_projects` AS p LEFT JOIN `wp_supsystic_ss_project_networks` AS pn ON p.id = pn.project_id LEFT JOIN `wp_supsystic_ss_networks` AS n ON pn.network_id = n.id WHERE p.id = 1 ORDER BY pn.position ASC


Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: Cannot modify header information - headers already sent by (output started at /var/www/fundtech/data/www/fundtech.hu/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php:340) in /var/www/fundtech/data/www/fundtech.hu/wp-includes/feed-rss2.php on line 8
Fundtech http://fundtech.hu Fri, 10 Jun 2016 09:17:19 +0000 hu hourly 1 https://wordpress.org/?v=6.3 Háromszög hármasok http://fundtech.hu/2016/06/09/haromszog-harmasok/ http://fundtech.hu/2016/06/09/haromszog-harmasok/#respond Thu, 09 Jun 2016 19:47:06 +0000 http://fundtech.hu/?p=15 "Háromszög hármasok" bővebben]]>

A topcoder.com oldalon találtam a következő feladatot. Vagyis nem pont ezt, csak egy ehhez hasonlót, amit kicsit átalakítottam. A feladat megoldásán keresztül látható, hogy miként lehet egymásba ágyazott ciklusokat használni, illetve a futási időt hogyan lehet csökkenteni egy kis gondolkodás után.

Az \((a, b, c)\) rendezett számhármast háromszög hármasnak nevezzük, ha \(a\), \(b\) és \(c\) olyan pozitív egész számok, amelyekből háromszög szerkeszthető. Azaz teljesül, hogy bármely két szám összege nagyobb a harmadiknál, azaz \(a + b > c\), \(a + c > b\) és \(b + c > a\).
Adott három pozitív egész szám: \(A\), \(B\) és \(C\). Hány háromszög hármas létezik, ha \(1\leq a\leq A\), \(1\leq b\leq B\) és \(1\leq c\leq C\)?

Adjunk a feladatra egy egyszerű megoldó algoritmust!

def TriangleTriples(A, B, C) :
    counter = 0
    for a in range(1, A + 1) :
        for b in range(1, B + 1) :
            for c in range(1, C + 1) :
                if (a + b > c and a + c > b and b + c > a) :
                    counter += 1
    return counter

A feltétel csak akkor teljesül, ha \(c\) értéke nagyobb \( b-a\)-nál és \( a-b\)-nél, azaz \( c > |b-a|\), illetve \(c < a + b\). Ennek értelmében a harmadik ciklus módosításával a feltétel el is hagyható.

def TriangleTriples(A, B, C) :
    counter = 0
    for a in range(1, A + 1) :
        for b in range(1, B + 1) :
            low = abs(b - a) + 1
            high = min(a + b - 1, C)
            for c in range(low, high + 1) :
                counter += 1
    return counter

Az első és a második ciklus mindig végigfut a teljes \([1, A]\), illetve \([1, B]\) intervallumon, a harmadik ciklus viszont csak az \([1, C]\)-nél általában szűkebb tartományon. Emiatt hasznos lenne, ha \(A\) és \(B\) kisebb lenne \(C\)-nél. Ezt elérhetjük, ha a ciklusok előtt sorba rendezzük a három bemeneti paramétert.

def TriangleTriples(A, B, C) :
    if (A > B) :
        (B, A) = (A, B)
    if (B > C) :
        (C, B) = (B, C)
        if (A > B) :
            (B, A) = (A, B)
    counter = 0
    for a in range(1, A + 1) :
        for b in range(1, B + 1) :
            low = abs(b - a) + 1
            high = min(a + b - 1, C)
            for c in range(low, high + 1) :
                counter += 1
    return counter

Vizsgáljuk meg, hogy a belső ciklust nem lehetne-e teljes egészében kiiktatni a megoldásból. Azért merül fel ez a kérdés, mert minden lefutásnál ugyanaz történik a cikluson belül, 1-gyel megnöveljük a számláló értékét. Ha tudnánk, hányszor fut le a ciklus, akkor a ciklust elhagyva, egyszerűen ennyivel kéne a számlálót növelni.
Négy esetünk van, hiszen a ciklus alsó- és felső határa is kétféleképpen állhat elő.

  • Ha \(a \leq b\) és \(a+b-1 \leq C\), akkor a ciklus \((b-a+1)\)-től \((a+b-1)\)-ig fut, ami \((2a-1)\)-szeri lefutást eredményez.
  • Ha \(a > b\) és \(a+b-1 \leq C\), akkor a ciklus \((a-b+1)\)-től \((a+b-1)\)-ig fut, ami \((2b-1)\)-szeri lefutást eredményez.
  • Ha \(a \leq b\) és \(a+b-1 > C\), akkor a ciklus \((b-a+1)\)-től \(C\)-ig fut, ami \((C+a-b)\)-szeri lefutást eredményez.
  • Ha \(a > b\) és \(a+b-1 > C\), akkor a ciklus \((a-b+1)\)-től \(C\)-ig fut, ami \((C-a+b)\)-szeri lefutást eredményez.

Ennek megfelelően alakul a kód is.

def TriangleTriples(A, B, C) :
    if (A > B):
        (B, A) = (A, B)
    if (B > C) :
        (C, B) = (B, C)
        if (A > B) :
            (B, A) = (A, B)
    counter = 0
    for a in range(1, A + 1) :
        for b in range(1, B + 1) :
            if a + b - 1 <= C :
                if a <= b :
                    counter += 2 * a - 1
                else :
                    counter += 2 * b - 1
            else :
                if a <= b :
                    counter += C + a - b
                else :
                    counter += C - a + b
    return counter

]]>
http://fundtech.hu/2016/06/09/haromszog-harmasok/feed/ 0