07 2011 档案
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1203一个简单的0-1背包问题 特别之处就是算的是概率 是乘法的操作 所以把原来的加法用函数代替为相应的操作即可#include<iostream>#include<stdio.h>#include<cstring>using namespace std;int m;double dp[10001];double f(double x,double y){ return 1-(1-x)*(1-y);}void ZeroOnePack(int cost, double wei
阅读全文
摘要:微软过桥问题的图论解法 微软的过桥问题说的是4个人在晚上过一座小桥,过桥时必须要用到手电筒,只有一枚手电筒,每次最多只可以有两人通过, 4个人的过桥速度分别为1分钟、2分钟、5分钟、10分钟,试问最少需要多长时间4人才可以全部通过小桥?这个问题如果用图论来建模的话,就可以以4个人在桥两端的状态来作为节点来构造一个有向图,如下图所示,以已经过桥了的人的状态作为图的节点,初始时没有人过桥,所以以空表示,第一轮有两个人过桥,有6种可能的组合,(1,2)(1,5)(1,10)(2,5)(2,10)(5,10),从空的状态转换到这些状态的需要的时间分别为2,5,10,5,10,10分钟,时间就作为有向边
阅读全文
摘要:http://poj.org/problem?id=1328题目大意:在直角坐标系中有N个点 用半径为R 圆心在X轴上的圆去覆盖这些点 求最小需要的圆的个数解题思路:如果有点的走坐标大于R那么必然有点无法覆盖 输出-1对所有的点求能覆盖这个点的圆的圆心坐标在X轴上的左右极限 题目就被转化为求在N个区间中 用最少的点使得每个区间内最少有一个点首先 对所有区间的按照左端点进行升序排列 如果一个区间的左端点大于当前的点 那么新建一个点在这个区间的右端点如果一个区间的左端点小于等于当前的点 那么当前的点变成这个区间的右端点和当前点中比较小的点#include<stdio.h>#includ
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1789Doing Homework againTime Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1600Accepted Submission(s): 945Problem DescriptionIgnatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homew
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3177Crixalis's EquipmentTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 594Accepted Submission(s): 229Problem DescriptionCrixalis - Sand King used to be a giant scorpion(蝎子) in the deserts of Kalimdor.
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3279AntsTime Limit:2 Seconds Memory Limit:32768 KBecho is a curious and clever girl, and she is addicted to the ants recently.She knows that the ants are divided into many levels depends on ability, also, she finds the number of each level
阅读全文
摘要:有多个发电站 中转站 和用户 多源 多汇的最大流问题 建立源点 和 汇点 将发电站连到源点上将用户连到汇点上求图的最大流#include<iostream>#include<queue>#include<stdio.h>#include<cstring>using namespace std;#define INF 0x7fffffffint cap[503][503],a[503],p[503];int ek(int s,int t,int n){ int f=0; while(1) { queue<int> q; memset(a
阅读全文
摘要:#include<iostream>#include<map>#include<string>#include<stdio.h>#include<cstring>#include<queue>using namespace std;const int INF=0x7fffffff;int cap[503][503],a[503],flow[503][503],p[503];int ek(int s,int t,int n){ memset(flow,0,sizeof(flow)); int f=0; while(1) {
阅读全文
摘要:#include<iostream>#include<stdio.h>#include<queue>#include<cstring>using namespace std;#define INF 1000000000#define MAXN 1000int a[MAXN];int cap[MAXN][MAXN],flow[MAXN][MAXN],p[MAXN];queue<int>q;int main(){ int n,m; while(cin>>n>>m) { memset(cap,0,sizeof(cap
阅读全文
摘要:DescriptionHere’s a simple graph problem: Find the shortest pathfrom the top-middle vertex to the bottom-middle vertexin a given tri-graph. A tri-graph is an acyclic graph of(N ≥ 2) rows and exactly 3 columns. Unlike regulargraphs, the costs in a tri-graph are associated with thevertices rather than
阅读全文
摘要:#include<iostream>#include<stdio.h>#include<string>using namespace std;#define MAX 50000int sum1;struct Node{ int left,right,sum;}stu[3*MAX];void CreateTree(int ii,int a,int b)//建树的结果只是形成一个空箱子 里面什么东西都没有 只有区间的两端{ stu[ii].left = a; stu[ii].right = b; stu[ii].sum = 0; if(a == b) { ret
阅读全文
摘要:#include<iostream>#include<stdio.h>using namespace std;#define MAX 200001int big;struct Node{ int r,l,max;}s[MAX*3];int Max(int a,int b){ return a>b?a:b;}void creat(int i,int a,int b){ s[i].l=a; s[i].r=b; s[i].max=0; if(a==b) return; else { int mid=(a+b)>>1; creat(i*2,a,mid); cr
阅读全文
摘要:strcmp: 用于比较两个字符串,原型如下:int strcmp ( char const *s1, char const *s2);如果s1小于s2,strcmp函数返回一个小于零的值。如果s1大于s2,函数返回一个大于零的值。如果两个字符串相等,函数就返回零。警告:初学者常常会编写下面这样的表达式 if ( strcmp (a, b)) 他以为如果两个字符串相等,它的结果将是真。但是,这个结果将正好相反,因为在两个字符串相等的情况下返回值是零(假)。 把这个返回值当作布尔值进行测试是一种坏风格,因为它具有三个截然不同的结果:小于、等于和大于。 所以更好的方法是把这个返回值与零进行比较。当
阅读全文
摘要:/*两次单源最短路径 输入的时候一次正向记录路径一次反向记录路径 */#include<iostream>#include<cstring>#include<stdio.h>#include<algorithm>using namespace std;#define INF 99999int t[1001][1001],dd[1001][1001];int v[1001],dp[1001],dp2[1001];int n,w;void f(int d[][1001]){ memset(v,0,sizeof(v)); for(int i=1;i&l
阅读全文
摘要:#include<iostream>#include<cstring>#include<string>#include<map>#include<stdio.h>using namespace std;int main(){ map<string,string> d; char str1[12],str2[12],str[30]; while(gets(str)) { if(strlen(str)==0) break; sscanf(str,"%s %s",str1,str2); d[str2]=str
阅读全文

浙公网安备 33010602011771号