Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ Update #589

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 84 additions & 2 deletions content/blog/LearningRustThoughKyouPro/Ex1/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "[番外編] アルゴリズム・データ構造ごとに問題を分類してみる"
postdate: "2023-11-23"
update: "2023-12-14"
update: "2023-12-16"
seriesName: "競プロで学ぶRust"
seriesSlug: "LearningRustThoughKyouPro"
description: "アルゴリズムやデータ構造ごとに解ける問題を分類しました。"
Expand Down Expand Up @@ -62,6 +62,45 @@ mod tests {
```
</details>

## 累積和

### ABC099 B - Stone Monument

[B - Stone Monument](https://atcoder.jp/contests/abc099/tasks/abc099_b)

<details>
<summary>コード例を見る</summary>

```rust
// https://atcoder.jp/contests/abc099/tasks/abc099_b

pub fn run(a: usize, b: usize) -> usize {
let mut cum_sum = Vec::new();

for i in 0..=(b-a) {
if i == 0 {
cum_sum.push(i)
} else {
cum_sum.push(cum_sum[i-1] + i);
}
}

*cum_sum.iter().last().unwrap() - b
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test() {
assert_eq!(2, run(8, 13));
assert_eq!(1, run(54, 65));
}
}
```
</details>

## bit全探索

[bit 全探索 - けんちょんの競プロ精進記録](https://drken1215.hatenablog.com/entry/2019/12/14/171657)
Expand Down Expand Up @@ -275,7 +314,6 @@ mod tests {
}
}
```

</details>

## 再帰関数
Expand Down Expand Up @@ -1159,6 +1197,50 @@ mod tests {
```
</details>

### AGC005 A - STring

[A - STring](https://atcoder.jp/contests/agc005/tasks/agc005_a)(<span style="color: green">Difficulty : 1054</span>)

<details>
<summary>コード例を見る</summary>

```rust
// https://atcoder.jp/contests/agc005/tasks/agc005_a

pub fn run(s: &str) -> usize {
let chars: Vec<char> = s.chars().collect();

chars.iter()
.fold(Vec::new(), |mut stack, c| {
stack.push(*c);

let len = stack.len();

if len >= 2 && stack[len-2] == 'S' && stack[len-1] == 'T' {
stack.truncate(len-2);
stack
} else {
stack
}
})
.iter()
.count()
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test() {
assert_eq!(4, run("TSTTSS"));
assert_eq!(0, run("SSTTST"));
assert_eq!(4, run("TSSTTTSS"));
}
}
```
</details>

## HashMap

### ABC230 B - Election
Expand Down