摘要: 题意:题目是中文的:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=16216分析:这道题目作为模板题其实值得多练习几次的。用树状数组来写:View Code 1 #include <stdio.h> 2 #include <iostream> 3 using namespace std; 4 #define DEBUG 5 const int MAXN = 50000 + 10; 6 int a[MAXN], n; 7 int lowbit(int x){return x&(-x);} 8 阅读全文
posted @ 2013-02-15 13:03 ChrisZZ 阅读(183) 评论(0) 推荐(0)
摘要: 题意:有n个任务,每个任务有三个参数r、d、w表示在[r,d]时间段内必须执行的工作量为w。处理器的工作速度可以变化,问执行中最大速度的最小值。分析:题目显然提示了要用二分。代码:View Code 1 #include <stdio.h> 2 #include <iostream> 3 #include <queue> 4 #include <vector> 5 #include <string.h> 6 #include <algorithm> 7 using namespace std; 8 const int MA 阅读全文
posted @ 2013-02-15 12:28 ChrisZZ 阅读(222) 评论(0) 推荐(0)
摘要: 题意:有n个垃圾,第i个垃圾坐标为(xi,yi)。有一个机器人按照编号从小到大哦捡起所有的垃圾并扔进垃圾桶,垃圾桶再远点。机器人手中垃圾总重量不能超过C,两点之间的距离为曼哈顿距离,求机器人行走的最短总路程分析:d[i]=min{d[j]+dist2origin(j+1)+dist(j+1,i)+dist2origin(i)|j<=i, w(j+1,i)<=c}里面可以写成函数f以简化计算代码:View Code 1 #include <stdio.h> 2 #include <algorithm> 3 using namespace std; 4 cons 阅读全文
posted @ 2013-02-15 11:42 ChrisZZ 阅读(160) 评论(0) 推荐(0)
摘要: 题意:给你一个n个点m条边的无向无环图,在尽量少的节点上放灯,使得所有边都被照亮,每盏灯将照亮以他为一个端点的所有边,在灯的总数最小的前提下,被两盏灯同时照亮的边数应当尽量大。分析:d(i,j)表示i的父节点放灯的状态为j(1表示放,0不放),以i为根的树的最小x值 x=Ma+c, a表示灯的总数, c表示只有一盏灯照亮此边, 题目转化成求x最小的问题, 把每个节点的x都求出来就好代码:View Code 1 #include <stdio.h> 2 #include <iostream> 3 #include <string.h> 4 #include & 阅读全文
posted @ 2013-02-15 10:49 ChrisZZ 阅读(318) 评论(0) 推荐(0)