C/C++
文章平均质量分 59
詠生
这个作者很懒,什么都没留下…
展开
-
multiset与set
set的含义是集合,它是一个有序的容器,里面的元素都是排序好的,支持插入,删除,查找等操作,就 像一个集合一样。所有的操作的都是严格在logn时间之内完成,效率非常高。 set和multiset的区别是:set插入的元素不能相同,但是multiset可以相同。原创 2017-01-24 12:14:19 · 159 阅读 · 0 评论 -
hdu--1045--Fire Net,NYOJ--587--dfs--blockhouses
/* Name: NYOJ--587--blockhouses Author: shen_渊 Date: 16/04/17 21:43 Description: dfs,逐个点深度优先搜索,不管能不能放炮台都得继续搜索,能放时考虑放不放 */#include#includeusing namespace std;bool check(int,int);void dfs(int原创 2017-04-16 21:47:37 · 233 阅读 · 0 评论 -
NYOJ--1100--WAJUEJI which home strong!
/* Name: NYOJ--1100--WAJUEJI which home strong! Author: shen_渊 Date: 15/04/17 21:02 Description: bfs+优先队列 ,这是一道水题,然而WA无数次, 第一次让我认识到,除了线程,还有程序员管不了的东西 */#include#include #includeusing name原创 2017-04-16 19:47:08 · 315 阅读 · 0 评论 -
hdu--1711--kmp应用在整形数组--Number Sequence
/* Name: hdu--1711--Number Sequence Author: shen_渊 Date: 16/04/17 19:58 Description: 第一次知道,KMP能用在整形数组 o(╯□╰)o */#include#includeusing namespace std;int kmp();void getFail();int n,m;int s原创 2017-04-16 20:19:56 · 190 阅读 · 0 评论 -
NYOJ--94--cigarettes
#includeint main(){ int N; scanf("%d",&N); while(N--) { int n,k; int m; scanf("%d %d",&n,&k); int last = n; while(n >= k) { m = n%k; n /= k; last += n; n原创 2016-08-02 20:02:49 · 326 阅读 · 0 评论 -
NYOJ--25--A Famous Music Composer
#include #includeint main(){ char arr1[5] = {0},arr2[10] = {0}; int i=1; while(scanf("%s%s",arr1,arr2) != EOF) { if(!strcmp(arr1,"A#"))printf("Case %d: Bb %s\n",i,arr2); else if原创 2016-08-02 20:02:16 · 383 阅读 · 0 评论 -
强大的string :: iterator 和next_permutation
//NYOJ--STL--擅长排列的小明#include #include #include using namespace std;string a="123456789";int main(){int n;cin >> n;while(n--){int n,m;cin >> n >> m;string output转载 2017-01-24 11:45:35 · 446 阅读 · 0 评论 -
NYOJ--927--搜索--The partial sum problem
/* Name: NYOJ--927--The partial sum problem Author: shen_渊 Date: 15/04/17 19:41 Description: DFS,和 NYOJ--1058--dfs--部分和问题 基本一致,递归的i+1注意了,其他没什么 */#include#includeusing namespace std;void dfs原创 2017-04-15 19:44:12 · 231 阅读 · 0 评论 -
NYOJ--1058--dfs--部分和问题
/* Name: NYOJ--1058--部分和问题 Author: shen_渊 Date: 15/04/17 19:27 Description: 简单的DFS,以为马上过的,递归的i+1写错了,重复好多情况 */#include #includeusing namespace std;void dfs(int,int);int n,k,flag;int arr[22]原创 2017-04-15 19:29:26 · 208 阅读 · 0 评论 -
HDU--1195--bfs--Open the Lock
/* Name: HDU--1195--Open the Lock Author: shen_渊 Date: 17/04/17 08:54 Description: bfs,用四维数组标记状态,每位数字可以做三种操作 +1,-1,交换 */#include#include#includeusing namespace std;struct node{ int steps;原创 2017-04-17 08:55:48 · 233 阅读 · 0 评论 -
hdu--1548--dfs--蜘蛛牌
/* Name: hdu--1548--蜘蛛牌 Author: shen_渊 Date: 17/04/17 09:15 Description: dfs,不好想,看两个大神的代码好久http://www.cnblogs.com/sook/archive/2011/03/27/1996775.html http://blog.csdn.net/cscj2010/art原创 2017-04-17 10:12:02 · 379 阅读 · 0 评论 -
hdu--1358--KMP算法失配函数getfail()的理解--Period
/* Name: hdu--1358--Period Copyright: ©2017 日天大帝 Author: 日天大帝 Date: 20/04/17 10:24 Description: 长度/向后移动的位数 = 出现的次数 kmp其实匹配到了第str.size()位,这一位原本是'\0'的, 但是由于里面的递推下一位的关系,这一位其实也是匹配了的; 这原创 2017-04-20 10:56:03 · 1015 阅读 · 0 评论 -
NYOJ--811--变态最大值
#include#includeint smax(int a,int b,int c){int max;max = (max = a>b?a:b)>c?max:c;return max;}int smin(int a,int b,int c){int max;max = (max = areturn max;}int main(){i原创 2016-07-30 09:44:08 · 545 阅读 · 0 评论 -
NYOJ--27--dfs--水池数目
/* Name: NYOJ--27--水池数目 Author: shen_渊 Date: 17/04/17 15:42 Description: 经典dfs水题,,, */#include#includeusing namespace std;int m,n,map[105][105],ct;void dfs(int,int);int dir[8][2] = {原创 2017-04-17 15:43:57 · 287 阅读 · 0 评论 -
NYOJ--21--bfs--三个水杯
/*输入第一行一个整数N(0<N<50)表示N组测试数据接下来每组测试数据有两行,第一行给出三个整数V1 V2 V3 (V1>V2>V3 V10)表示三个水杯的体积。第二行给出三个整数E1 E2 E3 (体积小于等于相应水杯体积)表示我们需要的最终状态输出每行输出相应测试数据最少的倒水次数。如果达不到目标状态输出-1*//* Name: NYOJ--21--三个水杯 Autho原创 2017-04-17 15:14:33 · 211 阅读 · 0 评论 -
NYOJ--19--next_permutation()--擅长排列的小明
/* Name: NYOJ--19--擅长排列的小明 Copyright: 2017 日天大帝 Author: 日天大帝 Date: 20/04/17 11:06 Description: 这道题可以DFS,然而用next_permutation更简单些 主要是全排列,将所有字符串考虑到后,只输出前m个字符 */#include#includeusing namespa原创 2017-04-20 11:59:31 · 332 阅读 · 0 评论 -
NYOJ--86--set.find()--找球号(一)
/* Name: NYOJ--86--找球号(一) Copyright: ©2017 日天大帝 Author: 日天大帝 Date: 20/04/17 14:45 Description: 理想很美好,现实很残酷,准备用字符串水过,结果TLE了 ╮(╯▽╰)╭ */#ifdef FAIL#include using namespace std;int main(){//原创 2017-04-20 15:18:52 · 279 阅读 · 0 评论 -
NYOJ--95--multiset--众数问题
/* Name: NYOJ--95--众数问题 Copyright: ©2017 日天大帝 Author: 日天大帝 Date: 20/04/17 16:02 Description: multiset水过 */#include#include using namespace std;multiset st;int main(){ ios::sync_with_stdio原创 2017-04-20 16:05:18 · 302 阅读 · 0 评论 -
NYOJ--13--打表--Fibonacci数
#include#includeint main(){ int a,b,c,N,i=2,m=0; int *q; scanf("%d",&N);fflush(stdin); q=(int *)malloc((N+1)*sizeof(int)); for(;m { scanf("%d",&q[m]); } m=0; while(N--) {原创 2016-06-29 17:04:15 · 308 阅读 · 0 评论 -
NYOJ--733--万圣节派对
#includeint deno(int a)//去掉大于4的 { for(int i=0;i { int k=a%10; if(k!=1&&k!=6) { continue; } int m=a/10; m %= 10; if( (k==1 && m == 6)|| (k==6 && m == 1)) { retur原创 2016-08-02 20:05:24 · 415 阅读 · 0 评论 -
NYOJ--714--Card Trick
/* Name: NYOJ--714--Card Trick Author: shen_渊 Date: 19/04/17 19:35 Description: 早上训练的第六届河南省程序设计大赛的题,看了数据只有13个,(没毛病,可以打表) 想用链表做,竟然没用过链表 看了别人的队列做的,才知道队列也可以 比赛的时候竟然是手算打表做的,心塞o(╯□╰)o */原创 2017-04-19 19:45:00 · 244 阅读 · 0 评论 -
NYOJ--42--dfs--一笔画问题
/* Name: NYOJ--42--一笔画问题 Author: shen_渊 Date: 18/04/17 15:22 Description: 这个题用并查集做,更好。在练搜索,试试手 本来用的vector存放边,结果,vector并不能当做数组,遍历的时候只能用迭代器 中间没有数据的部分读取会出错 输入第一行只有一个正整数N(N<=10)表示测试数据的组数。原创 2017-04-18 15:28:51 · 322 阅读 · 0 评论 -
NYOJ--266--字符串逆序输出
#include#includeint main(){int N;char arr[40] = {0};scanf("%d",&N);getchar();//fflush(stdin);两个结果一样,为何在nyoj测试用fflush不通过while(N--){gets(arr);fflush(stdin);for(int i=strlen(arr)-原创 2016-07-28 09:36:51 · 390 阅读 · 0 评论 -
hdu--3782--找规律--xxx定律
/* Name: hdu--3782--xxx定律 Author: shen_渊 Date: 17/04/17 21:34 Description: 找规律题,又想打表了 *//*for(int i=2;i<30;++i){ if(i%2==0){ cout<<i<<" "<<subHalf(i)<<" "<<addBig(subHalf(i))<<"\t增加了:\t"原创 2017-04-17 21:44:41 · 713 阅读 · 0 评论 -
字符串--hdu--3783--ZOJ
/* Name: 字符串--hdu--3783--ZOJ Author: shen_渊 Date: 17/04/17 20:58 Description: 明天开始刷字符串的题,先来道水题 */#include#include using namespace std;int ct[27];int main(){ string str; while(cin>>str){原创 2017-04-17 21:00:17 · 231 阅读 · 0 评论 -
NYOJ--24--素数距离问题
#include#include#includeint main(){ int *a,N,i,j=0,k,m,*num,d,n,*q; scanf("%d",&N);n=N; a=(int *)malloc((N+1)*sizeof(int)); num=(int *)malloc(2*(N+1)*sizeof(int)); q=(int *)malloc(2*原创 2016-06-30 09:03:09 · 339 阅读 · 0 评论 -
NYOJ--65--另一种阶乘问题
#include#includeint main(){int N;int *a;int num;int i;int j;int answer = 0;scanf("%d",&N);while(N--){scanf("%d",&num);a=(int*)malloc(sizeof(int)*num);for(i=0;i{a[i] =原创 2016-07-28 23:16:23 · 405 阅读 · 0 评论 -
C++中堆和栈的完全解析(转)
内存分配方面:堆: 操作系统有一个记录空闲内存地址的链表,当系统收到程序的申请时,会遍历该链表,寻找第一个空间大于所申请空间的堆结点,然后将该结点从空闲结点链表中删 除,并将该结点的空间分配给程序,另外,对于大多数系统,会在这块内存空间中的首地址处记录本次分配的大小,这样代码 中的delete语句才能正确的释放本内存空间。我们常说的内存泄露,最常见的就是堆泄露(还有资源泄露),它是指程序在运行转载 2017-02-14 17:31:53 · 188 阅读 · 0 评论 -
使用我的编译器,下面的代码 int i=7; printf("%d\n", i++ * i++); 返回 49?不管按什么顺序计算, 难道不该打印出56吗?
尽管后缀自加和后缀自减操作符 ++ 和 -- 在输出其旧值之后才会执行运算, 但这里的“之后”常常被误解。没有任何保证确保自增或自减会在输出变量原值之 后和对表达式的其它部分进行计算之前立即进行。也不能保证变量的更新会在表 达式 “完成” (按照 ANSI C 的术语, 在下一个 “序列点” 之前, 参见问题 3.7) 之前 的某个时刻进行。本例中, 编译器选择使用变量的旧值相乘以后再对二者进行自原创 2016-08-15 15:37:38 · 801 阅读 · 0 评论 -
NYOJ--113--字符串替换
/* Name: NYOJ--113--字符串替换 Author: shen_渊 Date: 18/04/17 15:41 Description: 字符串水题,秒过 */#include using namespace std;int main(){ ios::sync_with_stdio(false); string str; const string syou =原创 2017-04-18 15:42:21 · 270 阅读 · 0 评论 -
NYOJ--241--字母统计
/* Name: NYOJ--241--字母统计 Author: shen_渊 Date: 18/04/17 17:12 Description: 水过,C++11特性不能用,尴尬 */#include using namespace std;int main(){// freopen("in.txt","r",stdin) ; int t;cin>>t; while(t-原创 2017-04-18 17:16:12 · 305 阅读 · 0 评论 -
NYOJ--491--dfs(打表水过)--幸运三角形
/* Name: NYOJ--491--幸运三角形 Author: shen_渊 Date: 15/04/17 16:26 Description: DFS超时,深搜出第一行的所有情况,计算之后打表水过 0,0,0,4,6,0,0,12,40,0,0,171,410,0,0,1896,5160,0,0,32757*/#include#includeusing names原创 2017-04-15 17:16:33 · 192 阅读 · 0 评论 -
NYOJ--488--dfs--素数环
/* Name: NYOJ--488--素数环 Author: shen_渊 Date: 15/04/17 15:30 Description: DFS,素数打个表,37以内就够用了*/#include#include#include#includeusing namespace std;void dfs(int);int n;//int prime[25] = {2原创 2017-04-15 16:18:27 · 319 阅读 · 0 评论 -
NYOJ--353--bfs+优先队列--3D dungeon
/* Name: NYOJ--3533D dungeon Author: shen_渊 Date: 15/04/17 15:10 Description: bfs()+优先队列,队列也能做,需要开一个vis[35][35][35]标记*/#include#includeusing namespace std;struct node{ int x,y,z,steps; no原创 2017-04-15 15:14:12 · 222 阅读 · 0 评论 -
NYOJ--325--深度优先搜索--zb的生日
/* Name: NYOJ--325--zb的生日 Author: shen_渊 Date: 15/04/17 08:18 Description: 输入时计算总质量,DFS搜索和总质量差值一般最接近的质量和,当val已经大于总质量一般时剪枝 清空数组 DFS:选与不选 */#include #include#includeusing namespace st原创 2017-04-15 10:01:13 · 235 阅读 · 0 评论 -
NYOJ--284--广搜+优先队列--坦克大战
/* Name: NYOJ--284--坦克大战 Author: shen_渊 Date: 14/04/17 19:08 Description: 广度优先搜索+优先队列 注意清空地图 对输入地图进行了预处理,将S,R设置为# */#include #include #includeusing namespace std;const char YOU =原创 2017-04-14 21:25:25 · 275 阅读 · 0 评论 -
NYOJ--202--红黑树
/* Name: NYOJ--202--红黑树 Author: shen_渊 Date: 14/04/17 18:31 Description: 用结构体模拟二叉树的节点,因为左旋右旋不影响中序遍历,所以直接中序遍历 */#include #includeusing namespace std;struct node{ int left,right;}Tree[15];原创 2017-04-14 18:50:00 · 224 阅读 · 0 评论 -
NYOJ--2--括号配对问题
/* Name: NYOJ--2--括号配对问题 Author: shen_渊 Date: 18/04/17 21:15 Description: 先入栈个‘#’ 就好做了 */#include using namespace std;bool cmp(char,char) ;int main(){ int n;cin>>n; while(n--){ string st原创 2017-04-18 21:21:17 · 227 阅读 · 0 评论 -
HDU-2017-字符串统计
/* Name: HDU-2017-字符串统计 Author: shen_渊 Date: 18/04/17 20:19 Description: 水过 */#includeusing namespace std;int main(){ int n;cin>>n; while(n--){ string str;cin>>str; int ct = 0; for(s原创 2017-04-18 20:19:57 · 281 阅读 · 0 评论 -
NYOJ--56--阶乘因式分解(一)
/* Name: NYOJ--56--阶乘因式分解(一) Author: 日天大帝 Date: 20/04/17 20:45 Description: 求n的阶乘,这个数字可能很大,所以换别的思路做 n100,m=5,1-100中是5的倍数的有5、10、15……100,共20个,从这20个数中各分解出一个5 ,则有20个5,然后这20个数变成20、19、18……1,1-2原创 2017-04-20 20:53:06 · 260 阅读 · 0 评论