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解题报告------------------------------------------------------------------------------------------- ...
随机推荐
- js模拟类的创建以及继承的四部曲
<script> 1)创建父类 function Person(){ } Person.prototype.age = 18;//给父类添加属性 var p1 = new Person() ...
- JVM的异常处理
异常处理的两大组成要素:抛出异常和捕获异常.这两大要素共同实现程序控制流的非正常转移. 抛出异常分为:显式和隐式两种. 显式抛异常的主题是应用程序,它指的是在程序中使用 “throw” 关键字.手动 ...
- python 获取二维数组所有元素
import itertools original_list = [[,,],[,,], [], [,,]] new_merged_list = list(itertools.chain(*origi ...
- 【Demo】CSS3 动画文字
效果图: 完整代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...
- 微信小程序封装storage(含错误处理)
这次给你们安利的是微信小程序封装storage,先说下微信官方的 wx.getStorage({ key:"", success: function (res) { }, fail ...
- mysql插入中文数据报错 java.sql.SQLException: Incorrect string value: '\xE5\x90\x88\xE8\xAE\xA1' for column
1.我们创建数据库的时候没有更改数据库的字符集为utf8. 在mysql工具中,右击数据库,->"改变数据库",->选择“基字符集”为utf-8; 2,数据库中表的字符 ...
- poj 2029 Get Many Persimmon Trees 各种解法都有,其实就是瞎搞不算吧是dp
连接:http://poj.org/problem?id=2029 题意:给你一个map,然后在上面种树,问你h*w的矩形上最多有几棵树~这题直接搜就可以.不能算是DP 用树状数组也可作. #incl ...
- IOS-网络(GET请求和POST请求、HTTP通信过程、请求超时、URL转码)
// // ViewController.m // IOS_0129_HTTP请求 // // Created by ma c on 16/1/29. // Copyright © 2016年 博文科 ...
- 字典序全排列(java实现)
import java.util.Arrays; /** *字典序全排列 *字符串的全排列 *比如单词"too" 它的全排列是"oot","oto&q ...
- Xilinx SDK使用教程
本文参考 Xilinx SDK软件内置的教程,打开方法:打开SDK->Help->Cheet Sheets...->Xilinx SDK Tutorials,这里有6篇文档.本文详细 ...