codeforces 787A The Monster (猜想 + 证明)
来源:互联网 发布:赚话费的软件 编辑:程序博客网 时间:2024/06/15 17:15
解题思路:
这次是第二次做这道题,第一次做是这场比赛的时候,当时没怎么多想,因为是div2A,就感觉一定可以暴力解决,当时脑洞一开,觉得如果存在解就一定存在小于等于N的解。
赛后看题解的时候,发现题解和我的思路是一致的。开始寻求合理的证明,最开始一直往拓展欧几里得的方面去想,然后越想越复杂,一度放弃了。
这次和别人讨论这道题的时候突然发现了一个很简单的想法。
首先我们假设存在一组解(i,j)满足,i * a + b = j * c + d。 然后观察我们可以得到 (i + kc, j + ka)也是一组解。
然后我们说明一定存在一个自然数k,满足 0 ≤ i + kc ≤ N && 0 ≤ j + ka ≤ N 。
也许到这里还不是太显然,我们把式子做一个简单的变形
-i ≤ kc ≤ N - i && -j ≤ ka ≤ N - j K∈N
∵ c ≤ N && a ≤ N ∴ kc一定在一段长为N的区间上面存在值,ka同理, 证毕!
AC代码:
/* @Author: wchhlbt @Date: 2017/3/23*///#include <bits/stdc++.h>#include <vector>#include <list>#include <map>#include <set>#include <queue>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>#include <cstring>#define Fori(x) for(int i=0;i<x;i++)#define Forj(x) for(int j=0;j<x;j++)#define maxn 100#define inf 0x3f3f3f3f#define ONES(x) __builtin_popcount(x)using namespace std;typedef long long ll ;const double eps =1e-8;const int mod = 1000000007;const double PI = acos(-1.0);int dx[4] = {0,0,1,-1};int dy[4] = {1,-1,0,0};map<int,int> mp;int main(){ int a,b,c,d; cin>>a>>b>>c>>d; for(int i = 0; i<=100; i++){ mp[b+i*a]++; } for(int i = 0; i<=100; i++){ if(mp[d+i*c]){ cout << d+i*c << endl; return 0; } } cout << -1 << endl; return 0;}
阅读全文
0 0
- codeforces 787A The Monster (猜想 + 证明)
- CodeForces 787A The Monster
- CodeForces 787A A. The Monster(扩展欧几里得)
- codeforces 787A The Monster 扩展欧几里德 Java
- codeforces 787A the monster(扩展欧几里得做法+暴力做法)
- codeforces 487A Fight the Monster
- 【Codeforces】 487A Fight the Monster
- CodeForces 487A Fight the Monster
- codeforces #487A# Fight the Monster(枚举)
- Codeforces 487A Fight the Monster(暴力)
- Codeforces 487A Fight the Monster
- CodeFroces 787A The Monster
- codeforce 787 A. The Monster
- The Monster (Codefores-787A)
- Codeforces Round #278 (Div. 1) A. Fight the Monster( 暴力)
- codeforces 487 A Fight the Monster 暴力枚举
- A - Kill the monster (DFS)
- A. The Monster
- 编写一个程序,完成字符大小写的转换。
- [数论] 拓展欧几里得算法(poj 2115)
- 分治法实现前序遍历
- orabbix执行查询源码
- 技术点-hibernate关系映射-一对多/多对一映射
- codeforces 787A The Monster (猜想 + 证明)
- mybatis 多层级联问题
- hdu 6073 Matching In Multiplication(无向图+拓扑排序+dfs找环)
- Android学习之Broadcast简单使用
- Bootstrap FileInput中文API整理
- Hibernate映射类中的继承关系
- x:Null
- leetcode--Jump Game
- Android零基础入门第28节:轻松掌握RelativeLayout相对布局