摘要: 最小生成树,一道边有点多的题目,需要优化。DescriptionIn 2100, since the sea level rise, most of the cities disappear. Though some survived cities are still connected with others, but most of them become disconnected. The government wants to build some roads to connect all of these cities again, but they don’t want to ta 阅读全文
posted @ 2013-10-04 16:10 little_w 阅读(162) 评论(0) 推荐(0)
摘要: 第一道最小生成树问题 1 #include 2 #include 3 #include 4 #include 5 #define maxn 10000+100 6 using namespace std; 7 int r[maxn]; 8 int u[maxn]; 9 int v[maxn];10 int w[maxn];11 int p[maxn];12 int map[110][110];13 bool inmap[110][110];14 int cmp(const int i,const int j){return w[i]<w[j];}15 int find(int x)16 阅读全文
posted @ 2013-10-04 14:10 little_w 阅读(159) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2013-10-04 00:12 little_w 阅读(379) 评论(0) 推荐(0)
摘要: 1 #include 2 #define maxn 1005 3 #include 4 #include 5 #include 6 using namespace std; 7 8 9 int f[maxn],v[maxn],p[maxn],numcount;10 int F[maxn];11 bool vis[maxn*100];12 int n,w,k,a,b;13 14 int maxx(int a,int b)15 {16 if (a>=b) return a;else return b;17 }18 int find(int x){19 if(x==f[x]) ... 阅读全文
posted @ 2013-10-02 16:43 little_w 阅读(313) 评论(0) 推荐(0)
摘要: Description CX是要赶去上课,为了不迟到必须要以最短的路径到达教室,同时CX希望经过的路上能看到的学妹越多越好。现在把地图抽象成一个无向图,CX从1点出发,教室在N号点,告诉每个点上学妹的数量,每条边的长度。请你求出CX以最短路径赶到教室最多能看到多少学妹。Input 多组输入数据(最多20组),输入到文件结束。 每组数据第一行两个正整数N,M其中N代表点的个数(2 2 #include 3 #include 4 using namespace std; 5 typedef long long LL; 6 const int maxn=1000+5; 7 const long lo 阅读全文
posted @ 2013-10-02 16:21 little_w 阅读(256) 评论(0) 推荐(0)
摘要: Description zzy今天刚买了两个水瓢A和B,容量都是为1升,童心未泯的他打算用这个水瓢来玩游戏。 首先zzy准备了一个容量可看作无穷大的水缸,刚开始水缸是空的,然后用水瓢A往水缸里加水,用水瓢B把水缸里的水舀出去,当使用 水瓢B把水舀出去时水缸里必须要至少有1升的水。这样子使用N次水瓢A,也使用N次水瓢B,最后水缸会依旧空的。Input 输入有多个例子,直到文件结束。 每个例子仅含一个数N(0 2 #include 3 #include 4 #define mod 1000000007 5 #define maxn 10000+10 6 #define LL long long 7 阅读全文
posted @ 2013-10-02 16:13 little_w 阅读(795) 评论(0) 推荐(0)
摘要: 通过条件约束模拟后续全状态+暴力枚举决定变量==不超时{或者说,一边边求解一边判断正误以减少不必要的运算}统一代码风格 1 #include 2 #include 3 #include 4 using namespace std; 5 int f[4][2]={{0,-1},{0,1},{-1,0}}; 6 const int maxn=20; 7 int ans; 8 int addcha; 9 int cnt=0;10 int a[maxn][maxn];11 bool check(int n)12 {13 int aa[maxn][maxn];14 for(int i=0... 阅读全文
posted @ 2013-09-27 17:34 little_w 阅读(267) 评论(0) 推荐(0)
摘要: 思维题区间内点的移动(形象)保持原有顺序+重新排序后记录初始位置(容易思路不清)+想象等效模型 1 #include 2 #include 3 #include 4 #include 5 #define maxn 10000+10 6 using namespace std; 7 struct ant 8 { 9 int ord;//记录原始位置10 int f;//-1 : L , 1 : R11 int p;12 bool operator l)55 {56 printf("Fell o... 阅读全文
posted @ 2013-09-27 17:30 little_w 阅读(275) 评论(0) 推荐(0)
摘要: 枚举例子+归纳推理数轴处理曲线+固定点(将同一个点放在数轴首尾)#include#include#include#include#define eps 0.000001#define maxn 2020double a[maxn];double b[maxn];using namespace std;double abss(double n){ if (n>=0) return n;else return -n;}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { double k1=1/(n+0.0) 阅读全文
posted @ 2013-09-27 10:58 little_w 阅读(285) 评论(0) 推荐(0)
摘要: 初步解题原理:代数运算+单元素极值代数运算:xi表示第i个给i-1的数量,正负表示给或得c=(a1+a2+a3....an)/na1-x1+x2=c -->x2=x1-a1+ca2-x2+x3=c -->x3=x1-a1-a2+2ca3-x3+x4=c -->x4=x1-a1-a2-a3+3c......an-xn+x1=c -->xn=x1-a1-a2-a3....-a(n-1)+(n-1)cans=max{|x1|+|x2|+|x3|+....|xn|=|x1-0|+|x1-a1+c|+|x1-a1-a2+2c|.......|x1-a1-a2-a3....-a(n 阅读全文
posted @ 2013-09-26 23:19 little_w 阅读(222) 评论(0) 推荐(0)