• 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/

  • 相关阅读:
    php数组转换成js可用的数组的两种方式
    常用正则表达式--------------[拿把小刀,强大自己]
    AngularJs 相应回车事件
    常见的关系型数据库和非关系型数据库及其区别
    CMDB资产采集
    GB和GiB的区别
    python枚举详解
    python保留两位小数
    详解TCP三握四挥
    npm run dev 和 npm run serve
  • 原文地址:https://www.cnblogs.com/usedrosee/p/4673818.html
Copyright © 2020-2023  润新知