Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Time Limit: 2000 mSec
Problem Description

Input

Output
The only line should contain the minimal number of days required for the ship to reach the point (x2,y2)(x2,y2).
If it's impossible then print "-1".
Sample Input
0 0
4 6
3
UUU
Sample Output
5
题解:第一感觉是bfs,然后大概背包一下之类的,但是数据范围不允许呀,做出这个题的关键点就是注意到运动独立性(呵呵),和如果在第x天能到,那么对于y >= x的都能到,因此就可以二分,固定了天数之后,风吹的距离就是固定的,并且可以用前缀和O(1)求,然后就是判断风吹到的点和目标点的哈密顿距离是否<=天数即可。
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 1; i <= (n); i++)
#define sqr(x) ((x) * (x)) const int maxn = + ;
const int maxm = + ;
const int maxs = + ; typedef long long LL;
typedef pair<int, int> pii;
typedef pair<double, double> pdd; const LL unit = 1LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const double inf = 1e15;
const double pi = acos(-1.0);
const int SIZE = + ;
const LL MOD = ; LL sx, sy, ex, ey;
LL x[maxn], y[maxn];
LL n;
string str; bool Judge(LL lim)
{
LL m = lim / n, remain = lim % n;
LL xx = sx + m * x[n] + x[remain];
LL yy = sy + m * y[n] + y[remain];
if (abs(xx - ex) + abs(yy - ey) <= lim)
return true;
return false;
} int main()
{
ios::sync_with_stdio(false);
cin.tie();
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> sx >> sy >> ex >> ey;
cin >> n;
cin >> str;
LL len = str.size();
for (LL i = ; i < len; i++)
{
if (str[i] == 'U')
{
x[i + ] = x[i];
y[i + ] = y[i] + ;
}
else if (str[i] == 'D')
{
x[i + ] = x[i];
y[i + ] = y[i] - ;
}
else if (str[i] == 'L')
{
x[i + ] = x[i] - ;
y[i + ] = y[i];
}
else
{
x[i + ] = x[i] + ;
y[i + ] = y[i];
}
}
LL le = , ri = LLONG_MAX / ;
LL ans = -;
while (le <= ri)
{
LL mid = (le + ri) / ;
if (Judge(mid))
{
ri = mid - ;
ans = mid;
}
else
{
le = mid + ;
}
}
cout << ans << endl; return ;
}
Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship的更多相关文章
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems(矩阵快速幂)
题目传送门 题意: 一个魔法水晶可以分裂成m个水晶,求放满n个水晶的方案数(mol1e9+7) 思路: 线性dp,dp[i]=dp[i]+dp[i-m]; 由于n到1e18,所以要用到矩阵快速幂优化 ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
- Educational Codeforces Round 60 (Rated for Div. 2)
A. Best Subsegment 题意 找 连续区间的平均值 满足最大情况下的最长长度 思路:就是看有几个连续的最大值 #include<bits/stdc++.h> using n ...
- Educational Codeforces Round 60 (Rated for Div. 2)D(思维,DP,快速幂)
#include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;unordered_map<long ...
- Educational Codeforces Round 60 (Rated for Div. 2)E(思维,哈希,字符串,交互)
#include <bits/stdc++.h>using namespace std;int main(){ string t; cin>>t; int n=t.size() ...
- Educational Codeforces Round 60 (Rated for Div. 2) 即Codeforces Round 1117 C题 Magic Ship
time limit per test 2 second memory limit per test 256 megabytes input standard inputoutput standard ...
- Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String
题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3 ...
- Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题
B. Magic Stick Recently Petya walked in the forest and found a magic stick. Since Petya really likes ...
随机推荐
- Java核心技术第五章——2.Object类
Object类:所有类的超类 Object类是Java中所有类的始祖,在Java中每个类都是由它扩展而来的.但是并不需要这样写: public class Emloyee extends Object ...
- IDEA设置热部署
1.点击File找到Settings打开. 1.2:找到Compiler将 Build project automatically 勾选 2.使用快捷键 Ctrl+Shift+A 搜索 re ...
- 跟我一起学opencv 第五课之调整图像亮度和对比度
一.调整图像亮度与对比度 1.图像变换 ---像素变换-点操作 ---邻域操作-区域操作 调整图像亮度和对比度属于像素变换-点操作 公式为:g(i,j) = αf(i,j) + β 其中α>0 ...
- js node.js 编写命令工具demo
1 创建文件夹cli-demo 2 执行npm init 3 创建cli.js 文件 内容如下: //js文件变成可执行文件 #!/usr/bin/env node console.log(&quo ...
- 2019-中小型公司PHP面试题目记录(附带答案)
博主是三线省会城市的苦逼技术开发,主攻PHP方向,平时前后端语言也都有涉及,因为都是自学,上手就是框架,工作五年来基础补的不稳,换工作的时候苦不堪言,感觉一上来就问Ngnix的运行机制,php的被编译 ...
- 关于Python深浅拷贝
拷贝: 说明:原则上就是把数据分离出来,复制其数据,并以后修改互不影响. 何来深浅拷贝的说法? 深浅拷贝的“深”和“浅”可以理解为从变量到硬盘上的物理存储介质之间的层次的多少. 下面用一个示例来解释浅 ...
- 【工利其器】必会工具之(三)systrace篇(1)官网翻译
前言 Android 开发者官网中对systrace(Android System Trace)有专门的介绍,本篇文章作为systrace系列的开头,笔者先不做任何介绍,仅仅翻译一下官网的介绍.在后续 ...
- TypeScript 中的方法重载
方法重载(overload)在传统的静态类型语言中是很常见的.JavaScript 作为动态语言, 是没有重载这一说的.一是它的参数没有类型的区分,二是对参数个数也没有检查.虽然语言层面无法自动进行重 ...
- LVS(二)NAT模型配置
NAT配置模式 环境说明 LVS服务器(在eth0:0上设置VIP为:192.168.159.200/24) Eth0:192.168.159.133/24 GW:192.168.159.2 Et ...
- Promise来控制JavaScript的异步执行
一般来说,js.html都是按照从上至下这种方式来进行执行的.这就造成了,基本上所有的执行过程都是在一个线程中进行. 我们都知道,ajax的使用大大的提高了前后台的沟通效率,那么有没有什么方式,让js ...