上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 42 下一页
简单题,读懂题意就好,由于dp和ep都是叶子节点,这棵树又是满二叉树,所以,可以直接往上找到最近公共祖先,然后加减运算一下就好了View Code #include<cstdio>#include<cstdlib>int max(int a,int b){ return a>b?a:b;}int main(){ int d,e,f,dp,ep,h; while(scanf("%d%d%d%d%d%d",&d,&e,&f,&dp,&ep,&h)!=EOF) { int dep=0; dp--;ep- Read More
posted @ 2011-12-23 13:53 Because Of You Views(329) Comments(0) Diggs(0) Edit
分成左右两个部分a1,a2和-a3,-a4,-a5View Code import java.io.*;import java.util.*;import java.math.*;public class Main{ public static void main(String[] args){ Scanner cin = new Scanner (System.in); int a1=cin.nextInt(); int a2=cin.nextInt(); int a3=cin.nextInt(); int a4=c... Read More
posted @ 2011-12-22 12:24 Because Of You Views(213) Comments(0) Diggs(0) Edit
题意,一个图,要将每条边恰好遍历两遍,而且要以不同的方向,还要回到原点。直接dfs一下就好了,vis[]标记边是否访问,不会的仔细模拟一遍哪个dfs就好了View Code #include<stdio.h>#include<string.h>struct Edge{ int v,next;}edge[111111];int head[11111];int n,m,tot;bool vis[111111];void add(int s,int t){ edge[tot].v=t; edge[tot].next=head[s]; head[s]=tot++;}void d Read More
posted @ 2011-12-22 11:18 Because Of You Views(215) Comments(0) Diggs(0) Edit
View Code import java.io.*;import java.util.*;import java.math.*;public class Main{ public static BigInteger fun(BigInteger a,BigInteger b,BigInteger c) { int n=2; BigInteger x=a,y=b,z=c; BigInteger ans; while(n<99) { n++; ans=BigInteger... Read More
posted @ 2011-12-22 10:25 Because Of You Views(217) Comments(0) Diggs(0) Edit
毫无疑问,最远点对肯定都在土包上所以可以先求凸包再两两枚举土包上的点这时候的点会比原先情况下少很多凸包用的是快速土包法这种方法在有些时候会退化成N^2英文例子:http://www.cs.princeton.edu/courses/archive/spr10/cos226/demo/ah/QuickHull.html大牛博客:http://www.cnblogs.com/Booble/archive/2011/03/10/1980089.htmlView Code //快速土包算法,递归#include <iostream>#include <math.h>#defin Read More
posted @ 2011-12-21 18:00 Because Of You Views(956) Comments(0) Diggs(0) Edit
基本功不够扎实 dubug 了好久View Code #include<cstdio>#include<cstring>int h[50][50];int a[50];int sum[50];int ans[50];int re[50];int n,m;int tot;bool goal;void dfs(int dep,int p){ int i,j; goal=true; for(i=1;i<=n;i++) if(sum[i]<a[i]) goal=false; if(goal && dep>tot) { ... Read More
posted @ 2011-12-21 11:17 Because Of You Views(282) Comments(0) Diggs(0) Edit
风格:notonlysuccess感觉刚开始就看notonlysuccess可能不太好,建议还是先研究一下网上的其他风格,搞透之后在比较一下,这样就能充分理解并加以运用了下面就从一些题来初识一下线段树hdu 1394 Minimum Inversion Number求逆序数的功能View Code #include<cstdio>#include<algorithm>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn = 5010;i Read More
posted @ 2011-12-21 08:27 Because Of You Views(1255) Comments(0) Diggs(1) Edit
分析:典型dp,状态转移方程dp[i][j]=dp[i-1][j-1]+dp[i][j-i];dp[i][j]表示i辆卡车装j台电脑的方法数。例如:8台电脑3台车卡车1卡车2卡车3dp[3,8]=dp[2,7]+dp[3,5]第一类611卡车3只放一台电脑,运法总数相当于2台卡车运7台电脑dp[2,7]。521431第二类422每台车有一台以上电脑,运法总数相当于3台车运5台电脑dp[3,5]332c++View Code #include<stdio.h>#include<string.h>__int64 dp[210][210];void init(){ int i Read More
posted @ 2011-12-19 14:42 Because Of You Views(472) Comments(0) Diggs(0) Edit
推荐java学习室http://www.java3z.com/cwbwebhome/旧题新做,练java用View Code import java.io.*;import java.util.*;import java.math.*;public class Main{ static int n,m,match[]=new int[210]; static boolean mat[][]=new boolean [210][210],v[]=new boolean[210]; static boolean dfs(int pre) { int i; ... Read More
posted @ 2011-12-19 14:04 Because Of You Views(307) Comments(0) Diggs(0) Edit
http://www.cnblogs.com/zjh10/articles/2032294.html这个题目是说 每个点有权值,有些点的得到需要先得到某点,问你选M个点能够得到的最大值很明显是有依赖的背包,而且应该是有依赖中有依赖(虽然我觉得题目并没有很明确地说)~这样的话 我们就构建dp[i][j],i为i号点,j为它选了里面的几个点。。。。。这样的话 我们就发现其实是个树,点的值取决于子点的选法。方程dp[k][j]=max(dp[k][j],dp[k][j-kk]+dp[t[k][i]][kk])表示在第i个k的子点中选kk个点加上目前k号点选j-kk个点与直接在k号点选j个点谁更优。。 Read More
posted @ 2011-12-19 13:34 Because Of You Views(2474) Comments(7) Diggs(1) Edit
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 42 下一页