SGU Magic Pairs
2015-07-24 16:08
555 查看
A0x + B0y = kn
Ax + By = k'n
左差得
(A - A0)x + (B -B0)y = 0(mod n)
所以只要枚举A0, B0的倍数就行了。。
公式就是 ( (i*a)%n, (i*b)%n ), i =0, 1, ... , n-1
i*a, i*b如果大于n的话 不会影响结果, 因为对n取模 那一部分都约去了。。
View Code
大牛的详细分析:
http://d.ream.at/sgu-119/
Ax + By = k'n
左差得
(A - A0)x + (B -B0)y = 0(mod n)
所以只要枚举A0, B0的倍数就行了。。
公式就是 ( (i*a)%n, (i*b)%n ), i =0, 1, ... , n-1
i*a, i*b如果大于n的话 不会影响结果, 因为对n取模 那一部分都约去了。。
/*Author :usedrose */ /*Created Time :2015/7/24 14:55:16*/ /*File Name :2.cpp*/ #include <cstdio> #include <iostream> #include <algorithm> #include <sstream> #include <cstdlib> #include <cstring> #include <climits> #include <vector> #include <string> #include <ctime> #include <cmath> #include <deque> #include <queue> #include <stack> #include <set> #include <map> #define INF 0x3f3f3f3f #define eps 1e-8 #define pi acos(-1.0) #define MAXN 1110 #define OK cout << "ok" << endl; #define o(a) cout << #a << " = " << a << endl #define o1(a,b) cout << #a << " = " << a << " " << #b << " = " << b << endl using namespace std; typedef long long LL; set<pair<int, int > > s; int main() { //freopen("data.in","r",stdin); //freopen("data.out","w",stdout); cin.tie(0); ios::sync_with_stdio(false); int n, a, b; cin >> n; cin >> a >> b; for (int i = 1;i <= n; ++ i) s.insert(make_pair((a*i)%n, (b*i)%n)); cout << s.size() << endl; set<pair<int, int> > ::iterator it = s.begin(); while (it != s.end()) { cout << it->first << " " << it->second << endl; it++; } return 0; }
View Code
大牛的详细分析:
http://d.ream.at/sgu-119/
相关文章推荐
- main函数的参数
- !codeforces 399D Painting The Wall-概率dp
- Baidu Map API 1
- gentoo Hardened/Toolchain
- [INSTALL_FAILED_OLDER_SDK]错误
- [leetcode] 219. Contains Duplicate II
- [leetcode] 217.Contains Duplicate
- ORA-29786: SIHA attribute GET failed with error
- uva 10803 Thunder Mountain (floyd)
- hdu 5291 Candy Distribution 2015 Multi-University Training Contest 1
- hdu 5291 Assignment 2015 Multi-University Training Contest 1
- 在VirtualBox中安装Ubuntu14报错:Failed to open a session for the virtual machine,Unable to load R3……
- 如何定义AIDL跨进程间通信
- [LeetCode]Container With Most Water
- 2015 Multi-University Training Contest 2
- 2015 Multi-University Training Contest 2
- Snail—OC学习之选择器SEL
- Snail—OC学习之可变字典NSMutableDictionary
- Naigos PNP图无法加载最新数据
- Snail—OC学习之字典NSDictionary