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 ...
随机推荐
- 【干货】快速部署微软开源GPU管理利器: OpenPAI
[干货]快速部署微软开源GPU管理利器: OpenPAI 介绍 不管是机器学习的老手,还是入门的新人,都应该装备上尽可能强大的算力.除此之外,还要压榨出硬件的所有潜力来加快模型训练.OpenPAI作为 ...
- Project file is incomplete. Expected imports are missing 错误解决方案
当你打开一个.net core的项目,Visual Studio 可能无法打开,提示如下错误: D:\workshop\Github\Ocelot\src\Ocelot\Ocelot.csproj : ...
- Java核心技术第五章——2.Object类
Object类:所有类的超类 Object类是Java中所有类的始祖,在Java中每个类都是由它扩展而来的.但是并不需要这样写: public class Emloyee extends Object ...
- java虚拟机内存区域
java虚拟机运行时数据 程序计数器 是一块较小的内存空间,属于线程私有的内存. 用来记录正在执行的虚拟机字节码指令的地址. 每个线程都需要一个独立的程序计数器,各个线程间的计数器互不影响,独立存储. ...
- Fastadmin安装以及各种问题解决
FastAdmin是一款基于ThinkPHP5+Bootstrap的极速后台开发框架 https://www.fastadmin.net/ 参照官方文档安装,还是有坑的 首先注意:无需下载PHP.Th ...
- Kafka面试题
1.如何获取topic主题的列表bin/kafka-topics.sh --list --zookeeper localhost:2181 2.生产者和消费者的命令行是什么?生产者在主题上发布消息:b ...
- javascript ES6 新特性之 扩展运算符 三个点 ...
对于 ES6 新特性中的 ... 可以简单的理解为下面一句话就可以了: 对象中的扩展运算符(...)用于取出参数对象中的所有可遍历属性,拷贝到当前对象之中. 作用类似于 Object.assign() ...
- 深入理解Linux内核 学习笔记(3)
第三章 进程 可以看到很多熟悉的结构体 进程状态: 可运行状态(TASK_ RUNNING) 进程要么在CPU上执行,要么准备执行. 可巾断的等待状态(TASK_ INTERRUPTIBLE) 进程被 ...
- 从PRISM开始学WPF(四)Prism-Module-更新至Prism7.1
0x4Modules Modules是能够独立开发.测试.部署的功能单元,Modules可以被设计成实现特定业务逻辑的模块(如Profile Management),也可以被设计成实现通用基础设施或服 ...
- NFS服务和DHCP服务讲解(week3_day2)--技术流ken
NFS服务端概述 NFS,是Network File System的简写,即网络文件系统.网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS: NFS允许一个系统在网络上与他人共享目录 ...