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)求,然后就是判断风吹到的点和目标点的哈密顿距离是否<=天数即可。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define REP(i, n) for (int i = 1; i <= (n); i++)
  6. #define sqr(x) ((x) * (x))
  7.  
  8. const int maxn = + ;
  9. const int maxm = + ;
  10. const int maxs = + ;
  11.  
  12. typedef long long LL;
  13. typedef pair<int, int> pii;
  14. typedef pair<double, double> pdd;
  15.  
  16. const LL unit = 1LL;
  17. const int INF = 0x3f3f3f3f;
  18. const double eps = 1e-;
  19. const double inf = 1e15;
  20. const double pi = acos(-1.0);
  21. const int SIZE = + ;
  22. const LL MOD = ;
  23.  
  24. LL sx, sy, ex, ey;
  25. LL x[maxn], y[maxn];
  26. LL n;
  27. string str;
  28.  
  29. bool Judge(LL lim)
  30. {
  31. LL m = lim / n, remain = lim % n;
  32. LL xx = sx + m * x[n] + x[remain];
  33. LL yy = sy + m * y[n] + y[remain];
  34. if (abs(xx - ex) + abs(yy - ey) <= lim)
  35. return true;
  36. return false;
  37. }
  38.  
  39. int main()
  40. {
  41. ios::sync_with_stdio(false);
  42. cin.tie();
  43. //freopen("input.txt", "r", stdin);
  44. //freopen("output.txt", "w", stdout);
  45. cin >> sx >> sy >> ex >> ey;
  46. cin >> n;
  47. cin >> str;
  48. LL len = str.size();
  49. for (LL i = ; i < len; i++)
  50. {
  51. if (str[i] == 'U')
  52. {
  53. x[i + ] = x[i];
  54. y[i + ] = y[i] + ;
  55. }
  56. else if (str[i] == 'D')
  57. {
  58. x[i + ] = x[i];
  59. y[i + ] = y[i] - ;
  60. }
  61. else if (str[i] == 'L')
  62. {
  63. x[i + ] = x[i] - ;
  64. y[i + ] = y[i];
  65. }
  66. else
  67. {
  68. x[i + ] = x[i] + ;
  69. y[i + ] = y[i];
  70. }
  71. }
  72. LL le = , ri = LLONG_MAX / ;
  73. LL ans = -;
  74. while (le <= ri)
  75. {
  76. LL mid = (le + ri) / ;
  77. if (Judge(mid))
  78. {
  79. ri = mid - ;
  80. ans = mid;
  81. }
  82. else
  83. {
  84. le = mid + ;
  85. }
  86. }
  87. cout << ans << endl;
  88.  
  89. return ;
  90. }

Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship的更多相关文章

  1. 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 ...

  2. 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,所以要用到矩阵快速幂优化 ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

  4. Educational Codeforces Round 60 (Rated for Div. 2)

    A. Best Subsegment 题意 找 连续区间的平均值  满足最大情况下的最长长度 思路:就是看有几个连续的最大值 #include<bits/stdc++.h> using n ...

  5. 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 ...

  6. 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() ...

  7. 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 ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String

    题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3 ...

  9. 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 ...

随机推荐

  1. 【干货】快速部署微软开源GPU管理利器: OpenPAI

    [干货]快速部署微软开源GPU管理利器: OpenPAI 介绍 不管是机器学习的老手,还是入门的新人,都应该装备上尽可能强大的算力.除此之外,还要压榨出硬件的所有潜力来加快模型训练.OpenPAI作为 ...

  2. Project file is incomplete. Expected imports are missing 错误解决方案

    当你打开一个.net core的项目,Visual Studio 可能无法打开,提示如下错误: D:\workshop\Github\Ocelot\src\Ocelot\Ocelot.csproj : ...

  3. Java核心技术第五章——2.Object类

    Object类:所有类的超类 Object类是Java中所有类的始祖,在Java中每个类都是由它扩展而来的.但是并不需要这样写: public class Emloyee extends Object ...

  4. java虚拟机内存区域

    java虚拟机运行时数据 程序计数器 是一块较小的内存空间,属于线程私有的内存. 用来记录正在执行的虚拟机字节码指令的地址. 每个线程都需要一个独立的程序计数器,各个线程间的计数器互不影响,独立存储. ...

  5. Fastadmin安装以及各种问题解决

    FastAdmin是一款基于ThinkPHP5+Bootstrap的极速后台开发框架 https://www.fastadmin.net/ 参照官方文档安装,还是有坑的 首先注意:无需下载PHP.Th ...

  6. Kafka面试题

    1.如何获取topic主题的列表bin/kafka-topics.sh --list --zookeeper localhost:2181 2.生产者和消费者的命令行是什么?生产者在主题上发布消息:b ...

  7. javascript ES6 新特性之 扩展运算符 三个点 ...

    对于 ES6 新特性中的 ... 可以简单的理解为下面一句话就可以了: 对象中的扩展运算符(...)用于取出参数对象中的所有可遍历属性,拷贝到当前对象之中. 作用类似于 Object.assign() ...

  8. 深入理解Linux内核 学习笔记(3)

    第三章 进程 可以看到很多熟悉的结构体 进程状态: 可运行状态(TASK_ RUNNING) 进程要么在CPU上执行,要么准备执行. 可巾断的等待状态(TASK_ INTERRUPTIBLE) 进程被 ...

  9. 从PRISM开始学WPF(四)Prism-Module-更新至Prism7.1

    0x4Modules Modules是能够独立开发.测试.部署的功能单元,Modules可以被设计成实现特定业务逻辑的模块(如Profile Management),也可以被设计成实现通用基础设施或服 ...

  10. NFS服务和DHCP服务讲解(week3_day2)--技术流ken

    NFS服务端概述 NFS,是Network File System的简写,即网络文件系统.网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS: NFS允许一个系统在网络上与他人共享目录 ...