码迷,mamicode.com
首页 > 其他好文 > 详细

小椛椛的板子们

时间:2017-11-05 17:26:16      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:tchar   line   struct   res   getc   while   cas   fwrite   bsp   

 

实在不愿意再做题了,这几天写写板子。

 

Lucas

 

#include <cstdio>
#include <iostream>
#define rg register
inline void read (long long &n)
{
    rg char c = getchar ();
    for (n = 0; !isdigit (c); c = getchar ());
    for (; isdigit (c); n = n * 10 + c - 0, c = getchar ());
}
#define Max 1213231
typedef long long LL; LL fac[Max];
LL Pow (LL x, LL p, LL mo)
{
    LL a = x, res = 1;
    for (; p; p >>= 1, a *= a, a %= mo)
        if (p & 1) res *= a, res %= mo;
    return res % mo;
}
LL C (LL N, LL M, LL p) 
{ return M > N ? 0 : ((fac[N] * Pow (fac[M], p - 2, p)) % p * Pow (fac[N - M], p - 2, p) % p); }
LL Lucas (LL N, LL M, LL P) 
{ return !M ? 1 : (C (N % P, M % P, P) * Lucas (N / P, M / P, P)) % P; }
int main (int argc, char *argv[])
{
    LL T, x, y, p, L; read (T); rg int i;
    for (fac[0] = 1; T; -- T)
    {
        read (x), read (y), read (p);
        for (i = 1; i <= p; ++ i) fac[i] = fac[i - 1] * i, fac[i] %= p;
        printf ("%lld\n", Lucas (x + y, x, p));
    }
    return 0;
}

 

快速排序

虽然说不让用sort,但是我这种懒癌晚期的人怎么可能去手写sort呢?【其实是不会写

觉得过意不去,就写了快读和快输

#include <cstdio>
#include <iostream>
#include <algorithm>
struct io
{
    static const int BUF = 12310330;
    char p[BUF], *s, e[BUF], *t; int a[24];
    io () : s(p), t(e) { fread (s, 1, sizeof p, stdin); }
    ~io () { fwrite (e, 1, t - e, stdout); }
    operator int()
    {
        static int v,j;
        v = 0,j = 1;
        for (v = 0, j = 1; *s < 48; j = *s++ ^ 45);
        do v = v * 10 + *s++ - 48; while (*s > 32);
        return j ? v : -v;
    }
    void print(int v)
    {
        static int *q = a;
        if (!v) *t++ = 48;
        else
        {
            if (v < 0) *t++ = 45, v *= -1;
            for (; v; *q++ = v % 10 + 48, v /= 10);
            for (; q != a; *t++ = *--q);
        }
        *t++ = 32;
    }
} ip;
#define Max 100007
int a[Max]; 
int main (int argc, char *argv[])
{
#define rg register
    int N = ip; rg int i;
    for (i = 1; i <= N; ++ i) a[i] = ip;
    std :: sort (a + 1, a + 1 + N);
    for (i = 1; i <= N; ++ i) ip.print (a[i]);
    return 0;
}

 

小椛椛的板子们

标签:tchar   line   struct   res   getc   while   cas   fwrite   bsp   

原文地址:http://www.cnblogs.com/ZlycerQan/p/7787777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!