DullCodes’s diary

programming,c++,python,MachineLearning,Math,Django,Competitive

competitive

距離 基礎編

ユークリッド距離 マンハッタン距離 チェビシェフ距離 ミンコフスキー距離 AOJ 簡単な数学の知識を少しづつ ユークリッド距離 一番良く知られている距離の測り方 二点間をつなぐ線分の長さのこと math euclid distance マンハッタン距離 京都距離ともいう 2…

Leetcode Easy 500. Keyboard Row

Statement https://leetcode.com/problems/keyboard-row/ Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below. 要するにキーボードの列 "QWERTYUIP", "ASD…

Leetcode Easy 806. Number of Lines To Write String

Statement https://leetcode.com/problems/number-of-lines-to-write-string/ We are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a letter would cause the width o…

Leetcode Easy 1185. Day of the Week

Statement (Good, Bad) = (64, 748) https://leetcode.com/problems/day-of-the-week/ 年月日が整数値で与えられるので曜日を返せ Example Example 1: Input: day = 31, month = 8, year = 2019 Output: "Saturday" Example 2: Input: day = 18, month = 7, …

Leetcode Easy 1078. Occurrences After Bigram

Statement Example Constrains Answer 1 Statement https://leetcode.com/problems/occurrences-after-bigram/ string text, first, secondという文字列が与えられる text は空白に文字列が区切ってある その中にfirst, second が必ず存在している text[i] =…

最大公約数

最大公約数を求めよ 初めてのgcd ユークリッドの互除法 ちゃんとした実装 最大公約数を求めよ https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_1_B $$ 1 ≤ x, y ≤ 10^ 9 $$ が与えられるので、最大公約数を求めよ という問題 2つの整数…

Leetcode Easy 1030. Matrix Cells in Distance Order

Statement Example Constrains Answer 1 Statement https://leetcode.com/problems/matrix-cells-in-distance-order/ 行R 列C と 特定の点 (r0, c0)が与えられる (r, c), where 0 <= r < R and 0 <= c < C 特定の点から座標にある全ての点のマンハッタン距離…

LeetCode Easy 893. Groups of Special-Equivalent Strings

Statement Example Constrains Answer 1 Statement https://leetcode.com/problems/groups-of-special-equivalent-strings/ any two even indexed ってのは、一つ離れたインデックスのこと [0] - [2], [1] - [3], [2] - [4] みたいなやつら Exampleを見ると…

Leetcode Easy 1370. Increasing Decreasing String

Statement Example Constrains Answer 1 Answer 2 Statement https://leetcode.com/problems/increasing-decreasing-string/ Example Example 1: Input: s = "aaaabbbbcccc" Output: "abccbaabccba" Explanation: After steps 1, 2 and 3 of the first itera…

Leetcode Easy 1025. Divisor Game

Statement Example Constrains Answer 1 Statement Alice and Bob take turns playing a game, with Alice starting first. Initially, there is a number N on the chalkboard. On each player's turn, that player makes a move consisting of: Choosing a…

Leetcode Easy 908. Smallest Range I

Statement Example Constrains Answer 1 Answer 2 Answer 3 Statement (Good, Bad) = (176, 902) Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and add x to A[i]. After this process, we have some array…

Leetcode Easy 821. Shortest Distance to a Character

Statement Example Constrains Answer 1 Statement Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. 文字列 S と 文字 Cが与えられる 文字列 Sの中にある文字Cと…

Leetcode Easy 509. Fibonacci Number

Statement Example Constrains Answer 1 Answer 2 Statement The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That i…

Leetcode Easy 1002. Find Common Characters

Statement Example Constrains Answer 1 Statement Given an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For example, if a character o…

Leetcode Easy 1047. Remove All Adjacent Duplicates In String

Statement Example Constrains Answer 1 Answer 2 Statement Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them. We repeatedly make duplicate removals on S until we…

Leetcode Easy 1200. Minimum Absolute Difference

Statement Example Constrains Answer 1 Statement Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs in ascending order(with respect to pairs),…

Leetcode Easy 999. Available Captures for Rook

Statement Example Constrains Answer 1 Statement https://leetcode.com/problems/available-captures-for-rook/ 8 x 8 の盤面が与えられる Rがポーンを取れる数を返せ Example Input: [ [".",".",".",".",".",".",".","."], [".",".",".","p",".",".",".",…

AtCoder 日/立/製/作/所 コンテスト

A B まとめ 無理だね A https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_a 問題文を適当に読んでいて一回WA ちゃんと見たら意味がわからなくなったので 考えたことを全部コードにぶち込む #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n);</bits/stdc++.h>…

Leetcode Easy 344. Reverse String

Statement Example Constrains Answer 1 Answer 2 Statement Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying the …

Leetcode Easy 1160. Find Words That Can Be Formed by Characters

Statement Example Constrains Answer 1 Statement You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be used once). Return the sum of lengths of …

Leetcode Easy 1122. Relative Sort Array

Statement Example Constrains Answer 1 Statement Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the relative ordering of items in arr1 are th…

AtCoder Beginner Contest 158

A B C D E まとめ atcoder 158 problem results 開始してから9分後に参加 あぶねぇぎりぎりだよ A 問題文よりAもしくはBの駅どちらも存在していればよい <=> AAA または BBB の並び意外であればOK string s; cin >> s; if (s == "AAA" || s == "BBB") { cou…

Leetcode Easy 929. Unique Email Addresses

Statement Example Constrains Answer 1 Statement https://leetcode.com/problems/unique-email-addresses/ Example Example 1: Input: [ "test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com"] Output…

Statement Example Constrains Answer 1 Statement Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. 文字列が与えられる 空白で区切って、それぞ…

Leetcode Easy 1237. Find Positive Integer Solution for a Given Equation

Statement Example Constrains Answer 1 Statement (Good, Bad) = (73, 298) Given a function f(x, y) and a value z, return all positive integer pairs x and y where f(x,y) == z. The function is constantly increasing, i.e.: f(x, y) < f(x + 1, y)…

Leetcode Easy 811. Subdomain Visit Count

Statement Example Constrains Answer 1 Statement A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leet…

Leetcode Easy 922 Sort Array By Parity II

Statement Example Constrains Answer 1 Double Ended Queue Answer 2 Statement Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is …

Leetcode Easy 1051. Height Checker

Statement Example Constrains Answer 1 Statement Students are asked to stand in non-decreasing order of heights for an annual photo. Return the minimum number of students that must move in order for all students to be standing in non-decrea…

Leetcode Easy 1337. The K Weakest Rows in a Matrix

Statement Example Constrains Answer 1 Statement Given a m * n matrix mat of ones (representing soldiers) and zeros (representing civilians), return the indexes of the k weakest rows in the matrix ordered from the weakest to the strongest. …

Leetcode Easy 1356. Sort Integers by The Number of 1 Bits

Statement Example Constrains Answer 1 Answer 2 Answer 3 Statement Given an integer array arr. You have to sort the integers in the array in ascending order by the number of 1's in their binary representation and in case of two or more inte…