栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3411 Special Special Judge

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3411 Special Special Judge

#include <iostream>#include <vector>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <queue>#include <map>#include <cmath>using namespace std;class bigInt{public: int num[302], len; bigInt(){num[0]=0,len=0;} bigInt operator=(const long long &a) { long long tmp = a; len = 0; while (tmp) num[len++] = tmp % 10, tmp /= 10; if (!len) num[0] = 0, len = 1; } bigInt(const long long &a) { long long tmp = a; len = 0; while (tmp) num[len++] = tmp % 10, tmp /= 10; if (!len) num[0] = 0, len = 1; } bool operator<(const bigInt &a) { if (a.len != len) return len < a.len; for (int i = len - 1; i >= 0; i--) if (num[i] != a.num[i]) return num[i] < a.num[i]; return false; } bool operator>(const bigInt &a) { if (a.len != len) return len > a.len; for (int i = len - 1; i >= 0; i--) if (num[i] != a.num[i]) return num[i] > a.num[i]; return false; } bigInt operator+(const bigInt &a) { bigInt res; int i, j, c = 0, adda, addb; for (i = 0, j = 0; i < len || j < a.len || c; ) { adda = 0, addb = 0; if (i < len) adda = num[i++]; if (j < a.len) addb = a.num[j++]; res.num[res.len++] = (adda + addb + c) % 10; c = (adda + addb + c) / 10; } return res; } bigInt operator-(const bigInt &b) { bigInt res; int i, j, c = 0, suba, subb; for (i = 0, j = 0; i < len || j < b.len || c; ) { suba = 0, subb = 0; if (i < len) suba = num[i++]; if (j < b.len) subb = b.num[j++]; res.num[res.len++] = (suba - subb + c + 10) % 10; c = (suba - subb + c + 10) / 10 - 1; } for (i = res.len - 1; i > 0; i--) if (res.num[i]) break; res.len = i + 1; return res; } bigInt operator*(const bigInt &b) { bigInt res; int i, j, c, now, mulb, tmp; memset(res.num, 0, sizeof(int) * (len + b.len)); for (i = 0; i < len; i++) { now = i, c = 0; for (j = 0; j < b.len || c; ) { mulb = 0; if (j < b.len) mulb = b.num[j++]; tmp = res.num[now] + num[i] * mulb + c; res.num[now++] = tmp % 10; c = tmp / 10; } } for (i = len + b.len - 1; i > 0; i--) if (res.num[i]) break; res.len = i + 1; return res; } bigInt operator/(const bigInt &b) { bigInt res, diva; int i, j, c; for (i = len - 1; i >= 0; i--) { if (diva.len > 1 || diva.num[0]) { for (j = diva.len - 1; j >= 0; j--) diva.num[j + 1] = diva.num[j]; diva.len++; } diva.num[0] = num[i]; if (!diva.len) diva.len = 1; res.num[i] = 0; while (!(diva < b)) diva = diva - b, res.num[i]++; } for (i = len - 1; i > 0; i--) if (res.num[i]) break; res.len = i + 1; return res; } bigInt operator%(const bigInt &b) { bigInt res, diva; int i, j, c; for (i = len - 1; i >= 0; i--) { if (diva.len > 1 || diva.num[0]) { for (j = diva.len - 1; j >= 0; j--) diva.num[j + 1] = diva.num[j]; diva.len++; } diva.num[0] = num[i]; if (!diva.len) diva.len = 1; res.num[i] = 0; while (!(diva < b)) diva = diva - b, res.num[i]++; } for (i = diva.len - 1; i > 0; i--) if (diva.num[i]) break; diva.len = i + 1; return diva; } void display() { int i; for (i = len - 1; i > 1; i--) if (num[i]) break; for (; i >= 0; i--) printf("%d", num[i]); }};int n,m,a,b,x[10001];bigInt dp[51][51];bigInt ans;bigInt tot;bigInt A,B;bigInt gcd(bigInt a,bigInt b){ bigInt r; while(b>0) { r=a%b; a=b; b=r; } return a;}int main(int argc, char const *argv[]){ for(int i=0;i<=50;i++) dp[0][i]=0; while(scanf("%d%d%d%d",&n,&m,&a,&b)!=EOF) { dp[0][0]=1; B=b; A=a; tot=1; for(int i=1;i<=n;i++) tot=tot*(B-A+1); ans=0; for(int i=1;i<=n;i++) { scanf("%d",&x[i]); for(int j=0;j<=m;j++) { dp[i][j]=0; for(int l=a;l<=b;l++) { if(j-abs(l-x[i])>=0) dp[i][j]=dp[i][j]+dp[i-1][j-abs(l-x[i])]; } if(i==n) ans=ans+dp[i][j]; } } bigInt ***=gcd(ans,tot); ans=ans/***;; tot=tot/***; ans.display(); printf("/"); tot.display(); puts(""); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379588.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号