• 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)


    Problem A. Mischievous Problem Setter

     签到.

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 #define ll long long
     5 #define N 100010
     6 #define pii pair <int, int>
     7 #define x first
     8 #define y second
     9 int t, n, m;
    10 pii a[N];
    11 
    12 int main()
    13 {
    14     scanf("%d", &t);
    15     for (int kase = 1; kase <= t; ++kase)
    16     {
    17         printf("Case %d: ", kase);
    18         scanf("%d%d", &n, &m);
    19         for (int i = 1; i <= n; ++i) scanf("%d", &a[i].x);
    20         for (int i = 1; i <= n; ++i) scanf("%d", &a[i].y);
    21         sort(a + 1, a + 1 + n);
    22         int res = 0;
    23         for (int i = 1; i <= n; ++i) 
    24         {
    25             if (a[i].y <= m)
    26             {
    27                 ++res;
    28                 m -= a[i].y;
    29             }
    30             else 
    31                 break;
    32         }
    33         printf("%d
    ", res);
    34     }
    35     return 0;
    36 }
    View Code

    Problem K. Mr. Panda and Kakin

    题意:

    RSA解密

    思路:

    注意到题目的本意是求$x^(2^{30} + 3) = c pmod (n)$

    $从根号处暴力破出p和q,然后求(2^{30} + 3)对 phi(n) = (p - 1) cdot (q - 1) 的逆$

    $最后求幂即可,但是注意到大数模乘会爆,所以可以long ;double 或者用中国剩余定理$

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 #define ll long long
     5 int t;
     6 ll p, q;
     7 
     8 ll qmod(ll base, ll n, ll MOD)
     9 {
    10     base %= MOD; 
    11     ll res = 1; 
    12     while (n)
    13     {
    14         if (n & 1) res = res * base % MOD;
    15         base = base * base % MOD; 
    16         n >>= 1;
    17     }
    18     return res;
    19 }
    20 
    21 void get(ll n)
    22 {
    23     for (ll i = sqrt(n); i >= 0; --i) if (n % i == 0)  
    24     {
    25         p = i;
    26         q = n / i;   
    27         return; 
    28     }
    29 }
    30 
    31 ll exgcd(ll a, ll b, ll &x, ll &y)
    32 {
    33     if (a == 0 && b == 0) return -1;
    34     if (b == 0) { x = 1, y = 0; return a; } 
    35     ll d = exgcd(b, a % b, y, x); 
    36     y -= a / b * x;
    37     return d; 
    38 }
    39 
    40 ll mod_reverse(ll a, ll n)
    41 {
    42     ll x, y;
    43     ll d = exgcd(a, n, x, y);
    44     if (d == 1) return (x % n + n) % n;
    45     else return -1; 
    46 }
    47 
    48 int main()
    49 {
    50     ll n, c;
    51     scanf("%d", &t);
    52     for (int kase = 1; kase <= t; ++kase)
    53     { 
    54         printf("Case %d: ", kase);
    55         scanf("%lld%lld", &n, &c);
    56         get(n);
    57         ll r = (p - 1) * (q - 1);
    58         ll u = mod_reverse(((1ll << 30) + 3), r); 
    59         ll a = qmod(c, u, p);
    60         ll b = qmod(c, u, q);     
    61         b = (b - a + q) % q;
    62         ll inv = qmod(p, q - 2, q); 
    63         ll res = b * inv % q;
    64         res = (res * p % n + a) % n;
    65         printf("%lld
    ", res);
    66     }
    67     return 0;
    68 }
    View Code
  • 相关阅读:
    糍粑大叔的独游之旅-战斗!之弹道实现
    攻击判定流程研究: 瀑布算法、圆桌算法、混合算法解析
    GitHub排名TOP30的机器学习开源项目/贪心学院
    学习ES7+ES8
    k8s Ipvs 内部网络自动分配和内部网络一致ip地址,导致ip冲突
    Linux操作系统load average过高,kworker占用较多cpu
    chrome断点调试&&其他技巧
    Mongodb更新数组$pull修饰符 (mongodb 修改器($inc/$set/$unset/$push/$pop/upsert))
    记一次线上Java程序导致服务器CPU占用率过高的问题排除过程
    解决并发问题,数据库常用的两把锁(转)
  • 原文地址:https://www.cnblogs.com/Dup4/p/10348571.html
Copyright © 2020-2023  润新知