上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 18 下一页
入门:http://blog.csdn.net/accry/article/details/6070626View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 50005struct point{ int x, y;}p[maxn], res[maxn<<1];int max(int a, int b){ return a > b ? a : b;}int xmult(point o, point a, Read More
posted @ 2012-10-09 23:11 To be an ACMan Views(219) Comments(0) Diggs(0)
题意:有n个(n<=1000)城市,告诉坐标(int),边的权值就是两点的距离,并且每个城市都有人居住,现在要修路n-1条路,使得每个城市都连通。现能让一条边可以不用任何花费。求 这条边的两端点的总人数/(包含这条边的最小生成树的总权值-这条边的权值)最大值。即(Wa+Wb)/(mst-w(a,b))最大。思路:先求该图的最小生成树,prim,O(n^2);方法一: 枚举边枚举最小生成树的每条边,去掉这条边,最小生成树变成了2个各自连通的树,假设为树A,B。分别找到树A,B中人口最多的两个点,这两个点连起来就是去掉这条边所取得的最大比例。用树形DP可以求这个最大比例。方法二: 枚举点在求 Read More
posted @ 2012-10-07 22:30 To be an ACMan Views(1113) Comments(0) Diggs(1)
题意:一个N个点的无向图,先生成一棵最小生成树,然后给你Q次询问,每次询问都是x,y,z的形式, 表示的意思是在原图中将x,y之间的边增大(一定是变大的)到z时,此时最小生成数的值是多少。最后求Q次询问最小生成树的平均值。 N<=3000 , Q<=10000思路:先求出该图的最小生成树,用prim(), O(n^2)。对于每次询问, 都是将a,b之间的边增加到c, 会出现 两种情况:1. 如果边权增加的那条边原先就不在最小生成树中,那么这时候的最小生成树的值不变2. 如果在原最小生成树中,那么这时候将增加的边从原最小生成树中去掉,这时候生成树就被分成了两个各自联通的部分,可以证明 Read More
posted @ 2012-10-07 12:00 To be an ACMan Views(3016) Comments(0) Diggs(1)
230A A. Dragons贪心水题View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct node{ int x, y;}p[1003];bool cmp(node a, node b){ return a.x < b.x || a.x == b.x && a.y > b.y;}int main(){ int i, j; int n, s; while( ~scanf("%d%d", Read More
posted @ 2012-10-05 21:56 To be an ACMan Views(371) Comments(0) Diggs(0)
哈哈View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 300003int vis[maxn];struct node{ int sex, fa, de, DNA; // sex性别,fa父亲节点, de是不是死了;}p[maxn];int a[maxn];int n, m, k;int find(int x){ return p[x].fa == x ? x : p[x].fa = find(p[x].fa);}vo Read More
posted @ 2012-10-05 20:45 To be an ACMan Views(268) Comments(0) Diggs(0)
树形DP, 2 个dfs。前几天觉得很难,现在可以说是水题了。View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 10003struct E{ int v, next, w;}edge[maxn<<1];int tot, head[maxn];int n, m;void init(){ tot = 0; memset(head, -1, sizeof(int)*(n+1));}void add(int s, Read More
posted @ 2012-10-05 18:54 To be an ACMan Views(282) Comments(0) Diggs(0)
4001 模拟题,仔细一点可以1A。我的代码有点长,但思路很清楚。View Code #include<stdio.h>#include<string.h>bool vis[11][11];int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};int d[8][2] = {2, 1, 2, -1, -2, 1, -2, -1, 1, 2, 1, -2, -1, 2, -1, -2};int dd[8][2] = {1, 0, 1, 0, -1, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, -1};int main(){ Read More
posted @ 2012-10-05 18:37 To be an ACMan Views(278) Comments(0) Diggs(0)
今天比赛因为不会双端队列卡了几道题,今天好好学学。双端队列一般保存2个值, 原数组的下标,数组中的值。View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 1000003int a[maxn];int n, m;struct Queue{ int pos, val;}que[maxn];void getmin(){ int i; int head = 0, tail = -1; for(i = 0; i < m-1 Read More
posted @ 2012-10-04 22:00 To be an ACMan Views(413) Comments(0) Diggs(0)
View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn = 20003;struct node{ int v, next, w;}edge[maxn<<1];int tot;int head[maxn];int n;void init(){ tot = 0; memset(head, -1, sizeof(int) * (n+1));}void add(int x, int y){ edge[tot].v Read More
posted @ 2012-09-21 12:05 To be an ACMan Views(196) Comments(0) Diggs(0)
代码1:View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 1003#define inf 1<<29struct node{ int v, next, w;}edge[maxn<<1];int head[maxn];int tot;int n, m;void init(){ tot = 0; memset(head, -1, sizeof(head));}void add(int x, int Read More
posted @ 2012-09-17 20:03 To be an ACMan Views(171) Comments(0) Diggs(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 18 下一页