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 ...
随机推荐
- 探索JS引擎工作原理
JavaScript 从定义到执行,JS引擎在实现层做了很多初始化工作,因此在学习 JS 引擎工作机制之前,我们需要引入几个相关的概念:执行环境栈.全局对象.执行环境.变量对象.活动对象.作用域和作用 ...
- Java使用Try with resources自动关闭资源
Try-with-resources Try-with-resources是Java7中一个新的异常处理机制,它能够很容易地关闭在try-catch语句块中使用的资源. 利用Try-Catch-Fin ...
- 关于.Net mvc 项目在本地vs运行响应时间过长无法访问时,解决方法!
最近可能是刚升级了电脑使用了window10操作系统,总是遇到了一些以前没有遇到过的事情! 今早来到公司本来准备写bug的,但是当我打开vs运行的时候发现今天的电脑响应的时间明显的要比之前打开网页调试 ...
- 一个比Spring Boot快44倍的Java框架!
最近栈长看到一个框架,官方号称可以比 Spring Boot 快 44 倍,居然这么牛逼,有这么神奇吗?今天带大家来认识一下. 这个框架名叫:light-4j. 官网简介:A fast, lightw ...
- 在Linux(Centos7)上使用Docker运行.NetCore
在上一篇中我们写了如何在windows中使用docker运行.netcore,既然我们了解了windows下的运行发布,我们也可以试试linux下使用docker运行.netcore项目,那么今天我们 ...
- AssetsUtils【读取assets、res/raw、./data/data/包名/目录下的文件】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 封装了以下功能: 1.读取assets目录下的资源html.文件.图片,将文件复制到SD卡目录中: 2.读取res/raw目录下的文 ...
- ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)解决办法
一,报错原因及分析 mysql的这个报错的原因是mysql服务没有正确启动就是mysqld这个程序. mysql要想运行需要mysql和mysqld两个都启动才行 二,解决办法 右键我的电脑——> ...
- Mac下安装多版本python
1.安装Homebrew 将命令行复制至终端,进行安装. /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/H ...
- 使用nginx搭建高可用,高并发的wcf集群
很多情况下基于wcf的复杂均衡都首选zookeeper,这样可以拥有更好的控制粒度,但zk对C# 不大友好,实现起来相对来说比较麻烦,实际情况下,如果 你的负载机制粒度很粗糙的话,优先使用nginx就 ...
- golang命令行库cobra的使用
简介 Cobra既是一个用来创建强大的现代CLI命令行的golang库,也是一个生成程序应用和命令行文件的程序.下面是Cobra使用的一个演示: Cobra提供的功能 简易的子命令行模式,如 app ...