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 [题目] ...
随机推荐
- fail fast和fail safe策略
优先考虑出现异常的场景,当程序出现异常的时候,直接抛出异常,随后程序终止 import java.util.ArrayList; import java.util.Collections; impor ...
- 创建你自己定制的vuejs plugin扩展app的功能
什么是vuejs plugin插件 vuejs plugin插件是一个向你的app注入新的全局功能的强大但又简约的方式.从概念上来说,vue plugin非常简单,它就是一个包含了install方法的 ...
- xshell连接本地linux虚拟机速度很慢的解决办法
今天发现用xshell连接centos太慢,网上查询后发现是因为ssh的服务端在连接时会自动检测dns环境是否一致导致的,修改为不检测即可. 修改文件位置:vi /etc/ssh/sshd_confi ...
- Java自学-数字与字符串 装箱和拆箱
Java中基本类型的装箱和拆箱 步骤 1 : 封装类 所有的基本类型,都有对应的类类型 比如int对应的类是Integer 这种类就叫做封装类 package digit; public class ...
- Ansible--Ansible之Playbook
Ansible之Playbook Playbook介绍 playbook参考文档 Playbook与ad-hoc相比,是一种完全不同的运用ansible的方式,类似与saltstack的state状态 ...
- Vue笔记目录
Vue笔记目录 一.Vue.js介绍 二.vue基础-vue-cli(vue脚手架) ...持续更新中,敬请期待
- android中listview滑动卡顿的原因
导致Android界面滑动卡顿主要有两个原因: 1.UI线程(main)有耗时操作 2.视图渲染时间过长,导致卡顿 http://www.tuicool.com/articles/fm2IFfU
- Es查询工具使用
Kibana按照索引过滤数据 1.创建索引模式 2.查询索引中的数据 Es查询不返回数据 创建索引的时候指定mapping mappings={ "mappings": { &qu ...
- Linux搭建MySQL主从
实现目标 搭建两台MySQL服务器(一主一从),一台作为主服务器,一台作为从服务器,主服务器进行写操作,从服务器进行读操作. 工作流程概述 主服务器: 开启二进制日志 配置唯一的server-id 获 ...
- python中print用法
print用法 参考文档:https://blog.csdn.net/sinat_28576553/article/details/81154912 目录 一.print()函数概述 二.变量的输出 ...