|
摘要:http://ac.jobdu.com/problem.php?pid=1501如果一行数列里没有0,则我的方法是用两个变量正数与负数,sum表示前面数的乘积, 随时将sum 正负归类放在两个变量里,到 i 位置若为sum为负数,则在负数优先队列里找最大的负数去除到 i 位置若为sum为正数,则在正数优先队列里找#includedouble zmin;//ᅰ�ᅧ�double Fmax;//ᄌ쳐�double inp[100099];double dp[100099];int main(){ int n; while(scanf("%d",&n)!=EOF){ i
阅读全文
摘要:主要是对字符串的查找,为了方便并且快速的实现查找,用map会比较方便同时如何把一个带有空格的字符串变成多个单词也有一个小技巧char *point=book[i].keyWord;//关键词分离 while(*point){ sscanf(point,"%s",str); point+=strlen(str)+1; string stemp(str); mm_keyWord[stemp].push_back(i);}#include#include#include#include#include#include#include#include#in...
阅读全文
摘要:题意:成员A与成员B通话 ,成员B与成员C通话,则 ABC即为一个团伙,一共有若干个团伙,每个团伙的人数大于2且相互通话时间超过一定值即为黑帮,每个黑帮伙里有一个BOSS,boss是与各个成员打电话最多的那一个,找出所有黑帮boss跟与之相应成员数,按字典序排列。分析:通话姓名是字符串,不好直接构图,离散化一下,在用并查集确定团伙,在查找黑帮与BOSS#include#include#include#include#include#includeusing namespace std;int bossLen[2099];int oneLen[2099];int Link[2099];int n
阅读全文
摘要:http://ac.jobdu.com/problem.php?pid=1522我想到了用multiset的方法#include#include#include#include#include#includeusing namespace std;struct data{ int v; friend bool operator set1; stacksta; char s[9]; int temp; for(i=1;i::iterator po; for(po=set1.begin();p...
阅读全文
摘要:http://pat.zju.edu.cn/contests/pat-a-practise/1021无环连通图也可以视为一棵树,选定图中任意一点作为根,如果这时候整个树的深度最大,则称其为 deepest root。 给定一个图,按升序输出所有 deepest root。如果给定的图有多个连通分量,则输出连通分量的数量。1.使用并查集判断图是否为连通的。2.任意选取一点,做 dfs 搜索,选取其中一个最远距离的点 A,再做一次 dfs,找到的所有距离最远的点以及点 A 都是 deepest root。考虑到为稀疏图,则使用动态链表#include#include#include#include
阅读全文
摘要:惭愧,队列栈集合的容器操作滚瓜烂熟,但是就这个不熟,最近快毕业了,毕业论文上,老师说开静态数组不科学,所以就用这个吧,囧转下别的博客动态创建二维vector数组二维vectorvector<vector <int> > ivec(m ,vector<int>(n)); //m*n的二维vector动态创建m*n的二维vector方法一:vector<vector <int> > ivec;ivec.resize(m);for(int i=0;i<m;i++) ivec[i].resize(n);方法二:vector<vec
阅读全文
摘要:查询某个数字第N次出现在数列的位置mapView Code #include<stdio.h>#include<map>#include<string.h>#include<iostream>using namespace std;int mhash[1000099];struct data{ int x,y; friend bool operator <(data a,data b){//用map一定要写,不然会出错 if(a.y==b.y) return a.x<b.x; else return a.y<b.y;...
阅读全文
摘要:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=497&page=show_problem&problem=3146STL的使用,同时注意出栈出队列是的 empty判断View Code #include<iostream>#include<queue>#include<stack>#include<stdio.h>using namespace std;struct data { int v; int k;
阅读全文
摘要:注意不是优先队列,因为优先队列只能对队头进行操作,所以……单调队列,从队头到队尾所有都可以操作http://acm.hdu.edu.cn/showproblem.php?pid=4122一开始把时间,什么年月日,转化为时间小时(开始搞错WA了一次)后来使用单调队列,维护队列,使之到i 生产的最优,过期的出队列View Code #include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;char Month[13][9]={
阅读全文
摘要:最小的整数(HD版)时间限制 : 1000 ms 内存限制 : 100 MB提交次数 : 60 通过次数 : 5题目描述还记得上次新生赛的题目《最小的整数》么,这次题意有少许更改,但是基本题意还是不变的,数据量有所增加,做好心里准备喽。有一个整数(为n位数),你可以在这个数上去掉任意位,剩下的位置不变,比如123458 ,去掉第3位(从右往左第三位)留下12358,问用这种方法修改这个数直到只剩下一个m位整数,问最小的m位数是多少?我给的数据第一位不会是0。输入描述 测试数据有多组(大约100组),每组两行数据 ,第一行为两个整数 n,m(0<m<n<1000000),第一个
阅读全文
摘要:有N个人要去膜拜JZ,他们不知道JZ会出现在哪里,因此每个人有一个活动范围,只要JZ出现在这个范围内就能被膜拜,伟大的JZ当然希望膜拜他的人越多越好,但是JZ不能分身,因此只能选择一个位置出现,他最多可以被多少人膜拜呢,这个简单的问题JZ当然交给你了A_i..B_i (1 <=A_i <= B_i <= 1,000,000,000)N (1 <= N <= 50,000)44 81 25 103 5输出3思路:考虑到a,b的范围很大,N范围小,果断离散化一下,离散化以后,如果直接 add[] 暴力统计区间,会超时,考虑线段树,使用懒惰标记 500msView Co
阅读全文
摘要:http://www.zybbs.org/JudgeOnline/problem.php?id=1653STL组合数枚举下算总和的话其实就是杨辉三角View Code #include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[19];int b[19];int s[19][19];void fun(){ int i,j; memset(s,0,sizeof(s)); for(i=1;i<=10;i++)
阅读全文
摘要:思想是按草的新鲜程度作为第一关键词,前作为第二关键词排序(因为要取钱较少的,所以草鲜嫩排第一)multiset 储存符合第二关键词的 所有第一关键词,取合理且最小的第一关键词累积View Code #include<stdio.h>#include<algorithm>#include<iostream>#include<vector>#include<set>using namespace std;int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EO
阅读全文
摘要:G++提交会超时,C++不会超时View Code #include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){ int a[209],n,m,t,i; scanf("%d",&t); bool use; while(t--) { use=0; scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf(&
阅读全文
摘要:用到STL里的next_permutation(&a[0],&a[le])//说明a[0]->a[le-1]是自由排列的View Code #include<iostream>#include<string.h>#include<algorithm>using namespace std;bool cmp(char a,char b){ return a<b;}int main(){ char a[209]; while(gets(a)) { int le=strlen(a); sort(&a[0],&a[le],
阅读全文
摘要:set统计太方便了View Code #include<iostream>#include<set>using namespace std;struct data{ int x,y;}a[209];int main(){ int n; set<double>set1; while(scanf("%d",&n)!=EOF) { set1.clear(); int i,j; for(i=1;i<=n;i++) { scanf("%d%d",&a[i].x,&a[i].y); } double
阅读全文
|