首页 > 其他分享 >luogu P7004 [NEERC2013]Interactive Interception 题解

luogu P7004 [NEERC2013]Interactive Interception 题解

时间:2022-10-02 17:33:40浏览次数:77  
标签:std int 题解 P7004 mid luogu using include left

题目链接

感觉比较玄学的交互,看了题解才会做。

主体的思想是,我们在二分位置的同时也对 \(v\) 的范围进行修改。

假设我们现在的区间是 \([L,R]\) ,那么我们取 \(mid=\frac{L+R}{2}\) ,然后再询问 \(check(L, mid)\) 。
这样可以先得到当前时间上点 \(P\) 所在位置的范围,并把范围记录下来。

接着我们枚举每一个之前我们记录下来的位置范围 \(l_i\) 到 \(r_i\) 。
然后结合当前的 \(L\) 和 \(R\) 计算题目中速度的范围,再模拟让点再向前走一步即可。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cctype>
#include <string>

#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)

using std::pair;
using std::make_pair;
using std::string;

#define pii pair<int, int>
#define mp make_pair

using ll = long long;
const int inf = 1e9;
const ll infll = 0ll + 1e18;

#define int long long
const int N = 505;

int pos, v, mxv, l[N], r[N], tot, vleft, vright;

inline int check(int l, int r) {
  std::cout << "check " << l << " " << r << std::endl;
  string res; std::cin >> res;
  if (res[0] == 'Y') return 1;
  else return 0;
}

signed main(void) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL), std::cout.tie(NULL);
  std::cin >> pos >> vright;
  int left = 0, right = pos;
  while (left < right) {
    int mid = (left + right) / 2;
    if (check(left, mid) == 1) right = mid;
    else left = mid + 1;
    for (int i = 1; i <= tot; i ++) {
      vleft = std::max(vleft, (left - r[i]) / (tot + 1 - i));
      vright = std::min(vright, (right - l[i]) / (tot + 1 - i));
    }
    tot ++;
    l[tot] = left, r[tot] = right;
    left += vleft;
    right += vright;
  }
  std::cout << "answer " << left << std::endl;
  return 0;
}

标签:std,int,题解,P7004,mid,luogu,using,include,left
From: https://www.cnblogs.com/Oier-GGG/p/16749073.html

相关文章

  • BZOJ 2453 维护队列 题解
    带修莫队模板,双倍经验,注意add和del的顺序以及数据范围(洛谷上)。//bzoj#2453.维护队列#pragmaGCCoptimize(2)#include<bits/stdc++.h>usingnamespacestd;cons......
  • CF 617E XOR and Favorite Number 题解
    如果我们对给定的序列求出异或意义下的前缀和,哪么题意变为求满足\(sum_{i-1}\operatorname{xor}sum_j=k\)的\((i,j)\)数量。由于\(x\operatorname{xor}y=z\)等......
  • LeetCode 斐波那契数算法题解 All In One
    LeetCode斐波那契数算法题解AllInOneFibonacciNumber斐波那契数最佳实践性能优化"usestrict";/****@authorxgqfrms*@licenseMIT*@cop......
  • Luogu P7503 「HMOI R1」文化课
    题传先想一个巨shaber的暴力DP:设\(f_{i}\)为对前\(i\)个人分段的最优解,则:\[f_{i}=\max_{0\lej<i}\{f_{j}+\operatorname{W}(j+1,i)\}\]其中:\[\operatorname{W......
  • 2022 牛客多校题解
    2022牛客多校题解Contest1JContest2JContest3HHack(SAM)枚举B中的右端点,查询最长在A串中向右可以延伸多长。考虑对A串建立一个SAM,然后对于B串从左到右跑SAM的D......
  • 洛谷 P2709 小B的询问 题解
    莫队板子。//P2709小B的询问#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintMAXN=50005;structQuery{ intl,r,id;}q[MAXN];in......
  • The 2022 ICPC Asia Regionals Online Contest (II)部分题解
    ......
  • LeetCode 无重复字符的最长子串算法题解 All In One
    LeetCode无重复字符的最长子串算法题解AllInOnejs/ts实现无重复字符的最长子串无重复字符的最长子串原理图解滑动窗口"usestrict";/****@authorx......
  • Even Number Addicts - 题解【动态规划/记忆化搜索】
    题面本题是CodeforcesGlobalRound22的C题。原题链接见:C.EvenNumberAddicts。下面搬运一下题面:DescriptionAliceandBobareplayingagameonasequence\(a_......
  • LJT的书库题解
    原题链接题目难度较低,看懂题目后特别好想。注意到题目中说的,一个藏书室最多与两个相同的藏书室相连。那么含有所需书的藏书室是树上的一条链。但是,书的本数未知,且链的两......