上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 42 下一页
http://www.codeforces.com/problemset/problem/175/B标签是模拟题,我用两个数状数组做的,分别记录比当前数大的数的个数和小于等于当前数的个数有些细节都要处理好View Code //============================================================================// Name : w.cpp// Author : dd.cpp// Version :// Copyright : Your copyright notice// Descript... Read More
posted @ 2012-04-16 18:55 Because Of You Views(181) Comments(0) Diggs(0) Edit
题目要去掉一些的a[i],b[i]对,使得sigma(a[i])/sigma(b[i])最大,设100*sigma(a[i])/sigma(b[i])=r 最大,则100*sigma(a[i])-sigma(b[i])*r=0时r最大。因为这个式子是单调的,所以二分枚举答案,sigma(100*ai-mid*bi)==0时就为答案View Code #include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;struct node{ Read More
posted @ 2012-04-12 16:07 Because Of You Views(319) Comments(0) Diggs(0) Edit
这两题有一个共同的特点,都是从矩阵的左上角走到右下角,求最大能获得的权值不过poj 3422可以走k次poj 3422每个点走过一次后,这个点的权值就置零了,相当于经过一次后以后每次经过都没有费用了,所以每个点拆点后u->u' 建两条边一条边容量为1 费用为负的点权另一条边容量为INF,费用为0另外如果一个点能到另一个点,还是老方法u'->v,容量为INF,费用为0;最后要限制总流量为k,即建一个源点向1建一条容量为k,费用为0的边 n*n*2(最后一个点的出点) 向汇点连一条容量为k费用为0的边最后求一下S、T的最小费用流即可View Code #include& Read More
posted @ 2012-04-11 14:24 Because Of You Views(486) Comments(0) Diggs(0) Edit
求给那些边增加容量能增加总的流量显然,不是满流的边,增加也没有用,所以要增加容量的是那些满流的边。做法 求一次最大流 判断有几条边满流且能被源点和汇点搜到View Code #include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAX=100005;const int INF=1000000000;struct{ int v,c,next;}edge[1000000];int E,head[MAX];int gap[MAX],cur[MAX];int Read More
posted @ 2012-04-10 20:46 Because Of You Views(451) Comments(0) Diggs(0) Edit
代码很好懂,不解释了View Code #include<cstdio>#include<cstring>const int maxn = 50010;int c[maxn];void add(int x,int d){ for(;x<maxn;x+=x&-x) c[x]+=d;}int sum(int x){ int ans=0; for(;x>0;x-=x&-x) ans+=c[x]; return ans;}int bin(int val,int n){ int l=1,r=n+1,best=n+2; while(l<=r)... Read More
posted @ 2012-04-10 20:34 Because Of You Views(383) Comments(0) Diggs(0) Edit
枚举区间建图,好像也可以用多重匹配来做,不过不是很熟新建源点向每头牛连边牛向barns连边barns向汇点连边,边权为barns的容量,其实就是一个二分图最后求最大流就好了View Code #include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAX=100005;const int INF=1000000000;struct{ int v,c,next;}edge[1000000];int E,head[MAX];int gap[MAX],cur Read More
posted @ 2012-04-10 20:29 Because Of You Views(296) Comments(0) Diggs(0) Edit
给一幅图,若干个操作,每个操作时连接两个点,对于每个操作之后的图判断图中还有几条割边解法先求出最初的图中有几条割边bridge在求的过程中顺便建立一个方向,相当于变成有向图,如果发现某条边不是割边,就利用并查集将两个点合并,也可以不合并,但是速度上就相差很多了最后,一个联通块中的点就只以一个点为根了还有,如果s-t是割边,就标记一下t现在要连接两个点a,b在找他们的LCA的时候如果发现某条边是割边就bridge--因为需要一层层上去,遍历到从a,b到LCA的每条边,所以这个过程就直接暴力网上找了,不知还有没有什么更好的方法View Code #include<stdio.h>#in Read More
posted @ 2012-04-09 16:52 Because Of You Views(419) Comments(0) Diggs(0) Edit
已经做过一个类似的题目了,只是这道题目求的是最长的长度,那个题目求的是总的这样的序列的个数,都是用线段树或者树状数组来优化求和操作,使之降为log(n)View Code #include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn = 100010;int sum[maxn<<2];int num[maxn];int Read More
posted @ 2012-04-08 19:47 Because Of You Views(383) Comments(0) Diggs(0) Edit
要求去掉树中的一个点,使得分开的连通块中不存在总点数大于n/2的块直接dfs记录u节点下总共有几个儿子即可,水View Code #include<cstdio>#include<vector>#include<cstring>using namespace std;const int maxn = 10010;vector<int> edge[maxn];int sum[maxn],ans[maxn],n;void dfs(int u,int fa){ sum[u]=1; int i,j; bool flag=true; for(i=0;i&l Read More
posted @ 2012-04-08 19:44 Because Of You Views(224) Comments(0) Diggs(0) Edit
在某个点派出两个点去遍历所有的边,花费为边的权值,求最少的花费仔细分析后发现从哪个点出发是无所谓的如果从某个点出发要回到这个点,那么它走过的边肯定都被他遍历了两遍,画个图模拟一下就知道了但是如果不回来,则所走路径中有一条简单路径是可以只走一遍的,派出了两个点去遍历,也就是说有两条简单路径是可以直走一边的,我们要使这两条简单路径的总和尽可能的长,就转换为了树的最长路径问题了所以答案就为总的边权和的两倍减去树的最长路View Code #include<cstdio>#include<cstring>#include<vector>#include<que Read More
posted @ 2012-04-08 11:05 Because Of You Views(529) Comments(0) Diggs(0) Edit
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 42 下一页