$des$

https://loj.ac/problem/10215

$sol$

exgcd检查

$code$

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <cstdio>
  6.  
  7. using namespace std;
  8.  
  9. #define gc getchar()
  10. inline int read() {
  11. int x = ; char c = gc;
  12. while(c < '' || c > '') c = gc;
  13. while(c >= '' && c <= '') x = x * + c - '', c = gc;
  14. return x;
  15. }
  16.  
  17. #define LL long long
  18.  
  19. const int N = ;
  20.  
  21. LL C[N], P[N], L[N];
  22. int n;
  23. int M = 1e6;
  24.  
  25. LL Exgcd(LL a, LL b, LL &x, LL &y) {
  26. if(b == ) {
  27. x = , y = ; return a;
  28. }
  29. LL gg = Exgcd(b, a % b, x, y);
  30. LL tmp = x;
  31. x = y, y = tmp - a / b * y;
  32. return gg;
  33. }
  34.  
  35. bool Solve(LL k) {
  36. for(int i = ; i <= n; i ++) {
  37. for(int j = i + ; j <= n; j ++) {
  38. LL c1 = C[i], c2 = C[j], p1 = P[i], p2 = P[j], x, y;
  39. LL b = p1 - p2, d = c2 - c1;
  40. if(b < ) b = -b, d = -d;
  41. LL g = Exgcd(b, k, x, y);
  42. if(d % g) continue;
  43. x *= (d / g);
  44. LL r = k / g;
  45. while(x < ) x += r;
  46. x %= r;
  47. if(x <= min(L[i], L[j])) return ;
  48. }
  49. }
  50. return ;
  51. }
  52.  
  53. int main() {
  54. n = read();
  55. LL Max = ;
  56. for(int i = ; i <= n; i ++)
  57. C[i] = read(), P[i] = read(), L[i] = read(), Max = max(Max, C[i]);
  58. int a;
  59. for(a = Max; a <= M; a ++) {
  60. if(Solve(1ll * a)) {
  61. cout << a; return ;
  62. }
  63. }
  64.  
  65. return ;
  66. }

59: loj #10215的更多相关文章

  1. LOJ.6060.[2017山东一轮集训Day1/SDWC2018Day1]Set(线性基)

    LOJ BZOJ 明明做过一道(最初思路)比较类似的题啊,怎么还是一点思路没有. 记所有元素的异或和为\(s\),那么\(x_1+x_2=x_1+x_1\ ^{\wedge}s\). \(s\)是确定 ...

  2. LOJ 3119: 洛谷 P5400: 「CTS2019 | CTSC2019」随机立方体

    题目传送门:LOJ #3119. 题意简述: 题目说的很清楚了. 题解: 记恰好有 \(i\) 个极大的数的方案数为 \(\mathrm{cnt}[i]\),则答案为 \(\displaystyle\ ...

  3. Loj#143-[模板]质数判定【Miller-Rabin】

    正题 题目链接:https://loj.ac/p/143 题目大意 给出一个数\(p\),让你判定是否为质数. 解题思路 \(Miller-Rabin\)是一种基于费马小定理和二次探测定理的具有较高正 ...

  4. 编写高质量代码:改善Java程序的151个建议(第4章:字符串___建议56~59)

    建议56:自由选择字符串拼接方法 对一个字符串拼接有三种方法:加号.concat方法及StringBuilder(或StringBuffer ,由于StringBuffer的方法与StringBuil ...

  5. C#得到某月最后一天晚上23:59:59和某月第一天00:00:00

    项目需求: 某学校订单截止操作时间的上一个月最后一天晚上23:59:59 为止所有支付的订单统计: 代码: /// <summary> /// 通过学校和截止时间得到订单 /// < ...

  6. 重新想象 Windows 8 Store Apps (59) - 锁屏

    [源码下载] 重新想象 Windows 8 Store Apps (59) - 锁屏 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 锁屏 登录锁屏,获取当前程序的锁 ...

  7. Loj 1003–Drunk(拓扑排序)

    1003 - Drunk PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB One of my fr ...

  8. svn://59.46.115.123:13690/IOS/trunk/02.DevelopLib/04.Coding/uuridesharing

    svn://59.46.115.123:13690/IOS/trunk/02.DevelopLib/04.Coding/uuridesharing

  9. 59. 总结篇:数组中N(n=1,2,3)个只出现一次的数字[find N numbers which appear only once in array]

    [本文链接] http://www.cnblogs.com/hellogiser/p/find-n-numbers-which-appear-only-once-in-array.html [题目] ...

随机推荐

  1. 安装和启动docker

    1.安装和启动docker yum update -y yum install -y yum-utils yum-config-manager --add-repo https://download. ...

  2. C# vb .net图像合成-合成自定义路径

    在.net中,如何简单快捷地实现图像合成呢,比如合成文字,合成艺术字,多张图片叠加合成等等?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码 ...

  3. 微信小程序和asp.net core基于docker和nginx的交互

    这个文章的题目起的比较长,我想实现这样一个产品: 前端是微信小程序,后端是基于docker运行的asp.net core webapi.webapi通过nginx实现的反向代理接入,nginx同样基于 ...

  4. windows7下安装msys2

    系统: windows 7 首先需要msys2的安装包,可以去官网下载安装包官网地址: http://www.msys2.org/本次下载的是 msys2-x86_64-20190524.exe 注意 ...

  5. HDU2577 How to Type

    题目链接 一道DP问题 定义dp[i][j]为敲完第i个字母的最小花费,j=1代表Caps Lock打开,j=0代表Caps Lock关闭,则有: 如果第i个字母为大写: dp[i][1]=min(d ...

  6. ios、安卓前端兼容性

    1.日期兼容性 解决方法(请看我上一篇文章)安卓.ios时间转换成时间戳的形式 2.input框聚焦,ios出现outline或者阴影,安卓显示正常 解决方法 input:focus{outline: ...

  7. CSS文本居中问题

    文本水平居中 水平居中比较简单,将对应的html元素text-align属性值为center,其子元素就会水平居中. 文本垂直居中 单行文本垂直居中 设置文本元素的line-height属性值为元素高 ...

  8. vue自定义指令VNode详解(转)

    1.自定义指令钩子函数 Vue.directive('my-directive', {bind: function () {// 做绑定的准备工作// 比如添加事件监听器,或是其他只需要执行一次的复杂 ...

  9. Js基本语句

    js基本语句整理导向图 ---欢迎收藏^ - ^

  10. Android 中自定义仪表盘

    如图: 自定义属性 values文件下添加 attrs.xml文件 <?xml version="1.0" encoding="utf-8"?> & ...