博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
usaco16 jan gold
阅读量:4326 次
发布时间:2019-06-06

本文共 6517 字,大约阅读时间需要 21 分钟。

T1:angry cows

Bessie the cow has designed what she thinks will be the next big hit video game: "Angry Cows". The premise, which she believes is completely original, is that the player shoots a cow with a slingshot into a one-dimensional scene consisting of a set of hay bales located at various points on a number line; the cow lands with sufficient force to detonate the hay bales in close proximity to her landing site, which in turn might set of a chain reaction that causes additional hay bales to explode. The goal is to use a single cow to start a chain reaction that detonates all the hay bales.

There are NN hay bales located at distinct integer positions x_1, x_2, \ldots, x_Nx1,x2,,xN on the number line. If a cow is launched with power RR landing at position xx , this will causes a blast of "radius RR ", engulfing all hay bales within the range x-R \ldo s x+RxR\ldosx+R . These hay bales then themselves explode (all simultaneously), each with a blast radius of R-1R1 . Any not-yet-exploded bales caught in these blasts then all explode (all simultaneously) with blast radius R-2R2 , and so on.

Please determine the minimum amount of power RR with which a single cow may be launched so that, if it lands at an appropriate location, it will cause subsequent detonation of every single hay bale in the scene.

input:

The first line of input contains NN ( 2 \leq N \leq 50,0002N50,000 ). The remaining

NN lines all contain integers x_1 \ldots x_Nx1xN (each in the range

0 \ldots 1,000,000,00001,000,000,000 ).

output:

Please output the minimum power RR with which a cow must be launched in order

to detonate all the hay bales. Answers should be rounded and printed to exactly

1 decimal point.

题目是说把一头牛砸到某个位置会发生爆炸,爆炸半径是砸牛所用的能量R,每个干草堆如果被引爆会继续产生半径R-1(递减)的爆炸,问怎么扔可以把所有草堆引爆并且R最小。

令dp1[i]表示i左边全部被引爆的最小半径,有: 

 
dp1i=min{
aiaj,dp1j+1+1}(aiaj>dp1j+1,j<i)
dp1i=min{ai−aj,dp1j+1+1}(ai−aj>dp1j+1,j<i)

即表示最远直接引爆到j的最小半径。 
然后发现dp1和j是单调递增的,因此O(n)O(n)。 
dp2对称。 
然后再枚举投掷点即可。 

#include 
#include
#include
using namespace std;#define rep(i,j,k) for(i=j;i
dp1[j + 1] + 2) ++j; dp1[i] = min(a[i] - a[j], dp1[j + 1] + 2); } memset(dp2, 127, sizeof dp2); dp2[j = n - 1] = -2; for (i = n - 2; i >= 0; --i) { while (j - 1 > i && a[j - 1] - a[i] > dp2[j - 1] + 2) --j; dp2[i] = min(a[j] - a[i], dp2[j - 1] + 2); } for (i = 0, j = n - 1; i < j; ) { ans = min(ans, max((a[j] - a[i]) / 2, 2 + max(dp1[i], dp2[j]))); if (dp1[i + 1] < dp2[j - 1]) ++i; else --j; } printf("%.1f", 1.0 * ans / 2); return 0;}

by:http://blog.csdn.net/huanghongxun/ https://blog.csdn.net/huanghongxun/article/details/51193632

T2:

Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! They both fan out and search the farm along different paths, but stay in contact via radio so they can keep in touch with each-other. Unfortunately, the batteries in their radios are running low, so they want to plan their movements so as to conserve power, by trying to stay always within a short distance apart.

Farmer John starts at location ( f_x, f_yfx,fy ) and plans to follow a path consisting of NN steps, each of which is either 'N' (north), 'E' (east), 'S' (south), or 'W' west. Bessie starts at location ( b_x, b_ybx,by ) and follows a similar path consisting of MM steps. Both paths may share points in common. At each time step, Farmer John can either stay put at his current location, or take one step forward along his path, in whichever direction happens to be next (assuming he has not yet reached the final location in his path). Bessie can make a similar choice. At each time step (excluding the first step where they start at their initial locations), their radios consume energy equal to the square of the distance between them.

Please help FJ and Bessie plan a joint movement strategy that will minimize the total amount of energy consumed up to and including the final step where both of them first reach the final locations on their respective paths.

input:

The first line of input contains NN and MM ( 1 \leq N, M \leq 10001N,M1000 ). The

second line contains integers f_xfx and f_yfy , and the third line contains b_xbx

and b_yby ( 0 \leq f_x, f_y, b_x, b_y \leq 10000fx,fy,bx,by1000 ). The next line contains a

string of length NN describing FJ's path, and the final line contains a string

of length MM describing Bessie's path.

It is guranteed that Farmer John and Bessie's coordinates are always in the

range ( 0 \leq x,y \leq 10000x,y1000 ) throughout their journey. Note that East points in the positive x direction and North points in the positive y direction.

output:

Output a single integer specifying the minimum energy FJ and Bessie can use

during their travels.

FJ从位置(fx,fy)开始,并计划遵循由N步骤组成的路径,每个步骤都是“N”(北),“E”(东),“S”(南),或“W”(西)。Bessie从位置(bx,by)开始,并遵循由M步骤组成的类似路径。两个路径可以经过相同的点。在每个时间段,FJ可以保持在他现在的位置,或沿着他的道路前进一步,无论哪个方向恰好在下一个(假设他还没有到达他的路径的最后位置)。Bessie可以做出类似的选择。在每个时间步(不包括从初始位置开始的第一步),他们的无线电消耗的能量等于它们之间距离的平方。

dp[i][j]表示F走i步,J走j步的最小花费

然后进行状态转移就好了

#include 
#include
#include
using namespace std;typedef long long LL;const int maxn = 1005;int n, m;int dx[] = {
0, 0, -1, 1}, dy[] = {
1, -1, 0, 0};char str[maxn];LL dp[maxn][maxn];struct _po { int x, y;} F[maxn], B[maxn];inline int getid(char ch) { if(ch == 'N') return 0; if(ch == 'S') return 1; if(ch == 'W') return 2; if(ch == 'E') return 3;}inline LL dis(_po A, _po B) { return (LL)(A.x - B.x) * (A.x - B.x) + (LL)(A.y - B.y) * (A.y - B.y);}int main() { scanf("%d%d%d%d%d%d", &n, &m, &F[0].x, &F[0].y, &B[0].x, &B[0].y); scanf("%s", str + 1); for(int i = 1, op; str[i]; i++) { op = getid(str[i]); F[i] = (_po){F[i - 1].x + dx[op], F[i - 1].y + dy[op]}; } scanf("%s", str + 1); for(int i = 1, op; str[i]; i++) { op = getid(str[i]); B[i] = (_po){B[i - 1].x + dx[op], B[i - 1].y + dy[op]}; } memset(dp, 0x3f, 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;} 

 T3:暂时还没搞出来。

 

转载于:https://www.cnblogs.com/beiju-z/p/9291909.html

你可能感兴趣的文章
小D课堂 - 零基础入门SpringBoot2.X到实战_第11节 Logback日志框架介绍和SpringBoot整合实战_45、SpringBoot2.x日志讲解和Logback配置实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_02技术选型
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_汇总
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_01传统架构演进到分布式架构
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_02 微服务核心基础讲解
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_04微服务下电商项目基础模块设计...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-01 什么是微服务的注册中心
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-03CAP原理、常见面试题
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-04 SpringCloud微服务核心组件Eureka介绍和闭源后影响...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-05 服务注册和发现Eureka Server搭建实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-06 服务注册和发现之Eureka Client搭建商品服务实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-07 Eureka服务注册中心配置控制台问题处理...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_4-01 常用的服务间调用方式讲解
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_4-02 微服务调用方式之ribbon实战 订单调用商品服务...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_4-03 高级篇幅之Ribbon负载均衡源码分析实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_4-06 Feign核心源码解读和服务调用方式ribbon和Feign选择...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_4-05 微服务调用方式之feign 实战 订单调用商品服务...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-02 Netflix开源组件断路器
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-01分布式核心知识之熔断、降级
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-04 feign结合hystrix断路器开发实战下...
查看>>