上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 21 下一页
摘要: http://poj.org/problem?id=3159思路:用O(V+ElogV)的Dijkstra算法求1到n的最短路。即用优先队列优化Dijkstra算法。 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=300005; 6 const int maxm=150002; 7 struct node 8 { 9 int u,v,w;10 int next;11 } edge[maxm];12 struct pot13 {14 int v,w;15 p... 阅读全文
posted @ 2013-11-22 19:30 N_ll 阅读(246) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1025题意:富人路与穷人路都分别有从1到n的n个点,现在要在富人点与穷人点之间修路,但是要求路不能交叉,问最多能修多少条。思路:穷人路是按顺序给的,故求富人路的最长上升子序列即可。由于数据范围太大,应该用O(nlogn)的算法求LIS。 1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=500005; 6 int r[N],d[N]; 7 int main() 8 { 9 int n,cnt = 0,x,y... 阅读全文
posted @ 2013-11-22 16:24 N_ll 阅读(219) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1429 1 #include 2 #include 3 #include 4 using namespace std; 5 struct node 6 { 7 int x,y; 8 int state; 9 int step; 10 } s,t; 11 int Time,n,m; 12 int s_x,s_y,e_x,e_y; 13 char a[32][32]; 14 int vis[32][32][1026];//标记状态 15 int dir[4][2] ... 阅读全文
posted @ 2013-11-22 09:41 N_ll 阅读(180) 评论(0) 推荐(0)
摘要: 贪心算法和动态规划贪心算法1.贪心选择性质 所谓贪心选择性质是指所求问题的整体最优解可以通过一系列局部最优的选择,即贪心选择来达到。这是贪心算法可行的第一个基本要素,也是贪心算法与动态规划算法的主要区别。在动态规划算法中,每步所作的选择往往依赖于相关子问题的解。因而只有在解出相关子问题后,才能作出选择。而在贪心算法中,仅在当前状态下作出最好选择,即局部最优选择。然后再去解作出这个选择后产生的相应的子问题。贪心算法所作的贪心选择可以依赖于以往所作过的选择,但决不依赖于将来所作的选择,也不依赖于子问题的解。正是由于这种差别,动态规划算法通常以自底向上的方式解各子问题,而贪心算法则通常以自顶向下的方 阅读全文
posted @ 2013-11-13 20:57 N_ll 阅读(425) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1506题意:给出n个矩形的高度,每个矩形的宽都为1,求相邻的矩形能组合成的最大的矩形的面积。思路:求出比第i个矩形大的最左边的矩形的位置 l[i], 及比第i个矩形大的最右边的矩形的位置 r[i], 则第i个矩形的面积 s = (r[i]-l[i]+1)*hign[i]。 如果第i-1个矩形比第i个矩形大,则 l[i] 必定在 l[i-1]的 左边,同理,r[i]必定在 r[i+1]的右边。 1 #include 2 #include 3 #include 4 #define LL __int64 5 ... 阅读全文
posted @ 2013-11-13 16:27 N_ll 阅读(178) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1584题意:判断所给的点能不能形成凸包,并判断所给的圆是否在凸包内。改了好几天的一个题,今天才发现是输入顺序弄错了,办过的最脑残的事情。。sad 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int N=1002; 8 const double eps=1e-8; 9 double pi=acos(-1.0); 10 int n; 11 struct point 12 { 13 d... 阅读全文
posted @ 2013-11-09 13:32 N_ll 阅读(268) 评论(0) 推荐(0)
摘要: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=35800#problem/D 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 const int INF=1p[N]; 14 mapname_id; 15 mappos_id; 16 int value[N],link[N][N],ans; 17 18 int res() 19 { 20 i... 阅读全文
posted @ 2013-11-06 11:21 N_ll 阅读(187) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2187题意:求凸包上最远点距离的平方思路:开始用旋转卡壳求的最远点,WA,改了好久。。后来又改成枚举凸包上的点。。AC了。。 1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=50005; 6 int n; 7 struct Point 8 { 9 int x,y;10 Point(int x = 0,int y = 0):x(x),y(y) {}11 bool friend operator 1&&Cross(ch[m... 阅读全文
posted @ 2013-10-31 21:42 N_ll 阅读(358) 评论(2) 推荐(0)
摘要: http://poj.org/problem?id=1113题意:给出一些点的坐标,和一个半径r,求出这些点围成的凸包的周长再加上一个半径为r的圆的周长。 1 #include 2 #include 3 #include 4 const double PI=acos(-1.0); 5 const int N=1002; 6 using namespace std; 7 8 struct Point 9 {10 double x;11 double y;12 Point (double x = 0,double y = 0):x(x),y(y) {}13 ... 阅读全文
posted @ 2013-10-25 21:06 N_ll 阅读(278) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=3258题意理解起来很别扭,觉得自己描述的会让人搞不懂,建议去搜一下正规的解释。 1 #include 2 #include 3 #include 4 #include 5 const int N=100010; 6 using namespace std; 7 int main() 8 { 9 int L,n,m,d[N];10 scanf("%d %d %d",&L,&n,&m);11 d[0] = 0;//第一块石头的距离12 d[n+1] = L;//最后一块石头的距离13 for (i.. 阅读全文
posted @ 2013-10-23 21:01 N_ll 阅读(121) 评论(0) 推荐(0)
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 21 下一页