上一页 1 2 3 4 5 6 7 8 ··· 26 下一页
摘要: A题,一个简单的bfs#include#include#include#include#include#define maxn 100009 using namespace std;int vis[maxn];vectorve[maxn];queueq; bool bfs(int s){ int l; vis[s]=1; q.push(s); while(!q.empty()) { int v=q.front(); q.pop(); l=ve[v].size(); for(int i=0; ivis[v]+1... 阅读全文
posted @ 2014-03-09 19:06 Yours1103 阅读(225) 评论(0) 推荐(0) 编辑
摘要: lcis#include#include#include#define maxn 504using namespace std;int a[maxn];int b[maxn];int f[maxn];int pre[maxn][maxn];int biao[maxn];int main(){ int n,m; int t; while(scanf("%d",&n)!=EOF) { memset(f,0,sizeof f); memset(pre,0,sizeof pre); for(int i=1; ib[j]&&ma0;i--... 阅读全文
posted @ 2014-03-08 17:09 Yours1103 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 一道区间更新、查询的题;但是线段树不能做插入;后来才知道用splay;splay用来做区间查询的话,先将l-1旋转到根节点,然后把r+1旋转到根节点的右节点;这样的话,根节点的右节点的左子树就是我们要的区间;我的代码是网上大神的代码改了一下过来的,存着做模板;#include#include#include#define maxn 2000009#define lch(rt) son[rt][0]#define rch(rt) son[rt][1]using namespace std;int son[maxn][2],fa[maxn],size[maxn],val[maxn],st[maxn 阅读全文
posted @ 2014-03-04 13:42 Yours1103 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 3757一个模拟题,简单,但容易错;3758 大素数判定就行;#include#include#include#define maxn 100009using namespace std;int ans[3];int hit[maxn];int in[maxn];int ball[maxn];bool vis[maxn];int main(){ int n,m; int p,q; while(scanf("%d%d",&n,&m)!=EOF) { ans[0]=0; ans[1]=0; memset(vis,0,sizeof v... 阅读全文
posted @ 2014-03-02 23:11 Yours1103 阅读(246) 评论(0) 推荐(0) 编辑
摘要: 很简单但很虐心的一道题;我感觉自己的算法没错,但是老是过不了;= =但是还是把代码贴出来;我的方法,用并查集的方式做一课树,然后对树进行遍历;有多少棵树就有多少个点剩余;#include#include#include#define inf 1000000000#define maxn 2009using namespace std;struct node{ int x; int y; int p; int sum; int son[5]; bool operator =4)flag=0; return flag;}void dfs(int root)... 阅读全文
posted @ 2014-03-02 23:07 Yours1103 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 在第8组数据上WA了一天,后来才发现问题;#include#include#include#include#define maxn 200009#define inf 1e15using namespace std;int n,k,q;struct node{ int score; int pain; bool operatorb.score;}bool vis[maxn];int s[maxn];long long check(int p){ long long ans=0; int cnt_1=0; for(int i=1;i=p-1)cnt_1++; ... 阅读全文
posted @ 2014-03-01 16:14 Yours1103 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 这道题目的意思是对于每个要删除的数字,向前或向后找到一块连续的数字,而它是其中最小的;很容易看出对于所有要先删除的数字要从大到小删除;然后对于每个要删除的字母,要找到比他小的,但是在原数列中又靠它最近的数字;这样的话,很直观最多只能用lg n的复杂度来处理这个问题;可以用二分查找,也可以用set来代替;考虑到前面删除的一些数字不能计算进去,还要一个快速计算区间和的算法,用树状数组和线段树都可以;不过看到tags,上面写着还可以用dsu(disjoint set union)并查集来做;感觉挺神奇的,想到了之后再补上!#include#include#include#include#define 阅读全文
posted @ 2014-02-25 13:44 Yours1103 阅读(246) 评论(0) 推荐(0) 编辑
摘要: 直接从后面往前面扫,如果前面大,就把后面丢掉再把前面剩下的进行类似的处理就行;#include#include#include#define maxn 100005using namespace std;char s[maxn];int main(){ cin>>s; int l=strlen(s); int head=l-1,tail=l-1; int cnt=1; while(1) { while(s[head]=='0')head--; if(head>(tail-head+1)) { c... 阅读全文
posted @ 2014-02-24 12:33 Yours1103 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 本题的主要算法就是区间更新和区间求和;可以用线段树和树状数组来做;感觉线段树写的太麻烦了,看到官方题解上说可以用树状数组做,觉得很神奇,以前用过的树状数组都是单点维护,区间求和的;其实树状数组还可以区间维护,单点求值;和区间维护,区间求和的;详情请见博客。#include#include#include#include#define maxn 4000010#define ll long longusing namespace std;ll a[2][maxn];ll b[2][maxn];void add_a(int flag,int x,ll value){ while(x>0) . 阅读全文
posted @ 2014-02-23 21:29 Yours1103 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 几个小结论:1.路径长度=i+j-1;2.最简单的走法是先横走再竖着走或者先竖着走再横着走#include#includeusing namespace std;void print(int x,int y){ for(int i=1; im)continue; ans+=l-1; cnt++; if(cnt>=k)break; } if(cnt>=k)break; } printf("%d\n",ans);// printf("%d %d\n",l,i); for(; ... 阅读全文
posted @ 2014-02-23 13:57 Yours1103 阅读(160) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 26 下一页