zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    面对苹果的抄袭指责,小米到底有没有抄袭?
    如何用Ajax传一个数组数据
    为何日本人如此重视孩子的早餐问题
    常见编程语言对REPL支持情况小结
    坚持未必都是美德,也可能是无知
    PHP 5.4语法改进与弃用特性
    解决CI框架的Disallowed Key Characters错误提示
    如何抓取开了gzip的网页
    CodeIgniter自带的数据库类使用介绍
    Python内部变量与外部变量
  • 原文地址:https://www.cnblogs.com/Dup4/p/10348571.html
Copyright © 2011-2022 走看看