LoginSignup
2
0

ABC300以降のグラフ問題を総復習したい

Posted at

はじめに

グラフに苦手意識があるのでグラフ精進をしようと思います.
直近のグラフ出題をまとめている人が調べた限りいなかったので
自分でまとめました.

グラフ

※ 範囲はABC300以降のC~F問です.
  範囲を広げてほしい方がいれば言ってください
ABC302-E - Isolation
ABC303-E - A Gift From the Stars
ABC304-E - Good Graph
ABC305-E - Art Gallery on Graph
ABC305-F - Dungeon Explore
ABC309-D - Add One Edge
ABC311-C - Find it!
ABC318-D - General Weighted Max Matching
ABC324-F - Beautiful Path
ABC328-E - Modulo MST
ABC333-D - Erase Leaves
ABC334-E - Christmas Color Grid 1
ABC335-E - Non-Decreasing Colorful Path
ABC338-F - Negative Traveling Salesman
ABC341-F - Breakdown

やり方

とりあえず,スクレイピングで「グラフ」が含まれる問題を抽出しました.
なのでグリッドとかグラフ問題に帰着が必要な問題は拾えていませんすいません,,
拾う判定を入力形式とか解説まで広げたらもっと増えると思うので,
暇なときにやろうと思います.


# Atcoder ABCの問題ページにアクセスする
# 特定のワードが含まれる問題をcsvファイルに出力する

import requests
from bs4 import BeautifulSoup
import csv
from time import sleep
import random

# 問題に含まれるワードを入力
# string = input('input word: ')
string = 'グラフ'
file_name = 'graph.csv'

# 参照範囲を設定
list = []
for num in range(300,350):
    for level in ('c','d','e','f'):
        
        # アクセス前に1秒前後待機
        sleep(random.uniform(0.8, 1.2))
        url = 'https://atcoder.jp/contests/abc' + str(num) + '/tasks/abc' + str(num) + '_' +level

        try:
            response = requests.get(url)
            response.raise_for_status()  # ステータスコードが200でない場合は、エラーを発生させる

            # BeautifulSoupオブジェクトを作成し、HTMLを解析
            soup = BeautifulSoup(response.text, 'html.parser')

            # 問題文を取得
            title = soup.find('span', class_='h2').text.split('\t')[3][:-1]
            elements = soup.find('div', class_='part').find_all()

            for element in elements:
                for row in element:
                    if string in row:
                        print(f'[ABC{num}-{title}]({url})')
                        list.append([num,level,title,url])
                        break
                else:continue
                break

        # urlが存在しないときは無視
        except requests.exceptions.RequestException as e:
            print(f"URL {url} にアクセスできませんでした: {e}")

with open(file_name, 'w', newline='', encoding='utf-8') as file:
    writer = csv.writer(file)
    writer.writerow(['num','level','title','url'])
    for num,level,title,url in list:
        writer.writerow([num,level,title,url])
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0