数据结构-线段树-并查集-树状数组
文章平均质量分 64
码码要洗手
我很重要
展开
-
人工湖工路
点击打开链接 首先,用广度优先搜索肯定会超时。 所以,考虑用树状数组。 用一个数组记录ma[i]表示第i条到第i+1条路是边通的。那么就可以计算顺里针或者逆时针1的和数是否与城市的数目相等即可。 这可以用快速求和的方法——树状数组。 #include #include int c[100010],ma[100010]; int lowbit(int x){原创 2014-02-17 13:08:14 · 616 阅读 · 0 评论 -
敌兵布阵
点击打开链接 树状数组的应用。 #include #include int a[50010],c[50010]; int cnt = 1; int lowbit(int x){ return x&(-x); } void insert(int k,int d,int maxs){ while(k<=maxs){ c[k] += d;原创 2014-02-17 14:04:32 · 535 阅读 · 0 评论 -
宗教信仰
点击打开链接 并查集的应用。 #include #include int f[50005],sum; int find(int x){ if(f[x]!=x){ f[x] = find(f[x]); } return f[x]; } void make(int a,int b){ int f1 = find(a);原创 2014-02-17 14:14:51 · 701 阅读 · 0 评论 -
无线网络
点击打开链接 本题只要能正确建图(是否通信的关系),再通过并查集的知识就可以解题了,初始时每一台计算机都是损坏的。 1,根据坐标建立每对计算机的连通关系。 2,当操作为维修时,把本台计算机标记为好的,并将其与其可以通信的且完好的计算机进行合并操作,此时它们具有相同的根结点。 3,当操作为询问时,若两台计算机具有相同的根结点则可通信,否则不可通信 。 #includ原创 2014-02-17 14:41:08 · 785 阅读 · 0 评论 -
hdu1272_小希的迷宫
题目大意:原创 2014-07-22 20:54:22 · 466 阅读 · 0 评论 -
二分查找突破上下限,树状数组的三种应用。
result=lower_bound(nums.begin(),nums.end(),new_val); result=upper_bound(nums.begin(),nums.原创 2014-09-07 09:56:15 · 685 阅读 · 0 评论