上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 26 下一页
摘要: 题意:就是说有A、B两个公司要修路,有m条路,可能是属于A修的,也可能是属于B修的,现在要求所有路都联通的情况下的最小权值,并且A公司必须要修k条路。同:代码:#include#include#include#includeusing namespace std;struct node{ int v1,v2; int w;} s[100005],t[100005];int n,m,k,cnts,cntt;int father[100005],sum;int cmp(const node a,const node b){ if(a.w=k) return 1; els... 阅读全文
posted @ 2014-03-04 22:39 紫忆 阅读(1268) 评论(1) 推荐(0) 编辑
摘要: long exp_mod(long a,long n,long b) //a为底数,n为幂数,b为余数{ long t; if(n==0) return 1%b; if(n==1) return a%b; t=exp_mod(a,n/2,b); t=t*t%b; if((n&1)==1) t=t*a%b; return t;} 阅读全文
posted @ 2014-01-27 16:08 紫忆 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 题目大意:有n次询问,给出a到b区间的总和,问这n次给出的总和中有几次是和前面已近给出的是矛盾的??很有意思的一道题目,要是没有做过种类并查集,我肯定会以为这种题目是线段树题目......思路:我们对给出的区间a,b做以下操作,a-1,b 这样的话,当区间为1--2 3--4的时候,我们可以把两个区间合并成是区间1----4。在更新的时候,数值小的一定是为根节点,如此我们围绕根节点来更新就可,具体看代码:#include#include#includeusing namespace std;int father[200005],rank[200005],ans=0;int find(int x 阅读全文
posted @ 2013-12-16 16:24 紫忆 阅读(2472) 评论(0) 推荐(0) 编辑
摘要: 题意描述:简单的讲就是,给你一张无向图,求有多少条路径使得路径上的花费小于L,这里路径上的花费是这样规定的,a、b两点之间的多条路径中的最长的边最小值!思路:这题目有多个询问,肯定要用离线输出。思路的话,我们只需要从小到达枚举边的长度,如果两个并查集没有连通,那么联通之后的路径条数就应该是(num[a]*num[b])........#include#include#include#includeusing namespace std;int father[10005],num[10005];struct node{ int v1,v2; int dis;}s[50005];str... 阅读全文
posted @ 2013-12-16 16:16 紫忆 阅读(1424) 评论(0) 推荐(0) 编辑
摘要: 题意:给你2个图,最大度为2.问两个图是否相似。思路:图中有环、有链,判断环的个数以及每个环组成的人数,还有链的个数以及每个链组成的人数 是否相等即可。如果形成了环,那么每形成一个环,结点数就会多增加1,如果没形成环,那么结点数就会是一样,根据这里,引入set来写,会轻松很多。#include#include#include#include#includeusing namespace std;int father[100000],p[100000],sum[100000];int find(int x){ int i=x,root; while(x!=father[x]) ... 阅读全文
posted @ 2013-12-16 15:23 紫忆 阅读(917) 评论(0) 推荐(0) 编辑
摘要: 思路:对所有路径的速度从小到大排个序,然后枚举高度差就ok......#include#include#include#includeusing namespace std;#define M 10) { for(int i=0;i(s[j].dis-s[i].dis)) { minx=s[j].dis-s[i].dis; } break; } ... 阅读全文
posted @ 2013-12-16 15:11 紫忆 阅读(474) 评论(0) 推荐(0) 编辑
摘要: 这个题目,比较恶心,思路很是简单,就是模拟的时候有些麻烦......水题#include#include#includeusing namespace std;char s[100][100];int t[400][400],vist[400][400];int n,m;int p[13][3][3]={ { 0,1,0, 1,1,0, 0,0,0 }, { 0,1,0, 0,1,1, 0,0,0, }, { 0,0,0, 1,1,0, 0... 阅读全文
posted @ 2013-12-16 15:08 紫忆 阅读(510) 评论(0) 推荐(0) 编辑
摘要: #include#include#include#includeusing namespace std;#define M 25000#define maxn 100000000struct node{ int v1,v2; int dis;}s[M];int cmp(const node a,const node b){ if(a.dis0) { //int m=(n*(n-1))/2; int cnt=0; for(int i=0;i<=n;i++) father[i]=i; for(int i=... 阅读全文
posted @ 2013-12-16 14:58 紫忆 阅读(354) 评论(0) 推荐(0) 编辑
摘要: 题意:就是询问下,一个并查集里面结点数最多的....并输出来,大致是这个意思吧,当然可以离散化下,水题.....#include#include#include#includeusing namespace std;#define M 100005struct{ int father; int sum;} s[4*M];int t[2*M][2],a[2*M];int find(int x){ int i=x,root; while(x!=s[x].father) x=s[x].father; root=x; x=i; while(x!=... 阅读全文
posted @ 2013-12-16 14:55 紫忆 阅读(758) 评论(0) 推荐(0) 编辑
摘要: 这虽然是个并查集水题,但是要注意的地方还真的比较多。首先要所有的房间都连在一个并查集上,然后就是不能存在环......如此应该可以水过.....#include#include#includeusing namespace std;struct node{int x;int y;} no[200002];int f[200002],vis[200002];int find(int x){ return f[x]==x?x:f[x]=find(f[x]);}int main(){ int i,a,b,aa,bb,maxx=0,num=0; //memset(vis,0,size... 阅读全文
posted @ 2013-12-16 14:50 紫忆 阅读(884) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 26 下一页