BZOJ4510——[Usaco2016 Jan]Radio Contact
来源:互联网 发布:时尚女装淘宝店铺推荐 编辑:程序博客网 时间:2024/05/21 02:21
1、题意:John和Bessie分别从(fx,fy)和(bx,by)出发,他们通过无线电通讯,单位时间消耗能量大小等于两人距离的平方(但他们同时在出发点的开始时刻的能量不算),为了节约能量,他们尽量靠在一起。单位时间内John和Bessie都可以选择走或不走。问最小使用能量大小。 转自huanghongxun
2、分析:把两个人走的步数作为状态,做一遍dp即可
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define M 1010#define LL long longinline int read(){ char ch = getchar(); int x = 0, f = 1; while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while('0' <= ch && ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); } return x * f;}struct Node{ int x, y;} f[M], b[M];char str[M];int dx[] = {0, 1, 0, -1};int dy[] = {1, 0, -1, 0};LL dp[M][M];inline LL sqr(int x){ return (LL)x * (LL)x;}inline int get_direction(char ch){ if(ch == 'N') return 0; if(ch == 'E') return 1; if(ch == 'S') return 2; return 3;} inline LL dis(Node x, Node y){ return sqr(x.x - y.x) + sqr(x.y - y.y);}int main(){ //freopen("0input.in", "r", stdin); int n = read(), m = read(); f[0].x = read(), f[0].y = read(); b[0].x = read(), b[0].y = read(); scanf("%s", str); int x = f[0].x, y = f[0].y; for(int i = 0; i < n; i ++){ f[i + 1].x = (x += dx[get_direction(str[i])]); f[i + 1].y = (y += dy[get_direction(str[i])]); } scanf("%s", str); x = b[0].x, y = b[0].y; for(int i = 0; i < m; i ++){ b[i + 1].x = (x += dx[get_direction(str[i])]); b[i + 1].y = (y += dy[get_direction(str[i])]); } memset(dp, 0x7f, sizeof(dp)); dp[0][0] = 0; for(int i = 0; i <= n; i ++){ for(int j = 0; j <= m; j ++){ dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + dis(f[i + 1], b[j])); dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + dis(f[i], b[j + 1])); dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + dis(f[i + 1], b[j + 1])); } } printf("%lld\n", dp[n][m]); return 0;}
0 0
- BZOJ4510——[Usaco2016 Jan]Radio Contact
- 【BZOJ4510】[Usaco2016 Jan]Radio Contact【DP】
- BZOJ 4510: [Usaco2016 Jan]Radio Contact dp
- BZOJ4525——[Usaco2016 Jan]Angry Cows
- bzoj4509【Usaco2016 Jan】Angry Cows
- bzoj4512: [Usaco2016 Jan] Build Gates
- USACO2016 Jan Bronze 2:Angry Cows
- USACO2016 Jan Bronze 3:Mowing the Field
- USACO2016 Jan Bronze 1:Promotion Counting
- USACO2016 Jan Bronze 4:Promotion Counting
- BZOJ 4525: [Usaco2016 Jan]Angry Cows 二分
- [bzoj4511][Usaco2016 Jan]Subsequences Summing to Sevens
- BZOJ 4510 Radio Contact
- BZOJ4411——[Usaco2016 Feb]Load balancing
- contact——toolofna
- 【BZOJ】4511: [Usaco2016 Jan]Subsequences Summing to Sevens
- BZOJ 4511: [Usaco2016 Jan]Subsequences Summing to Sevens
- bzoj 4511: [Usaco2016 Jan]Subsequences Summing to Sevens
- 国民革命军新一军知识青年从军歌
- NavigationView的基本使用
- 在 SOHU BLOG 开一个空间
- 杂七杂八 洋酒不习惯
- Spring整合redis的错误
- BZOJ4510——[Usaco2016 Jan]Radio Contact
- 悼念贝娜齐尔·布托
- User Defined Hadoop DataType
- 看不下去的《集结号》
- JS(JavaScript) 与 JSP(Java server page) 的区别
- 说说大清国的铁帽子王
- java.lang.reflect.InvocationTargetException 异常(Json转化时抛出)
- 吉林大学唯唐敖庆一人尔
- Filter的生命周期