上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 42 下一页
matrix[i][j]表示第i个水桶要倒matrox[i][j](比例)的水到第j个水桶,由于倒的次数非常多,所以可以用矩阵连乘来优化,求出倒了m次后的结果如样例可得矩阵0 10.5 0.5这个矩阵连乘2次0.5 0.50.25 0.75就是倒2次水后的结果然后呢统计即可View Code #include <cstdio>#include <cstring>#define ld __int64const int maxn = 22;int n,m;struct Matrix{ double a[maxn][maxn]; void init() { for(... Read More
posted @ 2012-03-02 16:14 Because Of You Views(422) Comments(0) Diggs(0) Edit
答案是:n+1+逆序数的数量因为如果n条线段都不相交,一定可以划分成n+1个区域,然后就画图YY一下View Code #include <cstdio> #include <algorithm>using namespace std;int left[50003], right[50003]; int cnt; struct node { int y1,y2;}p[30010];int cmp(node a,node b){ return a.y1<b.y1;}void merge(int a[], int l, int m, int r) { int i, j Read More
posted @ 2012-03-01 14:50 Because Of You Views(366) Comments(0) Diggs(0) Edit
hdu 3577 也是这样的题目典型的线段树区间覆盖,懒惰标记要多记录两个域,一个是区间内最大值所在的最左的位置,另一个是最右的位置View Code //zoj 3573#include<stdio.h>#include<cstring>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define mid (l+r)>>1const int maxn = 100010;int sum[maxn<<2];//子树区间内最大的覆盖次数int col[maxn<<2 Read More
posted @ 2012-03-01 14:10 Because Of You Views(406) Comments(0) Diggs(0) Edit
类型:无源汇可行流参考自()http://hi.baidu.com/evelynhe/blog/item/f1c5ba2fcbe674271e3089ad.html每条边的容量满足一定的限制,即有一个上限值,也有一个下限值上界用ci表示,下界用bi表示。下界是必须流满的,那么对于每一条边,去掉下界后,其自由流为ci– bi。主要思想:每一个点流进来的流=流出去的流对于每一个点i,令Mi= sum(i点所有流进来的下界流)– sum(i点所有流出去的下界流)如果Mi大于0,代表此点必须还要流出去Mi的自由流,那么我们从源点连一条Mi的边到该点。如果Mi小于0,代表此点必须还要流进来Mi的自由流, Read More
posted @ 2012-02-29 16:24 Because Of You Views(1021) Comments(0) Diggs(0) Edit
A了3个多串匹配的水题模板View Code #include<cstdio>#include<cstring>#include<queue>using namespace std;const int maxn = 1000010;struct Tire{ int flag,fail; int next[26]; void init() { flag=0;fail=-1; for(int i=0;i<26;i++) next[i]=0; }}tb[maxn];int tot;char str[maxn];void insert(char... Read More
posted @ 2012-02-28 18:20 Because Of You Views(332) Comments(0) Diggs(0) Edit
求的最大流后依次从源点和汇点开始dfs 如果能搜到的点数之和等于总的点数,最小割唯一,否则不唯一View Code #include<stdio.h>#include<string.h>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 pre[MAX],dis[MAX];void add_edge(int s,int t,int c,int cc){/*加边的时候同时加两条, Read More
posted @ 2012-02-27 16:28 Because Of You Views(352) Comments(0) Diggs(0) Edit
由行向列建图,增加两个源汇点,源点向行连边,容量为该行的花费,列向汇点连边,容量为该列的代价,一个伞兵的位置为x,y,则从x行向y列连一天容量为无穷大的边,最后求最大流(最小割的容量)即可View Code #include<cstdio>#include<cstring>#include<cmath>const int MAX=100005;const double INF=1000000000;struct{ int v,next; double c;}edge[1000000];int E,head[MAX];int gap[MAX],cur[MAX] Read More
posted @ 2012-02-27 15:50 Because Of You Views(236) Comments(0) Diggs(0) Edit
其实这道题目的难点不在容斥原理,在于大数越界、取余等等的细节首先求出通项公式为n(2n+1)(n+1)(3n² +3n-1)/30求(a/b)%mod有两种方法1、原式=a%(b*n)/b2、原式=a*b^(phi(mod)-1)%mod;(其中b与mod互质)本题中,由于mod过大,采用第一种方法会出错,于是用了第二种方法。容斥过程中比如要加上2的四次,4的四次,6的四次。。。。可把2的四次提取出来,另外一项就变成了四次方和了View Code #include<cstdio>#include<cstring>#include<cmath>#in Read More
posted @ 2012-02-26 19:21 Because Of You Views(822) Comments(0) Diggs(0) Edit
先把中缀表达式转换成表达式树保存下来,再用后缀表达式计算,过程比较繁琐所幸最后还是封装成了一个类写的很挫的View Code #include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>#include<iostream>using namespace std;int flag;bool pre;class calc{ enum Type { DATA,ADD,SUB,MULTI,DIV,OPAREN,CPAREN,EOL}; struct node { T Read More
posted @ 2012-02-25 11:18 Because Of You Views(303) Comments(0) Diggs(0) Edit
View Code #include <cstdio> int left[250003], right[250003]; __int64 count; void merge(int a[], int l, int m, int r) { int i, j, k, n1, n2; n1 = m - l + 1; n2 = r - m; for (i = 0; i < n1; i++) left[i] = a[l+i]; for (i = 0; i < n2; i++) right[i] = ... Read More
posted @ 2012-02-23 20:35 Because Of You Views(224) Comments(0) Diggs(0) Edit
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 42 下一页