01 2013 档案

摘要:hdu2489求一个图中的一颗子树,使得Sum(edge weight)/Sum(point weight)最小~数据量很小,暴力枚举,只是要注意精度,否则WA~dfs暴力枚举C(M,N)种情况。枚举出这M个点之后,Sum(point weight)固定,进行prime或者Kruskal使Sum(edge weight)求最小。View Code 1 #include 2 #include 3 #include 4 const int N=20; 5 const int inf=10000000; 6 int w[N];//用于记录每个点的权值 7 int ans[N];//用于记录答... 阅读全文
posted @ 2013-01-22 02:12 _sunshine 阅读(1008) 评论(0) 推荐(0)
摘要:感觉题意很扭曲。。。 不是求最大生成树!给一个图,求pseudoforest伪森林,要求每个连通分量最多可以有一个环。求能构成的最大值。 错误写法,求出最大生成树+最大的边 正确写法:在求最大生成树的思路的基础上每次判断一下环的问题~6 70 1 90 2 61 2 83 4 54 5 53 5 42 4 1这组数据如果是错误的方法就是34,选择(0,1),(1,2),(0,2),(2,4),(3,4),(4,5)正确的方法答案是37,选择(0,1),(1,2),(0,2),(3,4),(3,5),(4,5)View Code 1 #include <stdio.h> 2 #inc 阅读全文
posted @ 2013-01-22 02:05 _sunshine 阅读(481) 评论(0) 推荐(0)
摘要:poj3342View Code 1 #include <map> 2 #include <stdio.h> 3 #include <vector> 4 #include <string> 5 #include <iostream> 6 using namespace std; 7 const int N=205; 8 vector<int > V[N]; 9 map<string,int> M;10 string child,father;11 int dp[N][2];12 bool ok[N][2];13 阅读全文
posted @ 2013-01-19 01:36 _sunshine 阅读(1282) 评论(0) 推荐(0)
摘要:梳理了一下字典序:hdu1251裸 字典树View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 using namespace std; 5 struct trie{ 6 int cnt; 7 trie *next[26]; 8 }; 9 trie *root=new trie;10 void insert(char s[]){11 trie *p=root,*newnode;12 for(int i=0;s[i]!='\0';i++){13 if( 阅读全文
posted @ 2013-01-13 00:50 _sunshine 阅读(388) 评论(0) 推荐(0)
摘要:斐波那契史:① 求斐波那契数的后四位,矩阵乘法+快速幂。② 求斐波那契数的前四位(n<100000000),用到斐波那契数的公式(Hdu1568)。③ 求斐波那契数的前40位(n<100000)(Hdu4099)。④ 求斐波那契“串”的某一位(百度之星)……斐波那契数公式:①矩阵+快速幂②hdu1568 先看对数的性质 loga(b^c)=c*loga(b),loga(b*c)=loga(b)+loga(c); Eg: log10(10234432)= log10(1.0234432*10^7)= log10(1.0234432)+7; log10(1.0234432)就是log1 阅读全文
posted @ 2013-01-11 17:09 _sunshine 阅读(833) 评论(0) 推荐(1)
摘要:阶乘:View Code 1 import java.io.*; 2 import java.math.*; 3 public class BigInteger_factorial { 4 public static void main(String[] args) throws IOException{ 5 BigInteger s = BigInteger.valueOf(1); 6 for ( int i = 1;i<=500 ; i++){ 7 s = s.multiply(BigInteger.valueOf(i)... 阅读全文
posted @ 2013-01-11 15:52 _sunshine 阅读(451) 评论(0) 推荐(0)
摘要:Hdu1102 最小生成树 Prime算法(裸):首先有两个集合V{},边的集合E{}。先选择一个点,加入到V集合中,然后选择和这个V集合中的点相关连的边中最小的,将边的另一头的点加入到V集合中,该边加入到E集合中,V集合中的点是一个连通图,每次找和这个连通图相连的最短边,来更新。View Code 1 #include <stdio.h> 2 #include <string.h> 3 const int N=105; 4 const int inf=10000000; 5 int map[N][N],n; 6 int vis[N*(N+1)/2]; 7 int di 阅读全文
posted @ 2013-01-11 00:18 _sunshine 阅读(2536) 评论(0) 推荐(0)
摘要:A了4081顺便看了一下4082,感觉题目不好翻译,前几段都是没用的,意思就是给你n个点(0<n<18),数据范围很小…求这n个点能组成最多有多少个相似三角形。暴力枚举,但是要注意很多细节,首先:①去重点,在图论里总是会有去掉重边,可是计算几何里很少遇到去掉重点的问题,所以容易被遗忘,so……记住!!!!②判断三个点能否组成三角形,即是否共线。后台数据应该水了,一开始的代码,对于41 12 23 34 4这组数据输出1也AC了~View Code 1 #include <stdio.h> 2 #include <iostream> 3 #include &l 阅读全文
posted @ 2013-01-11 00:06 _sunshine 阅读(612) 评论(0) 推荐(0)
摘要:好久没写题了,水一水练习一下吧:hdu1272判断连通无环图: 判断成环的时候,只要判断输入边的两个点。 有一个共同的父节点,那么这两个点就成环。 判断连通的时候,只要判断根节点数为1即可。View Code 1 #include <stdio.h> 2 #define N 100010 3 int father[N]; 4 int mark[N]; 5 int find(int x){ 6 if(x!=father[x]) 7 father[x]=find(father[x]); 8 return father[x]; 9 }10 void merge... 阅读全文
posted @ 2013-01-08 14:53 _sunshine 阅读(824) 评论(0) 推荐(0)