uva 10034 Problem A: Freckles】的更多相关文章

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=975 最小生成树. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define maxn 1000 using namespace std;…
虽然是道普通的最小生成树题目,可还是中间出了不少问题,暴露的一个问题是不够细心,不够熟练.所以这篇博客就当记录一下bug吧. 代码一:kruskal #include<stdio.h> #include<math.h> #include<stdlib.h> #include<string.h> #define N 110 typedef struct { double x,y; } Point; Point point[N]; typedef struct…
题目大意:给出n个点的坐标(x,y),要求用线段将n个点连接起来,求最小的线段和. 最小生成树问题,用Kruskal算法进行求解,其中用到了并查集.将所有的点连接,构成一张图,对每一条边进行编号,两点间的距离作为权重. #include <cstdio> #include <algorithm> #include <cmath> #define square(x) (x)*(x) #define MAXN 10000 #define POINTN 100+10 usin…
题目上仅仅给的坐标,没有给出来边的长度,不管是prim算法还是kruskal算法我们都须要知道边的长度来操作. 这道题是浮点数,也没啥大的差别,处理一下就能够了. 有关这两个算法的介绍前面我已经写过了.就不在多写了 prim算法: <span style="font-family:Courier New;font-size:18px;">#include<iostream> #include<cstdio> #include<cstdlib&g…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=973 #include <cstdio> #include <cstring> #include <algorithm> #define ll long long using namespace std; ]; int n; ll dp[]; int mai…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=970 通过对每一个字符串,每一个位置进行枚举三个操作,然后二分查找操作后的字符串是否存在,dp记录. #include <cstdio> #include <cstring> #include <algorithm> #define N 25000 usin…
链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88171#problem/F 代码: #include <cstdio> #include <cstring> #include <algorithm> #define maxn 20000 using namespace std; int t; int n,k; int a[maxn]; bool flag; ]; int main() { scanf…
计算所有点之间的权值   然后就是最小生成树 #include<cstring> #include<string> #include<cstdio> #include<algorithm> #include<cmath> #include<map> #include<deque> using namespace std; struct point { double x,y; }; struct edge { int u,v…
题意:能否在一个整数序列的每相邻的两项之间添加一个加减号,使得最终结果能被一个给定整数K<=100整除. dp[i][j]表示第i个数取余k为j的布尔值. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 20000 using namespace std; int t; int n,k; int a[maxn]; bool flag; ]; int main() { sc…
紫皮书题: 题意:让你设计照明系统,给你n种灯泡,每种灯泡有所需电压,电源,每个灯泡的费用,以及每个灯泡所需的数量.每种灯泡所需的电源都是不同的,其中电压大的灯泡可以替换电压小的灯泡,要求求出最小费用 题解:每种电压灯泡要么全换,要么全不换,因为只换部分还要加额外的电源费用,并且换了部分之后费用更少,不如全换 先把灯泡按照电压从小到大排序,这样进行dp时,后面的电压大的如果比电压小的更优的话就可以替换了 设dp[j]为前j个最优了,则dp[i] = min{dp[i],dp[j] + (s[i]…