
C++
gy5461
行成于思而毁于随
展开
-
hypot函数
hypot函数头文件math.h或cmathhypot(a,b)的返回值为double类型,相当于sqrt(a*a+b*b)原创 2018-10-04 21:30:28 · 6173 阅读 · 0 评论 -
ACM/ICPC 2018亚洲区预选赛北京赛站网络赛题目4 : 80 Days
#include <map>#include <cstring>#include <string>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cctype&原创 2018-09-22 18:11:35 · 658 阅读 · 0 评论 -
一只小蜜蜂...HDU2044
#include <map>#include <cstring>#include <string>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cctype&原创 2018-10-06 12:20:00 · 176 阅读 · 0 评论 -
你会自己实现sizeof这个库函数吗?
#define what(v) (char*)(&v+1)-(char*)(&v)7个字符的串,却输出8,因为有'\0'啦哈哈C++学习交流群:群号:810196747原创 2018-09-28 23:39:40 · 651 阅读 · 0 评论 -
线性表(顺序表)
#include<cstdio>#include<cstdlib>#include<iostream>#include<algorithm>using namespace std;//定义顺序表初始容量和扩容容量#define LIST_INIT_SIZE 100#define LISTINCREMENT 10typedef str...原创 2018-09-28 23:53:00 · 215 阅读 · 0 评论 -
线性表(链表)
#include<stdio.h>#include<stdlib.h>typedef struct LNode { int data; struct LNode *next;}LNode,*LinkList;void CreatList_L(LinkList &L, int n) { //逆位序输入n个元素的值,建立带表头结点的单链线性表L. L ...原创 2018-09-28 23:56:18 · 305 阅读 · 0 评论 -
循环队列
#pragma warning(disable:4996);#include<cstdio>#include<cstdlib>int MAXQSIZE = 5;typedef struct { int *base; int front;//队列开始 int rear;//队列结束的下一个位置}SqQueue;bool InitQueue(SqQueue...原创 2018-10-20 19:37:49 · 134 阅读 · 0 评论 -
二叉树非递归后序遍历
#pragma warning(disable:4996)#include<cstdio>#include<cstdlib>typedef struct BiTNode { char data; struct BiTNode *lchild, *rchild;//左右孩子指针}BiTNode,*BiTree;bool CreateBiTree(BiTree ...原创 2018-10-27 15:47:26 · 138 阅读 · 0 评论 -
统计字符串中字符个数
因为ASCII码只有256个,故可以这样做:#pragma warning(disable:4996)#include<cstdio>#include<cstdlib>#include<cstring>char str[200];int cnt[256];void CountChar(char* str) { //统计每个字符出现的个数并打印...原创 2018-10-27 15:50:36 · 532 阅读 · 0 评论 -
随机位置生成随机数
#include<stdio.h>#include<stdlib.h>#include <time.h>int main(){ srand((unsigned)time(NULL)); int num [3][3]; // printf("%d\n",rand()%3); for(int i=0;i<3;i++) ...原创 2018-10-27 16:00:59 · 877 阅读 · 0 评论 -
深入理解并彻底掌握使用unique函数去重
宏观来看,使用unique函数去重主要分为以下几步:以vector为例:声明部分:#include<vector>#include<algorithm>vector<int>v;vector<int>::iterator new_end;三个主要步骤:sort(v.begin(),v.end());//第一步:排序(从小...原创 2018-10-27 21:11:33 · 1124 阅读 · 0 评论 -
洛谷 P1028 数的计算,递推优化版
题目描述我们要求找出具有下列性质数的个数(包含输入的自然数n):先输入一个自然数n(n≤1000),然后对此自然数按照如下方法进行处理: 不作任何处理; 在它的左边加上一个自然数,但该自然数不能超过原数的一半; 加上数后,继续按此规则进行处理,直到不能再加自然数为止. 输入输出格式输入格式:1个自然数(n≤1000)输出格式:1个整数,表示具有...原创 2018-11-07 22:27:49 · 293 阅读 · 0 评论 -
DFS无向网(邻接表)
#pragma warning(disable:4996)#include<cstdlib>#include<cstdio>#include<cstring>#define MAX_VERTEX_NUM 20#define TRUE 1#define FALSE 0#define ERROR -1 /*出错*/#define OK 1i...原创 2018-11-24 19:44:21 · 1178 阅读 · 0 评论 -
BFS无向图(邻接表)
#pragma warning(disable:4996)#include<cstdlib>#include<cstdio>#include<cstring>#define MAX_VERTEX_NUM 20#define TRUE 1#define FALSE 0#define ERROR -1 /*出错*/#define OK 1i...原创 2018-11-24 19:46:00 · 529 阅读 · 0 评论 -
ACM必须注意的一个问题
洛谷P1003 铺地毯第一次交:很奇怪这是为什么,明明很快就出结果了,12s不要太夸张,后来只改了一个字符:‘~’出乎意料的绿了,居然是因为while中scanf前面没有加~,一定要注意这个问题呀,AC代码:#include <map>#include <set>#include <cstring>#include <str...原创 2018-11-25 22:13:53 · 408 阅读 · 0 评论 -
动态链接库注意事项
建立:1.新建VC++->Wndows桌面->动态链接库项目2.写头文件:(注意构造函数和析构函数都要写在头文件中)#ifndef 头文件名#define 头文件名#endif//头文件名写源文件3.源文件->添加新项->代码->模块定义文件(.def)LIBRARY "DLL项目名"EXPORTS 函数名1 @1 ...原创 2019-03-25 22:15:15 · 366 阅读 · 0 评论 -
为什么要写成NULL == p
p == NULL一旦写错为p = NULL大多数编译器连个Warning都不会有。原创 2019-09-26 22:12:41 · 411 阅读 · 0 评论 -
POJ-2503 B - Babelfish
题意:你去了一个新城市,需要听懂别人说话,给你一本字典,通过这本字典,你可以把他们的方言词翻译成你掌握的词汇,如:dog对应方言是ogday,输入字典上收录的词条,如下:dog ogdaycat atcaypig igpayfroot ootfrayloops oopslay注意:字典与查询之间输入换行接下来是根据字典查询方言对应的你掌握的词汇,如果有,打印出对应词汇,如果没...原创 2018-09-21 14:43:26 · 328 阅读 · 0 评论 -
abc:def:ghi=1:2:3问题
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){ int n, i, j; char a[10];//数组定义比实际大一些 for(n = 123; n < 330; n++) { ...原创 2018-09-20 19:18:48 · 632 阅读 · 0 评论 -
银行(Account)
//Account.h#ifndef ACCOUNT_H#define ACCOUNT_Hclass Account{public: Account(int m_accountNumber = 0, double m_availableBalance = 0);// constructor sets attributes 构造函数 double getAvailableBalance() con...原创 2018-06-26 23:28:57 · 875 阅读 · 0 评论 -
异或规律xor
x+y=a;x^y=b;则x=(a-b)/2;//x小y大y=a-x;原创 2018-09-16 21:21:53 · 1533 阅读 · 0 评论 -
解决vs不能用strcpy问题
增加预处理#pragma warning(disable:4996)原创 2018-09-16 21:24:33 · 6824 阅读 · 0 评论 -
J - Ananagrams
Most crossword puzzle fans are used to anagrams — groups of words with the same letters in different orders — for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute...转载 2018-09-18 22:29:14 · 165 阅读 · 0 评论 -
I - Andy's First Dictionary UVA - 10815
Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the wo...原创 2018-09-18 22:32:18 · 142 阅读 · 0 评论 -
eps double 的==与!= :
int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}const double eps=1e-8; 传统意义 修正写法1 修正写法2 a == b sgn(a - b) == 0 fabs(a – b) ...原创 2018-09-18 22:37:26 · 332 阅读 · 0 评论 -
欧拉函数打表:
#define maxn 3000010int p[maxn];void oula(){ int i,j; for(i=1; i<=maxn; i++) p[i]=i; for(i=2; i<=maxn; i+=2) p[i]/=2; for(i=3; i<=maxn; i+=2) if(p[i]==i...原创 2018-09-18 22:38:10 · 209 阅读 · 0 评论 -
网络流:
Ek算法:#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<iostream>#include<queue>using namespace std;int pre[250];int n,m;int ed...原创 2018-09-18 22:39:18 · 99 阅读 · 0 评论 -
马拉车:
char数组型:int const MAX = 110005;char s[MAX << 1];int p[MAX << 1];int Manacher(){ int len = (int)strlen(s), maxp = 0, ans = 0; for(int i = len; i >= 0; i--) { ...原创 2018-09-18 22:40:38 · 209 阅读 · 0 评论 -
字符串在不在字符串数组里:字符串哈希
# include <iostream># include <stdio.h># include <string.h># include <algorithm># include <math.h># include <queue># include <string># include <原创 2018-09-18 22:43:00 · 267 阅读 · 0 评论 -
unique函数:
#include <iostream>#include <cassert>#include <algorithm>#include <vector>#include <string>#include <iterator> using namespace std; int main(){ //cout...原创 2018-09-18 22:43:37 · 630 阅读 · 0 评论 -
线段树求最值:
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;#define maxn 50005#define inf 0x3f3f3f3fint n,q;int a[maxn],ll[maxn<<1]...原创 2018-09-18 22:44:11 · 578 阅读 · 6 评论 -
ST算法求最值:
const int maxn=50005;int a[maxn],dp[maxn][30],d[maxn][30];void rmq(){ for(int i=1;i<=n;i++){dp[i][0]=a[i];d[i][0]=a[i];} for(int j=1;(1<<j)<=n;j++){ for(int i=1;i+(1<...原创 2018-09-19 19:43:40 · 218 阅读 · 0 评论 -
穿越空间的限制,走最短的路找到你
1.最短路u->v之间的最短路满足以下限制: 对任意k ∈ G(V,E) 有 dist u,v <= dis u,k + dis k,j关键操作-松弛:void relax(int i,int j,int k){ if(dis[k]>dis[i]+j) dis[k]=dis[i]+j;} 2.多源点多汇点最短路FLOYD复杂度 O(...原创 2018-09-20 18:58:49 · 200 阅读 · 0 评论 -
提高cin效率
std::ios::sync_with_stdio(false);std::cin.tie(0);原创 2018-09-20 19:01:12 · 252 阅读 · 0 评论 -
C预处理
指示 描述 #define 替代预处理宏 #include 从另一个文件中插入一个特定的头 #undef 取消定义预处理宏 #ifdef 如果定义了这个宏返回true #ifndef...原创 2018-09-20 19:07:49 · 173 阅读 · 0 评论 -
冒泡排序(从小到大)
void bubble(int work[],size_t size,int(*compare)(int a,int b)){ void swap(int *element1Ptr,int *element2Ptr); for(unsigned int pass=1;pass<size;++pass){ for(size_t count=0;count&l...原创 2018-09-20 19:15:49 · 1574 阅读 · 0 评论 -
C++中字符数组与string的相互转换
字符数组转化成string类型charch[]="ABCDEFG";stringstr(ch);//也可stringstr=ch;或者charch[]="ABCDEFG";stringstr;str=ch;//在原有基础上添加可以用str+=ch;将string类型转换为字符数组charbuf[10];stringstr("ABCDEFG")...原创 2019-09-26 22:13:51 · 318 阅读 · 0 评论