Advertisement
Guest User

s11

a guest
Jul 13th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 2.95 KB | None | 0 0
  1. \documentclass[a4paper]{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage{url}
  4. \usepackage{minted}
  5. \usepackage{graphicx}
  6.  
  7. \title{UAP Training}
  8. \author{Rafid Bin Mostofa}
  9. \date{July 13, 2019}
  10.  
  11. \begin{document}
  12.  
  13. \maketitle
  14. \hline
  15. \tableofcontents
  16. \pagebreak
  17.  
  18. \section{Chinese Remainder Theorem}
  19. This is a good source: \url{https://cp-algorithms.com/algebra/chinese-remainder-theorem.html} \\
  20. \subsection{Problems}
  21. \begin{itemize}
  22.    \item \url{http://www.lightoj.com/volume_showproblem.php?problem=1319} [\ref{code:monkey}]
  23.    \item RUET 2019 A
  24. \end{itemize}
  25.  
  26. \section{Flow}
  27.  
  28. \subsection{Maximum Flow}
  29. \begin{figure}[h]
  30.    \centering
  31.    \includegraphics{maxflow}
  32.    \label{fig:my_label}
  33. \end{figure}
  34.  
  35.  
  36. \begin{itemize}
  37.    \item \url{https://www.topcoder.com/community/competitive-programming/tutorials/maximum-flow-section-1/}
  38.    \item \url{https://www.topcoder.com/community/competitive-programming/tutorials/maximum-flow-section-2/}
  39. \end{itemize}
  40. Problems: \url{http://www.lightoj.com/volume_problemcategory.php?user_id=29559&category=Max%20Flow/Min%20Cut}
  41.  
  42. \subsection{Min Cost Max Flow}
  43. Source: \url{https://cp-algorithms.com/graph/min_cost_flow.html} \\ \\
  44. Problems: \url{http://www.lightoj.com/volume_problemcategory.php?user_id=29559&category=Min%20Cost%20Max%20Flow} \\
  45. Another Problem: \url{https://toph.co/p/alice-loves-to-play-game}
  46.  
  47. \subsection{Bipartite Matching}
  48. \begin{itemize}
  49.    \item Hopcroft Karp
  50.    \item Kuhn
  51.    \item Hungarian (Weighted)
  52. \end{itemize}
  53.  
  54. \pagebreak
  55. \section{APPENDIX}
  56. \subsection{LightOJ 1319 - Monkey Tradition}
  57. \label{code:monkey}
  58.  
  59. \begin{minted}{cpp}
  60. #include <bits/stdc++.h>
  61. using namespace std;
  62.  
  63. typedef pair<long long, long long> pll;
  64. #define ff first
  65. #define ss second
  66.  
  67. pll extendedEuclid(int a, int b) { // returns x, y | ax + by = gcd(a,b)
  68.     if(b == 0) return pll(1, 0);
  69.     else {
  70.         pll d = extendedEuclid(b, a % b);
  71.         return pll(d.ss, d.ff - d.ss * (a / b));
  72.     }
  73. }
  74.  
  75. long long modInv(int a, long long p) {
  76.     pll ret = extendedEuclid(a, p);
  77.     return ((ret.ff % p) + p) % p;
  78. }
  79.  
  80. unsigned long long crt(vector<int> &rem, vector<int> &mod) {
  81.     assert(rem.size() == mod.size());
  82.    
  83.     unsigned long long ret = 0;
  84.     int n = rem.size();
  85.  
  86.     unsigned long long MOD = 1;
  87.     for(int i=0; i<n; ++i) MOD *= mod[i];
  88.  
  89.     // you shouldn't run a n^2 loop inside crt
  90.     // this case was exceptional and
  91.     // the programmer was too lazy to optimize
  92.     for(int i=0; i<n; ++i) {
  93.         long long cur = rem[i];
  94.         for(int j=0; j<n; ++j) {
  95.             if(i == j) continue;
  96.             cur = (cur * mod[j]);
  97.             cur = (cur * modInv(mod[j], mod[i]));
  98.             cur %= MOD;
  99.         }
  100.         ret = (ret + cur) % MOD;
  101.     }
  102.  
  103.     return ret;
  104. }
  105.  
  106. int main() {
  107.     int t, tc=0;
  108.     scanf("%d", &t);
  109.  
  110.     while(t--) {
  111.         int n;
  112.         scanf("%d", &n);
  113.         vector<int> rem(n), mod(n);
  114.         for(int i=0; i<n; ++i) cin >> mod[i] >> rem[i];
  115.  
  116.         unsigned long long res = crt(rem, mod);
  117.         printf("Case %d: %llu\n", ++tc, res);
  118.     }
  119.  
  120.     return 0;
  121. }
  122. \end{minted}
  123. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement