59: loj #10215
$des$
https://loj.ac/problem/10215
$sol$
exgcd检查
$code$
- #include <iostream>
- #include <cstdlib>
- #include <algorithm>
- #include <cstring>
- #include <cstdio>
- using namespace std;
- #define gc getchar()
- inline int read() {
- int x = ; char c = gc;
- while(c < '' || c > '') c = gc;
- while(c >= '' && c <= '') x = x * + c - '', c = gc;
- return x;
- }
- #define LL long long
- const int N = ;
- LL C[N], P[N], L[N];
- int n;
- int M = 1e6;
- LL Exgcd(LL a, LL b, LL &x, LL &y) {
- if(b == ) {
- x = , y = ; return a;
- }
- LL gg = Exgcd(b, a % b, x, y);
- LL tmp = x;
- x = y, y = tmp - a / b * y;
- return gg;
- }
- bool Solve(LL k) {
- for(int i = ; i <= n; i ++) {
- for(int j = i + ; j <= n; j ++) {
- LL c1 = C[i], c2 = C[j], p1 = P[i], p2 = P[j], x, y;
- LL b = p1 - p2, d = c2 - c1;
- if(b < ) b = -b, d = -d;
- LL g = Exgcd(b, k, x, y);
- if(d % g) continue;
- x *= (d / g);
- LL r = k / g;
- while(x < ) x += r;
- x %= r;
- if(x <= min(L[i], L[j])) return ;
- }
- }
- return ;
- }
- int main() {
- n = read();
- LL Max = ;
- for(int i = ; i <= n; i ++)
- C[i] = read(), P[i] = read(), L[i] = read(), Max = max(Max, C[i]);
- int a;
- for(a = Max; a <= M; a ++) {
- if(Solve(1ll * a)) {
- cout << a; return ;
- }
- }
- return ;
- }
59: loj #10215的更多相关文章
- LOJ.6060.[2017山东一轮集训Day1/SDWC2018Day1]Set(线性基)
LOJ BZOJ 明明做过一道(最初思路)比较类似的题啊,怎么还是一点思路没有. 记所有元素的异或和为\(s\),那么\(x_1+x_2=x_1+x_1\ ^{\wedge}s\). \(s\)是确定 ...
- LOJ 3119: 洛谷 P5400: 「CTS2019 | CTSC2019」随机立方体
题目传送门:LOJ #3119. 题意简述: 题目说的很清楚了. 题解: 记恰好有 \(i\) 个极大的数的方案数为 \(\mathrm{cnt}[i]\),则答案为 \(\displaystyle\ ...
- Loj#143-[模板]质数判定【Miller-Rabin】
正题 题目链接:https://loj.ac/p/143 题目大意 给出一个数\(p\),让你判定是否为质数. 解题思路 \(Miller-Rabin\)是一种基于费马小定理和二次探测定理的具有较高正 ...
- 编写高质量代码:改善Java程序的151个建议(第4章:字符串___建议56~59)
建议56:自由选择字符串拼接方法 对一个字符串拼接有三种方法:加号.concat方法及StringBuilder(或StringBuffer ,由于StringBuffer的方法与StringBuil ...
- C#得到某月最后一天晚上23:59:59和某月第一天00:00:00
项目需求: 某学校订单截止操作时间的上一个月最后一天晚上23:59:59 为止所有支付的订单统计: 代码: /// <summary> /// 通过学校和截止时间得到订单 /// < ...
- 重新想象 Windows 8 Store Apps (59) - 锁屏
[源码下载] 重新想象 Windows 8 Store Apps (59) - 锁屏 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 锁屏 登录锁屏,获取当前程序的锁 ...
- Loj 1003–Drunk(拓扑排序)
1003 - Drunk PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB One of my fr ...
- 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
- 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 [题目] ...
随机推荐
- 安装和启动docker
1.安装和启动docker yum update -y yum install -y yum-utils yum-config-manager --add-repo https://download. ...
- C# vb .net图像合成-合成自定义路径
在.net中,如何简单快捷地实现图像合成呢,比如合成文字,合成艺术字,多张图片叠加合成等等?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码 ...
- 微信小程序和asp.net core基于docker和nginx的交互
这个文章的题目起的比较长,我想实现这样一个产品: 前端是微信小程序,后端是基于docker运行的asp.net core webapi.webapi通过nginx实现的反向代理接入,nginx同样基于 ...
- windows7下安装msys2
系统: windows 7 首先需要msys2的安装包,可以去官网下载安装包官网地址: http://www.msys2.org/本次下载的是 msys2-x86_64-20190524.exe 注意 ...
- HDU2577 How to Type
题目链接 一道DP问题 定义dp[i][j]为敲完第i个字母的最小花费,j=1代表Caps Lock打开,j=0代表Caps Lock关闭,则有: 如果第i个字母为大写: dp[i][1]=min(d ...
- ios、安卓前端兼容性
1.日期兼容性 解决方法(请看我上一篇文章)安卓.ios时间转换成时间戳的形式 2.input框聚焦,ios出现outline或者阴影,安卓显示正常 解决方法 input:focus{outline: ...
- CSS文本居中问题
文本水平居中 水平居中比较简单,将对应的html元素text-align属性值为center,其子元素就会水平居中. 文本垂直居中 单行文本垂直居中 设置文本元素的line-height属性值为元素高 ...
- vue自定义指令VNode详解(转)
1.自定义指令钩子函数 Vue.directive('my-directive', {bind: function () {// 做绑定的准备工作// 比如添加事件监听器,或是其他只需要执行一次的复杂 ...
- Js基本语句
js基本语句整理导向图 ---欢迎收藏^ - ^
- Android 中自定义仪表盘
如图: 自定义属性 values文件下添加 attrs.xml文件 <?xml version="1.0" encoding="utf-8"?> & ...