• SGU Magic Pairs


    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取模 那一部分都约去了。。

     1 /*Author :usedrose  */
     2 /*Created Time :2015/7/24 14:55:16*/
     3 /*File Name :2.cpp*/
     4 #include <cstdio>
     5 #include <iostream>
     6 #include <algorithm>
     7 #include <sstream>
     8 #include <cstdlib>
     9 #include <cstring>
    10 #include <climits>
    11 #include <vector>
    12 #include <string>
    13 #include <ctime>
    14 #include <cmath>
    15 #include <deque>
    16 #include <queue>
    17 #include <stack>
    18 #include <set>
    19 #include <map>
    20 #define INF 0x3f3f3f3f
    21 #define eps 1e-8
    22 #define pi acos(-1.0)
    23 #define MAXN 1110
    24 #define OK cout << "ok" << endl;
    25 #define o(a) cout << #a << " = " << a << endl
    26 #define o1(a,b) cout << #a << " = " << a << "  " << #b << " = " << b << endl
    27 using namespace std;
    28 typedef long long LL;
    29 
    30 set<pair<int, int > > s;
    31 int main()
    32 {
    33     //freopen("data.in","r",stdin);
    34     //freopen("data.out","w",stdout);
    35     cin.tie(0);
    36     ios::sync_with_stdio(false);
    37     int n, a, b;
    38     cin >> n;
    39     cin >> a >> b;
    40     for (int i = 1;i <= n; ++ i) 
    41         s.insert(make_pair((a*i)%n, (b*i)%n));
    42     cout << s.size() << endl;
    43     set<pair<int, int> > ::iterator it = s.begin();
    44     while (it != s.end()) {
    45         cout << it->first << " " << it->second << endl;
    46        it++;    
    47     }
    48 
    49     return 0;
    50 }
    View Code

    大牛的详细分析:

    http://d.ream.at/sgu-119/

  • 相关阅读:
    [Linux]-Nginx平滑升级
    [Linux]-部署PXE网络装机
    [Linux]--构建DR模式的LVS群集
    [Linux]--构建NAT模式的LVS群集
    [Linux]-Apache,awstats部署
    [Linux]-部署Nginx Apache动静分离
    [Linux]-Rsync同步
    Vue.js内部运行机制(一)
    JS类数组对象及如何转变为真正的数组
    JS、TS中的符号表达式
  • 原文地址:https://www.cnblogs.com/usedrosee/p/4673818.html
Copyright © 2020-2023  润新知