HDU 4584(2013杭州邀请赛I题-水)
来源:互联网 发布:js中NaN 编辑:程序博客网 时间:2024/05/22 16:40
http://acm.hdu.edu.cn/showproblem.php?pid=4584
题意:找出一条HC路线,要求HC的曼哈顿距离尽量小,H的x坐标尽量小,y坐标尽量小,C的x坐标尽量小,y坐标尽量小。
思路:直接在每条边去找出答案即可,我是直接排个序就找出答案。
代码:
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;const int N = 1605;struct Point { int x, y; Point(){} Point(int _x, int _y) {x = _x; y = _y; }} c[N], h[N];struct Edge { int dis; Point a, b; Edge() {} Edge(Point _a, Point _b) {a = _a; b = _b;dis = abs(a.x - b.x) + abs(a.y - b.y); }} e[666666];int n, m, cn, hn, en;char str[45];bool cmp(Edge a, Edge b) { if (a.dis != b.dis)return a.dis < b.dis; if (a.a.x != b.a.x)return a.a.x < b.a.x; if (a.a.y != b.a.y)return a.a.y < b.a.y; if (a.b.x != b.b.x)return a.b.x < b.b.x; return a.b.y < b.b.y;}int main() { while (~scanf("%d%d", &n, &m) && n + m) {cn = hn = en = 0;for (int i = 0; i < n; i++) { scanf("%s", str); for (int j = 0; j < m; j++) {if (str[j] == 'C') c[cn++] = Point(i, j);else if (str[j] == 'H') h[hn++] = Point(i, j); }}for (int i = 0; i < hn; i++) { for (int j = 0; j < cn; j++) {e[en++] = Edge(h[i], c[j]); }}sort(e, e + en, cmp);printf("%d %d %d %d\n", e[0].a.x, e[0].a.y, e[0].b.x, e[0].b.y); } return 0;}
1 0
- HDU 4584(2013杭州邀请赛I题-水)
- HDU 4585 Shaolin(2013杭州邀请赛J题-二分)
- hdu 4576(2013杭州邀请赛)
- HDOJ 4584/2013年杭州邀请赛I题 Building bridges 水题
- HDU 4578 Transformation(2013 杭州赛区全国邀请赛 1003)
- hdu4584 (2013杭州邀请赛)
- hdu4858 (2013杭州邀请赛)
- HDU 4584Shaolin2012杭州全国邀请赛J题(暴力或set 两种做法)
- HDU 4576 (2013杭州邀请赛J题-dp滚动数组优化)
- hdu 4485 2013杭州邀请赛 Building bridges
- hdu 4585 2013杭州邀请赛 Shaolin
- HDU 4585 Shaolin 2013杭州邀请赛
- hdu 4576 Robot 杭州邀请赛第一题
- 小记2013杭州邀请赛
- 2013 杭州赛区邀请赛
- HDU 4578 Transformation 解题报告(线段树,2013杭州邀请赛)
- HDU 4576(2013杭州邀请赛) 滚动数组+模拟过程
- hdu 4578 Transformation 2013ACM-ICPC杭州赛区全国邀请赛
- mulan使用
- C++ UNICODE 文件读写相关(转载)
- oracle 创建用户
- TCP速率与窗口,带宽,RTT之间的关系
- 第四周项目二-三角形类2
- HDU 4584(2013杭州邀请赛I题-水)
- POJ 1456
- 学习IOS开发的第11天
- 两个关于a,b的面试题
- 黑马程序员--高新技术<一>eclipse开发工具及相关知识加强
- System.gc
- 测井曲线绘图显示算法总结——双缓冲技术
- php 二维码生成
- Struts2.x+Spring3.x+Hibernate4.x 整合(五)Struts 升级到 2.3.15.3