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解题报告------------------------------------------------------------------------------------------- ...
随机推荐
- SSL/TLS协议概览
SSL/TLS协议是什么 计算机网络的OSI七层模型和TCP/IP四层模型想必大家都知道.其中SSL/TLS是一种介与于传输层(比如TCP/IP)和应用层(比如HTTP)的协议.它通过"握手 ...
- System.Data.SQLite未能加载文件或程序集
1.简直是作死帝呀.不需要修改dll的名字,否则就坐等悲剧吧 如果项目中有x86和x64的dll,可以建两个不同的文件夹分别存放,但是千万不要修改掉默认的dll的名字 System.Data.SQLi ...
- JavaScript之搜索框
啧啧啧,又到月末了,时间过的真的好快啊︿( ̄︶ ̄)︿现在没课上,天天宅在寝室就这么三件事:吃饭睡觉打豆豆.真感无所事事,无聊至极!突然好怀念那些上课的日子啊!至少不像现在,生活状态全部都搅乱了:以前可 ...
- UVA-10615 Rooks (二分图匹配)
题目大意:在一个nxn的方格中,有些位置有车,要给每一个车都涂上颜色,使得同一行和同一列的任意两个车颜色不同,求一种需要颜色种数最少的涂色方案. 题目分析:所需的最少颜色种数是显然就能得出的,假设最少 ...
- java 实现断点续传
请求头一:>>>>>>>>>>>>>>>>>>>>>>>> ...
- IOS-网络(JSON解析数据与XML解析数据)
一.JSON解析数据 // // VideoModel.h // IOS_0130_网络视频 // // Created by ma c on 16/1/30. // Copyright © 2016 ...
- jquery+html5制作超酷的圆盘时钟表
自己封装的一个用HTML5+jQuery写的时钟表 代码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...
- epoll 模型
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- SharePoint Development - Custom Field using Visual Studio 2010 based SharePoint 2010
博客地址 http://blog.csdn.net/foxdave 自定义列表的时候有时候需要自定义一些字段来更好地实现列表的功能,本文讲述自定义字段的一般步骤 打开Visual Studio,我们还 ...
- 判断设备(PC,安Android,iOS)
//判断是不是PC function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = new Array("An ...