More Related Content
Similar to ものづくりに活かす数学 (2024 年 1 月 26 日 N/S 高等学校での数学の授業) (20)
More from Kensuke Otsuki (14)
ものづくりに活かす数学 (2024 年 1 月 26 日 N/S 高等学校での数学の授業)
- 2. 自己紹介 (経歴)
• 2014年:東京大学大学院 情報理工学系研究科 修了
• 2015年:NTT データ数理システム AI リサーチャー
• 2017〜2019年:ブログ活動
• 2020〜2022年:アルゴリズム本で印税生活
• 2011年:東京大学 工学部 航空宇宙工学科 卒業
• 2022年:株式会社アルゴ式 共同創業
• 2023年〜:モノグサ株式会社 コンテンツアーキテクト
- 4. 自己紹介 (趣味)
(1月26日) (7 の形) (1234567890 で「コ」)
• 虫食算作り
❌
1
2
• ボルダリング
• 競技プログラミング (AtCoder など)
• 国内旅行、鉄道旅行
6
• ブログ
- 14. 14
ビット演算
• ポケモンの状態の管理
#include <iostream>
#include <bitset>
using namespace std;
const unsigned int BIT_FLAG_DAMAGE = 0b00000001; // HP が満タンでないか
const unsigned int BIT_FLAG_MAHI = 0b00000010; // 麻痺状態になっているか
const unsigned int BIT_FLAG_SENTOFUNO = 0b00000100; // 戦闘不能状態になっているか
// atack して、単にダメージを受ける
const unsigned int MASK_ATTACK = BIT_FLAG_DAMAGE;
// punch して、ダメージも受けて、麻痺もする
const unsigned int MASK_PUNCH = BIT_FLAG_DAMAGE | BIT_FLAG_MAHI;
int main() {
// start: 0000, 初期状態
unsigned int status = 0;
cout << "start: " << bitset<4>(status) << endl;
// attacked: 0001 になる
status |= MASK_ATTACK;
cout << "attacked: " << bitset<4>(status) << endl;
// punched: 0011 になる
status |= MASK_PUNCH;
cout << "punched: " << bitset<4>(status) << endl;
return 0;