求一个100到300行之间的c++程序!方向不限,有必要的注释!希望不要去网上复制粘贴,多谢了!这
求一个100到300行之间的c++程序!方向不限,有必要的注释!希望不要去网上复制粘贴,多谢了!这已经是我第四次发布这个问题了!心里很不是滋味。希望有靠谱的人帮忙,多谢了...
求一个100到300行之间的c++程序!方向不限,有必要的注释!希望不要去网上复制粘贴,多谢了!这已经是我第四次发布这个问题了!心里很不是滋味。希望有靠谱的人帮忙,多谢了!
展开
1个回答
展开全部
#include <bits/stdc++.h>
using namespace std;
const int N = 108, mod = 1e9 + 7;
int n, T;
long long power(long long x, int q) {
long long r = 1;
while (q) {
if (q & 1) r = r * x % mod;
q >>= 1; x = x * x % mod;
}
return r;
}
long long gcd(long long a, long long b)
{return b ? gcd(b, a % b) : a;}
struct fact {
long long a, b;
fact(long long a = 0, long long b = 1) :
a((a + mod) % mod), b((b + mod) % mod) {}
fact operator +=(const fact &o) {
long long g = gcd(b, o.b), k1 = b / g, k2 = o.b / g;
b = b * k2 % mod; a = (a * k2 + o.a * k1) % mod;
return *this;
}
fact operator +(const fact &o) const
{fact r = *this; return r += o;}
fact operator -=(const fact &o) {
long long g = gcd(b, o.b), k1 = b / g, k2 = o.b / g;
b = b * k2 % mod; a = ((a * k2 - o.a * k1) % mod + mod) % mod;
return *this;
}
fact operator -(const fact &o) const
{fact r = *this; return r -= o;}
fact operator *=(const fact &o)
{a = a * o.a % mod; b = b * o.b % mod; return *this;}
fact operator *(const fact &o) const
{fact r = *this; return r *= o;}
fact operator /=(const fact &o) {
if (!o.a || !o.b) exit(1);
a = a * o.b % mod, b = b * o.a % mod; return *this;
}
fact operator /(const fact &o) const
{fact r = *this; return r /= o;}
} a[N][N], f[N];
struct point {
int k, o; fact p;
point() {}
point(int k, int o, int a, int b) :
k(k), o(o), p(fact(a, b)) {}
void input() {
int a, b; char opt[2];
scanf("%s%d%d%d", opt, &o, &a, &b);
p = fact(a, b); k = (opt[0] == 'X');
}
} p[N];
void gauss() {
int t = n + 1;
for (int i = 0; i < t; i++)
for (int j = i + 1; j < t; j++) {
fact p = a[j][i] / a[i][i];
for (int k = t; k >= i; k--)
a[j][k] -= a[i][k] * p;
}
for (int i = t - 1; i >= 0; i--) {
f[i] = a[i][t] / a[i][i];
for (int j = i - 1; j >= 0; j--)
a[j][t] -= f[i] * a[j][i];
}
}
int main() {
freopen("azelso.in", "r", stdin);
freopen("azelso.out", "w", stdout);
scanf("%d%d", &T, &n);
for (int i = 1; i <= n; i++)
p[i].input();
p[++n] = point(0, T, 1, 1);
p[0] = point(0, 0, 1, 1);
for (int i = 0; i < n; i++) {
a[i][i] += fact(-1, 1);
if (!p[i + 1].k)
a[i][i + 1] += fact(1, 1), a[i][n + 1] += fact(p[i].o - p[i + 1].o, 1);
else {
a[i][i + 1] += p[i + 1].p, a[i][n + 1] += fact(p[i].o - p[i + 1].o, 1) * p[i + 1].p;
fact cur = fact(1, 1) - p[i + 1].p;
for (int j = i; j >= 0; j--)
if (!p[j].k) {
a[i][j] += cur * p[j].p; a[i][n + 1] += fact(p[i].o - p[i + 1].o, 1) * cur * p[j].p;
cur -= cur * p[j].p;
}
}
}
a[n][n] = fact(1, 1); a[n][n + 1] = fact(0, 1);
gauss();
cout << f[0].a * power(f[0].b, mod - 2) % mod << endl;
fclose(stdin); fclose(stdout);
return 0;
}
追问
能运行吗?
第一行为什么要这样写
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询