USACO 2016 January Contest, Gold解题报告
1.Angry Cows
http://www.usaco.org/index.php?page=viewproblem2&cpid=597
dp题+vector数组运用
将从左向右与从右向左扫描结合。先从左到右DP,确定每个干草捆向右爆炸的最小半径,再从右到左,确定每个干草捆向左爆炸的最小半径。通过扫描每个干草捆,用这两个数字来确定我们应该设置初始引爆点的最佳位置。
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define INF 2000000000
int main()
{
//freopen("angry.in", "r", stdin);
//freopen("angry.out", "w", stdout);
int n;
scanf("%d",&n);
vector<int> a(n);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
a[i]*=;
}
sort(a.begin(), a.end());
a.resize(unique(a.begin(),a.end())-a.begin()); vector<int> DP[];
for(int it=;it<;it++)
{
int l=;
DP[it].resize(n,INF);
DP[it][]=-;
for(int i=;i<n;i++)
{
while(l+<i&&abs(a[i]-a[l+])>DP[it][l+]+)
{
l++;
}
DP[it][i]=min(abs(a[i]-a[l]),DP[it][l+]+);
}
reverse(a.begin(),a.end());
}
reverse(DP[].begin(),DP[].end()); int i=,j=n-,res=INF;
while(i<j)
{
res=min(res,max((a[j]-a[i])/,+max(DP[][i],DP[][j])));
if(DP[][i+]<DP[][j-])
i++;
else
j--;
}
printf("%d.%d\n",res/,(res%?:));
return ;
}
2.Radio Contact
这个问题实际上是一个隐藏的 动态时间扭曲问题,其中误差函数是FJ和Bessie之间的平方距离。
因此,可以通过动态编程解决问题。对于Farmer John和Bessie的每个可能的位置,我们可以通过尝试向前迈出FJ,向前走Bessie,向前移动他们来计算他们达到最终位置所需的最小能量。
#include <vector>
#include <cstring>
#include <cstdio>
#include <map>
#include <iostream>
using namespace std;
#define INF 0x7FFFFFFFFFFFFFFFLL
long long memo[][]; vector<pair<long long, long long> > F;
vector<pair<long long, long long> > B;
long long solve(int fi, int bi) {
/* The energy cost of the radio for this timestep. */
long long base = (F[fi].first - B[bi].first) * (F[fi].first - B[bi].first) +
(F[fi].second - B[bi].second) * (F[fi].second - B[bi].second);
if (fi + == F.size() && bi + == B.size()) {
return base;
}
long long& ref = memo[fi][bi];
if (ref != -) return ref;
/* Don't include the cost of the first timestep. */
if (fi == && bi == ) base = ;
ref = INF;
if (fi + < F.size()) {
/* Step FJ forward. */
ref = min(ref, base + solve(fi + , bi));
}
if (bi + < B.size()) {
/* Step Bessie forward. */
ref = min(ref, base + solve(fi, bi + ));
}
if (fi + < F.size() && bi + < B.size()) {
/* Step both forward. */
ref = min(ref, base + solve(fi + , bi + ));
}
return ref;
}
int main() {
//freopen("radio.in", "r", stdin);
//freopen("radio.out", "w", stdout);
map<char, int> dx, dy;
dx['E'] = ; dx['W'] = -;
dy['N'] = ; dy['S'] = -;
int N, M;
scanf("%d%d",&N,&M);
int fx, fy, bx, by;
scanf("%d%d%d%d",&fx,&fy,&bx,&by);
string SF, SB;
cin >> SF >> SB;
/* Compute FJ's path. */
F.push_back(make_pair(fx, fy));
for (int i = ; i < SF.size(); i++) {
fx += dx[SF[i]];
fy += dy[SF[i]];
F.push_back(make_pair(fx, fy));
}
/* Compute Bessie's path. */
B.push_back(make_pair(bx, by));
for (int i = ; i < SB.size(); i++) {
bx += dx[SB[i]];
by += dy[SB[i]];
B.push_back(make_pair(bx, by));
}
memset(memo, -, sizeof(memo));
cout << solve(, ) << endl;
return ;
}
USACO 2016 January Contest, Gold解题报告的更多相关文章
- USACO 2016 February Contest, Gold解题报告
1.Circular Barn http://www.usaco.org/index.php?page=viewproblem2&cpid=621 贪心 #include <cstd ...
- USACO 2016 US Open Contest, Gold解题报告
1.Splitting the Field http://usaco.org/index.php?page=viewproblem2&cpid=645 给二维坐标系中的n个点,求ans=用一个 ...
- USACO Section2.2 Preface Numbering 解题报告 【icedream61】
preface解题报告----------------------------------------------------------------------------------------- ...
- USACO Section2.1 Hamming Codes 解题报告 【icedream61】
hamming解题报告----------------------------------------------------------------------------------------- ...
- USACO Section2.1 Healthy Holsteins 解题报告 【icedream61】
holstein解题报告 --------------------------------------------------------------------------------------- ...
- USACO Section2.1 The Castle 解题报告
castle解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- USACO Section1.5 Prime Palindromes 解题报告
pprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- USACO Section2.3 Controlling Companies 解题报告 【icedream61】
concom解题报告------------------------------------------------------------------------------------------ ...
- USACO Section2.3 Money Systems 解题报告 【icedream61】
money解题报告------------------------------------------------------------------------------------------- ...
随机推荐
- 使用JavaScript下载csv文件
前端可以使用JavaScript在客户端下载包含页面数据的文件,这里以下载CSV格式文件为例,代码如下: function downloadData(data, filename, type) { v ...
- 一个轻量级分布式 RPC 框架 — NettyRpc
原文出处: 阿凡卢 1.背景 最近在搜索Netty和Zookeeper方面的文章时,看到了这篇文章<轻量级分布式 RPC 框架>,作者用Zookeeper.Netty和Spring写了一个 ...
- POJ 1034 The dog task(二分图匹配)
http://poj.org/problem?id=1034 题意: 猎人和狗一起出去,狗的速度是猎人的两倍,给出猎人的路径坐标,除了这些坐标外,地图上还有一些有趣的点,而我们的狗,就是要尽量去多的有 ...
- C++网络通信字节序问题
htonl(), ntohl(), htons(), ntohs() 函数 在C/C++写网络程序的时候,往往会遇到字节的网络顺序和主机顺序的问题.这是就可能用到htons(), ntohl(), n ...
- python assert 断言详细用法格式
使用assert断言是学习python一个非常好的习惯,python assert 断言句语格式及用法很简单.在没完善一个程序之前,我们不知道程序在哪里会出错,与其让它在运行最崩溃,不如在出现错误条件 ...
- tp5.1报错 页面错误!请稍后再试
修改框架中convention.php // 应用调试模式 'app_debug' => true, 修改app.php不一定有效.
- DWZ 框架详解
这是一个智障的框架,能别用就别用.
- 智课雅思词汇---二十七、形容词后缀-ant/-ent
智课雅思词汇---二十七.形容词后缀-ant/-ent 一.总结 一句话总结: ...的 后缀:-ant ①[形容词后缀] 大部分与-ance或-ancy,相对应,表示属于...的.具有...性质的 ...
- 微信小程序纯css制作圆形进度条所遇到的问题
wrapBox:最外层盒子,背景色为进度条的颜色 leftBox/rightBox:半宽等长 左/右浮动的盒子,背景色为灰色 roundMask:居中的盒子 用来遮盖leftBox和rightBox ...
- 310. Minimum Height Trees -- 找出无向图中以哪些节点为根,树的深度最小
For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...