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解题报告------------------------------------------------------------------------------------------- ...
随机推荐
- ubuntu16.04更新源的时候显示:由于没有公钥,无法验证下列签名: NO_PUBKEY 3D5919B448457EE0【学习笔记】
平台:ubuntu16.04 作者:庄泽彬(欢迎转载,请注明作者) 在添加了bazel的源之后执行sudo apt-get update出现下面的错误 echo "deb [arch=amd ...
- 采用注解方式实现security
采用注解方式使用security,首先我们需要用注解方式实现Spring MVC,新建一个Maven项目 本项目目录结构如下: 我们会发现在WEB-INF中没有web.xml文件,下面会介绍,采用j ...
- Codeforces Round #402 (Div. 2) A,B,C,D,E
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- ros 杀掉所有节点
rosnode kill -a 或者 rosnode kill --all
- c++ 字符串拷贝以及合并
#include<iostream> #include<string> using namespace std; class stringfun { ]; public: vo ...
- 使用 Redis
Redis(https://redis.io/),既不像 SQLite 以表的形式存储数据,也不像 MongoDB 允许以嵌套结构存储和查询,它是一种内存数据库结构,即将数据缓存在内存中.它将键—值( ...
- c++之to_string()函数
函数原型:string to_string (int val);string to_string (long val);string to_string (long long val);string ...
- Solaris11 Vsphere client tool 的鼠标问题
Mouse does not function on a Solaris 11 virtual machine (2040498) http://kb.vmware.com/selfservice/m ...
- 关于UDP很好的书籍和文章(整理、持续更新)
文章 告知你不为人知的 UDP:疑难杂症和使用(必看)
- Android 之低版本高版本实现沉浸式状态栏
沉浸式状态栏确切的说应该叫做透明状态栏.一般情况下,状态栏的底色都为黑色,而沉浸式状态栏则是把状态栏设置为透明或者半透明. 沉浸式状态栏是从android Kitkat(Android 4.4)开始出 ...