cout

luogu P3254 圆桌问题

天大地大妈咪最大 提交于 2020-02-12 12:51:37
简单的最大流问题,一样的设源点汇点,每个单位向每个餐桌连capacity为1的边,源点向每个单位连capacity为人数的边,每个餐桌向汇点连capacity为座位数的边,跑最大流,若flow=总人数则有方案,遍历每一个单位流量为1的点即可 #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x)&(-x)) typedef long long LL; const int maxm = 1e5+5; const int INF = 0x3f3f3f3f; struct edge{ int u, v, cap, flow, nex; } edges[maxm]; int head[maxm], cur[maxm], cnt, level[1024]; void init() { memset(head, -1, sizeof(head)); } void add(int u, int v, int cap) { edges[cnt] = edge{u, v, cap, 0, head[u]}; head[u] = cnt++; } void addedge(int u, int v, int cap) { add(u, v, cap), add(v, u, 0); } void bfs(int s) {

C++11中新特性之:initializer_list详解

孤人 提交于 2020-02-11 07:03:03
C++11提供的新类型,定义在<initializer_list>头文件中。 template< class T > class initializer_list; 先说它的用处吧,然后再详细介绍一下。 首先有了initializer_list之后,对于STL的container的初始化就方便多了,比如以前初始化一个vector需要这样: int a[] = {0, 1, 2, 3}; std::vector<int> vec(a, a+sizeof(a)); 或者 std::vector<int> vec; vec.push_back(1); vec.push_back(3); vec.push_back(3); vec.push_back(2); 有了initializer_list后,就可以直接像初始化数组一样: class Test { private: static std::map<string, string> const nameToBirthday = { {"lisi", "18841011"}, {"zhangsan", "18850123"}, {"wangwu", "18870908"}, {"zhaoliu", "18810316"}, }; } 当然啦,里面的std::map必须提供参数为initializer_list的构造函数如: map( std

汉诺塔(记录每种路径次数)

一世执手 提交于 2020-02-11 02:24:45
https://ac.nowcoder.com/acm/contest/3004/I 题意:输出汉诺塔移动过程中每一种移动的次数和移动总数。 如下 A->B:XX A->C:XX B->A:XX B->C:XX C->A:XX C->B:XX SUM:XX 解法:记忆化搜索,当前状态的可以由上一状态得到。 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <cstdio> #include <string> #include <stdio.h> #include <queue> #include <stack> #include <map> #include <set> #include <string.h> #include <vector> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF 0x3f3f3f3f #define mod 998244353 #define PI acos(-1) using

stl_string复习

独自空忆成欢 提交于 2020-02-10 20:43:20
#include <iostream> #include <string> #include <algorithm> using namespace std; void definition() //定义 { string str(5,'a'); cout << str <<endl; string str1("abcdefghijklmn"); cout << str1 <<endl; string str2("123456789",3); cout << str2 <<endl; string str3("abcdefghijklmn",3,5); cout << str3 <<endl; } void output(string str) //输出 { cout << str << "\n" << str.c_str() << '\n' << str[3] << str.at(3) <<endl; } void attribute(string str) //属性 { string str1("123"); cout << str1.capacity() << endl; //空间大小 str1.reserve(18); //重置空间大小 cout << str1.capacity() << endl; cout << str.length() << endl; /

bitset用法

旧街凉风 提交于 2020-02-10 20:32:05
头文件:#include <bitset> bitset类型在定义时就需要指定所占的空间,例如 bitset<233>bit; bitset类型可以用string和整数初始化(整数转化成对应的二进制) int main() { bitset<23>bit (string("11101001")); cout<<bit<<endl; bit=233; cout<<bit<<endl; return 0; } /* 00000000000000011101001 00000000000000011101001 */ bitset支持所有的位运算 bitset<8> foo ("10011011"); cout << foo.count() << endl;  //5  (count函数用来求bitset中1的位数,foo中共有5个1 cout << foo.size() << endl;   //8  (size函数用来求bitset的大小,一共有8位 cout << foo.test(0) << endl;  //true  (test函数用来查下标处的元素是0还是1,并返回false或true,此处foo[0]为1,返回true cout << foo.test(2) << endl;  //false  (同理,foo[2]为0,返回false cout << foo.any()

c++之文件IO

守給你的承諾、 提交于 2020-02-10 20:22:40
四、 I/O 操作 1. 基本输入输出 在针对I/O操作时,标准库提供一组操作符( manipulator ),允许程序堆输出的内容进行格式化,比如:输出数字的十六进制、浮点值的精度等。类似以前的 endl 就是一个操作符,但它并不是一个普通的值,是用于输出一个换行符并且兼具刷新缓冲区的功能。 输出布尔数据 在c/c++中,在对bool类型的数据做输出的时候,打印的是 0 、1 ,如果希望看到的是 true 和 false ,那么可以使用 boolalpha 操作符。 bool flag = false; cout << "flag的值是:" << flag << endl; // 打印 0 //操作符只会影响后续的输出 打印 0 false cout << "flag的值是:" << flag <<" 添加操作符后:"<<boolalpha << flag << endl; 输出整形数字 在输出数字时,可以选择使用 十进制 、 八进制 、 十六进制 输出 ,它们只会影响整形数字, 默认会采用十进制输出数字 cout <<"十进制:" << dec <<9 << endl; // 9 cout <<"八进制:" << oct <<9 << endl; // 10 cout <<"十六进制:" << hex <<10 << endl; // a /

C++——函数

北城余情 提交于 2020-02-10 13:04:05
文章目录 函数重载 函数重载匹配 函数重载的原理 代码示例 函数的缺省参数(默认实参) 代码示例 哑元函数 代码示例 内联函数(inline) C++的动态内存分配 代码示例 引用(reference) 定义 常引用 引用型函数参数 代码示例 函数重载 在相同的作用域,定义同名的函数,但是它们的参数有所区分,这样的函数之间的关系称为函数重载。 函数重载匹配 调用重载关系的函数时,编译器将根据实参和形参匹配程度,自动选择最优的重载版本。 当前g++编译器匹配的一般规则: 完全匹配 >=常量转换 > 升级转换 > 降级转换 > 省略号 函数重载的原理 C++编译器是通过对函数进行换命,将参数表的类型信息整合到新的名字中,解决函数重载和名字冲突的矛盾。 使用关键字“extern”用于声明C++中的函数,要求该函数不做换名以方便C程序调用该函数。 代码示例 overload.cpp # include <iostream> using namespace std ; int foo ( int i ) { cout << "foo(int)" << endl ; } void foo ( int i , int j ) { cout << "foo(int,int)" << endl ; } void foo ( int a , float f ) { cout << "foo(int

C++ string类的使用

﹥>﹥吖頭↗ 提交于 2020-02-09 19:05:15
C++ string的使用 在了解如何使用string类之前,我们先来看看C语言中使用字符串有 多麻烦 : 调用头文件:cstring 定义一个C字符串: char str1[51]="Hello World"; char str2[51]="你好,世界"; printf("%s \n %s",&str1,&str2); 判断两个字符串是否相等: if(strcmp(str1,str2)) //do sth. 后续赋值: strcpy(str1,str2); 现在来看看string是如何使用的: string类的成员函数: | 名称 |功能 | |--|--| | 构造函数 | 初始化字符串 | | 析构函数| 销毁字符串 | | =| 赋值 | |+,+ =,append( ),push_back() |拼接字符串 | | insert ()| 插入字符 | |erase() | 删除字符| | clear()| 移除全部字符(相当于="")| |resize() |改变字符数量 | | replace()| 替换字符| |!=,==,<,<= ,>=,>,|比较字符串 | |c_str()| 将内容以 C - string 形式返回| |substr() |返回子字符串| |size(),length() |返回字符串长度 | |find() |搜寻某子字符串或字符|

C++ printing boolean, what is displayed?

情到浓时终转凉″ 提交于 2020-02-09 02:09:39
问题 I print a bool to an output stream like this: #include <iostream> int main() { std::cout << false << std::endl; } Does the standard require a specific result on the stream (e.g. 0 for false )? 回答1: The standard streams have a boolalpha flag that determines what gets displayed -- when it's false, they'll display as 0 and 1 . When it's true, they'll display as false and true . There's also an std::boolalpha manipulator to set the flag, so this: #include <iostream> #include <iomanip> int main()

C++ printing boolean, what is displayed?

烂漫一生 提交于 2020-02-09 02:09:18
问题 I print a bool to an output stream like this: #include <iostream> int main() { std::cout << false << std::endl; } Does the standard require a specific result on the stream (e.g. 0 for false )? 回答1: The standard streams have a boolalpha flag that determines what gets displayed -- when it's false, they'll display as 0 and 1 . When it's true, they'll display as false and true . There's also an std::boolalpha manipulator to set the flag, so this: #include <iostream> #include <iomanip> int main()