随笔分类 -  C/C++

摘要:The void_t idiom in C++ template metaprogramming. 阅读全文
posted @ 2021-06-08 15:30 Pat 阅读(105) 评论(0) 推荐(0)
摘要:I learned this trick from "hitonanode" 's "submission" on AtCoder. The trick is like What I used to do is like using this trick, the code becomes I th 阅读全文
posted @ 2019-11-05 09:59 Pat 阅读(159) 评论(0) 推荐(0)
摘要:Fisher Yates shuffle Durstenfeld's in place version 现在问题是如何给随机数引擎 一个种子(seed)。常见的办法是用系统时间: 或者 。但是这种方法有争议,见 https://stackoverflow.com/q/36663027/6052725 阅读全文
posted @ 2019-09-18 11:16 Pat 阅读(267) 评论(0) 推荐(0)
摘要:C++ Primer 5th edition, chapter 13. The Rule of Three If a class needs a destructor, it almost surely needs a copy constructor and copy assignment ope 阅读全文
posted @ 2019-09-13 23:48 Pat 阅读(208) 评论(0) 推荐(0)
摘要:我已经在博客里面发布了好几篇 CLion 使用笔记了,没追究这是第几篇,姑且算作第三篇。 我的 CLion 是搭配了 "MSYS2" 和 "Conan" 使用的。MSYS2 提供 C++ toolchain。Conan 作为 C++ 包管理工具,用它可以方便地安装 Boost 等 C++ 库。 MS 阅读全文
posted @ 2019-05-30 03:26 Pat 阅读(2389) 评论(0) 推荐(0)
摘要:Separate compilation let us split our programs into several files, each of which can be compiled independently. allows programs to be written in logic 阅读全文
posted @ 2019-04-08 23:37 Pat 阅读(352) 评论(0) 推荐(0)
摘要:Macro expansion is done by the C preprocessor at the beginning of compilation. The C preprocessor is named and usually can be invoked from command lin 阅读全文
posted @ 2019-03-10 15:11 Pat 阅读(491) 评论(0) 推荐(0)
摘要:C++'s most vexing parse 是 Scott Meyers 在其名著《Effective STL》中创造的一个术语。 Scott 用这个术语来形容 C++ 标准对于 declaration 语句的消歧义(ambiguity resolution)约定与常人的认知相悖。 形如 或 的 阅读全文
posted @ 2019-03-05 16:33 Pat 阅读(1733) 评论(0) 推荐(1)
摘要:第一次注意到这个问题。 cppreference 上的条目: "lower_bound" "upper_bound" C++17 草案 N4659 lower_bound Requires: The elements of shall be partitioned with respect to t 阅读全文
posted @ 2018-11-06 11:27 Pat 阅读(567) 评论(0) 推荐(0)
摘要:这篇博客的源起是下面的一段代码 其中 相当于 (`std::priority_queue clear()` 方法)。以前我清空 priority_queue 用的是 然而 "编译器" 对这个语句给出了一个警告: (g++ 6.3.0: ) 概念 implicit class type convers 阅读全文
posted @ 2018-07-21 16:36 Pat 阅读(599) 评论(0) 推荐(0)
摘要:"题目链接" "题解视频" "题解文档" 解法概要: 问题可以转化为 考虑一个长为 $2n$ 的数组 $A$,$1$ 到 $n$ 这 $n$ 个整数每个恰在 $A$ 中出现 $2$ 次。判断是否存在一个长为 $n$ 的子段使得 $1$ 到 $n$ 在其中各出现一次。 这个经典问题可用双指针在 $O( 阅读全文
posted @ 2018-05-23 22:06 Pat 阅读(489) 评论(0) 推荐(0)
摘要:我并不会写 CMakeFiles 。 我要对拍,所以需要按下 Ctrl + F9 后同时编译 main.cpp 和 ref.cpp 两个文件,并生成 main.exe 和 ref.exe 以备进一步处理。 我把 CMakeLists.txt 写成 (其他无关的部分省略了) 然而这样仍旧只编译 mai 阅读全文
posted @ 2018-04-16 15:48 Pat 阅读(803) 评论(0) 推荐(0)
摘要:lambda expression(lambda 表达式,$\lambda$ 表达式) 是 C++ 11 引入的特性。 一般而言,lambda 表达式的返回值类型可不指定,而由返回值推断。 需要注意的是:在不指定返回值类型时,lambda 表达式的返回值类型推断是 不 支持隐式(或称「自动」)类型转 阅读全文
posted @ 2017-12-26 01:36 Pat 阅读(907) 评论(0) 推荐(0)
摘要:题目大意 考虑一个 $4$ 行 $n$ ($4\le n\le 1000$)列的矩阵 $f$,$f$ 中的元素为 或 。 对 $f$ 进行若干次如下变换: 将一个 $k\times k$($1\le k \le 4$)的子矩阵中的元素全部替换为 ,代价为 $a_k$( $1 \le a_k \le 阅读全文
posted @ 2017-12-20 17:06 Pat 阅读(506) 评论(0) 推荐(0)
摘要:题目大意 给定正整数 $n$($2\le n\le 10^9$)。 考虑无序整数对 $(x, y)$($1\le x,y\le n, x\ne y$)。 求满足 「$x+y$ 结尾连续的 9 最多」的数对 $(x,y)$ 的个数。 例子: $n=50$,$(49,50)$ 是一个满足条件的数对。 比 阅读全文
posted @ 2017-12-17 22:17 Pat 阅读(203) 评论(0) 推荐(0)
摘要:题目大意 给定 $n$($n\le 50000$) 个由小写英文字母构成的字符串,每个串的长度不超过 10,每个串有一个权值 $v$ ($1\le v\le 100000$)。 回答 $m$($m\le 50000$)组询问,询问格式为两个字符串 $p,s$,求输入中满足「以 $p$ 为前缀并且以 阅读全文
posted @ 2017-12-14 17:03 Pat 阅读(260) 评论(0) 推荐(0)
摘要:__int128 是 GCC 提供的扩展(extension),可以当作 128 位整数使用。 关于 __int128 和 __int128_t Normally, _t suffix means a typedef, __ prefix means reserved for compiler an 阅读全文
posted @ 2017-12-13 09:14 Pat 阅读(3691) 评论(0) 推荐(0)
摘要:Windows 上的 C++ 编译器主要有: "MinGW" (Minimalist GNU for Windows) "TDM GCC" (TDM 是 Twilight Dragon Media 的缩写) "Mingw w64" (A Windows compiler suite combinin 阅读全文
posted @ 2017-12-04 17:24 Pat 阅读(1745) 评论(0) 推荐(0)
摘要:Reference Web cites for the C++ standard library 1. "cppreference" 2. "cplusplus" 3. "sgi" 4. "IBM" 5. "MSDN" 6. "isocpp" More resources at this "page 阅读全文
posted @ 2016-11-03 15:51 Pat 阅读(381) 评论(0) 推荐(0)
摘要:( This article is under constant construction ) DISCLAIMER: 本文的主要内容来自 "https://gcc.gnu.org/onlinedocs/gcc/" 这篇随笔主要记录有关build C/C++程序的知识. 包括 gcc/g++ 的各个 阅读全文
posted @ 2016-11-01 17:52 Pat 阅读(1336) 评论(0) 推荐(0)