From 0145e378f09cd9939e72fb3fed2fd27ae2ba13c8 Mon Sep 17 00:00:00 2001 From: TooYoungTooSimp <6648049+TooYoungTooSimp@users.noreply.github.com> Date: Sun, 4 Dec 2016 12:35:57 +0800 Subject: [PATCH] bzoj 1005 1211 1867 --- OnlineJudges/lydsy/1005.py | 41 +++++++++++++++++++++++ OnlineJudges/lydsy/1211.cpp | 66 +++++++++++++++++++++++++++++++++++++ OnlineJudges/lydsy/1867.cpp | 52 +++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 OnlineJudges/lydsy/1005.py create mode 100644 OnlineJudges/lydsy/1211.cpp create mode 100644 OnlineJudges/lydsy/1867.cpp diff --git a/OnlineJudges/lydsy/1005.py b/OnlineJudges/lydsy/1005.py new file mode 100644 index 0000000..6e04116 --- /dev/null +++ b/OnlineJudges/lydsy/1005.py @@ -0,0 +1,41 @@ +def fast_pow(a,b): + ans=1 + while b: + if(b%2==1): + ans*=a + a*=a + b/=2 + return ans +frac=[1] +for i in range(1,1001): + frac.append(i*frac[-1]) +n=(int)(input()) +m=0 +arr=[] +for i in range(0,n): + arr.append((int)(input())) +ans=0 +if n==1: + if arr[0]==0: + ans=1 + else: + ans=0 +else: + ans=frac[n-2] + left=n-2 + for i in arr: + if i == -1: + m+=1 + elif i==0: + ans=0 + left=0 + break + else: + ans/=frac[i-1] + left-=i-1 + if m<2: + ans=0 + else: + ans/=frac[left] + ans*=fast_pow(m,left) +print ans \ No newline at end of file diff --git a/OnlineJudges/lydsy/1211.cpp b/OnlineJudges/lydsy/1211.cpp new file mode 100644 index 0000000..eca749f --- /dev/null +++ b/OnlineJudges/lydsy/1211.cpp @@ -0,0 +1,66 @@ +#include +typedef long long int64; +int prime[201], pcnt, cnt[201]; +bool notprime[1001]; +void genPrime() +{ + notprime[0] = notprime[1] = true; + for (int i = 2; i < 1001; i++) + if (!notprime[i]) + for (int j = i*i; j < 1001; j += i) + notprime[j] = true; + for (int i = 0; i < 1001; i++) + if (!notprime[i]) + prime[pcnt++] = i; +} +int64 fast_pow(int64 x, int y) +{ + int64 ans = 1; + for (; y; x *= x, y >>= 1) + if (y & 1) + ans *= x; + return ans; +} +void decomp(int x, int d) +{ + for (int i = 0; i < pcnt && x; i++) + while (x % prime[i] == 0) + { + cnt[i] += d; + x /= prime[i]; + } +} +int64 comp() +{ + int64 ans = 1; + for (int i = 0; i < pcnt; i++) + if (cnt[i]) + ans *= fast_pow(prime[i], cnt[i]); + return ans; +} +int main() +{ + genPrime(); + int n, sum = 0; + scanf("%d", &n); + if (n == 1) + { + scanf("%d", &n); + putchar('0' + !n); + } + else + { + for (int i = 2; i <= n - 2; i++) + decomp(i, 1); + for (int i = 0, x; i < n; i++) + { + scanf("%d", &x); + if (x == 0) break; + sum += x - 1; + for (int j = 2; j < x; j++) + decomp(j, -1); + } + printf("%lld", sum != n - 2 ? 0 : comp()); + } + return 0; +} \ No newline at end of file diff --git a/OnlineJudges/lydsy/1867.cpp b/OnlineJudges/lydsy/1867.cpp new file mode 100644 index 0000000..5169295 --- /dev/null +++ b/OnlineJudges/lydsy/1867.cpp @@ -0,0 +1,52 @@ +#include +#include +typedef unsigned long long int64; +inline int64 gcd(int64 a, int64 b) +{ + int64 tmp; + if (a < b) { tmp = a; a = b; b = tmp; } //make sure a>b + while (b) + { + tmp = b; + b = a%b; + a = tmp; + } + return a; +} +int64 a[51][51]; +char c[51][51]; +int n, m; + +void calc(int i, int j) +{ + if (j > i || i >= n) return; + else + { + if (c[i][j] == '*') + { + a[i + 1][j] += (a[i][j] / 2); + a[i + 1][j + 1] += (a[i][j] / 2); + } + else if (c[i][j] == '.') + { + a[i + 2][j + 1] += a[i][j]; + } + else return; + } +} + +int main() +{ + scanf("%d%d", &n, &m); + int64 total = (1ULL << n); + for (int i = 0; i < n; i++) + for (int j = 0; j <= i; j++) + std::cin >> c[i][j]; + a[0][0] = total; + for (int i = 0; i < n; i++) + for (int j = 0; j <= i; j++) + calc(i, j); + int64 k = gcd(a[n][m], total); + printf("%lld/%lld", a[n][m] / k, total / k); + return 0; +}