CF 787A
来源:互联网 发布:网络陷阱有哪些 编辑:程序博客网 时间:2024/05/22 21:36
题目链接:http://codeforces.com/contest/787/problem/A
题意:给你a,b,c,d并且有两个数列,一个数列是b, b+a, b+2*a, ”’ ,另外一个是 d , d + c, d + 2*c,”’,现在问你这两个数列最小的相等的值是什么?
解法:
You need to find out if there are non-negative integers like i and j such ai + b = cj + d and i or j (or both) is minimized. It’s easy to show that if a, b, c, d ≤ N, and such i and j exist, then i, j ≤ N, so you can iterate over i and check if such j exists.
我直接两重for循环暴力的。
复杂度O(n^2)
//CF 787A#include <bits/stdc++.h>using namespace std;int main(){ int a, b, c, d; cin >> a >> b >> c >> d; int ans = 0x3f3f3f3f; for(int i = 0; i <= 1000; i++){ for(int j = 0; j <= 1000; j++){ if(b+a*i == d+c*j){ ans = min(ans, b+a*i); } } } if(ans == 0x3f3f3f3f) puts("-1"); else cout << ans << endl;}
0 0
- CF 787A
- CF 2A Winner
- CF 128A Statues
- <cf>A. Exams
- CF 109A
- CF 111A
- CF 4A Watermelon
- CF 237A (Cash)
- CF 6 A - Triangle
- CF:96A.Football
- CF:208A. Dubstep
- CF:41A. Translation
- CF:59A. Word
- CF:43A. Football
- CF:78A. Haiku
- CF:A. Flipping Game
- CF 148 div1 A
- CF 127 div1 A
- 关于逻辑运算符的理解
- C++ 基础(六) —— 函数(2)
- Unity Scene 数据迁移研究
- 2017-03-24
- 问题4--centos怎么设置时间与另一台服务器时间同步
- CF 787A
- js中的事件委托技术
- JAVA内部类的一些总结
- 线段树操作中的一些预判方法【UOJ 228】【codeforces 438D】
- 问题5--zabbix数据库连接问题
- 浅谈Java中的对象和对象引用
- ZooKeeper 学习笔记一:常用命令
- VS2012串口助手编程C++
- 洛谷 P1336 最佳课题选择