HDU 4873 ZCC Loves Intersection(可能性)
HDU 4873 ZCC Loves Intersection
题目链接
题意:d维的。长度为n的块中,每次选d条平行于各条轴的线段,假设有两两相交则点数加1,问每次得到点数的期望是多少
思路:自己推还是差一些,转篇官方题接把,感觉自己想的没想到把分子那项拆分成几个多项式的和,然后能够转化为公式求解。
代码:
#include <cstdio>
#include <cstring>
#include <cmath>const int MAXN = 10005;struct bign {int len, num[MAXN];bign () {len = 0;memset(num, 0, sizeof(num));}bign (int number) {*this = number;}bign (const char* number) {*this = number;}void DelZero ();void Put ();void operator = (int number);void operator = (char* number);bool operator < (const bign& b) const;bool operator > (const bign& b) const { return b < *this; }bool operator <= (const bign& b) const { return !(b < *this); }bool operator >= (const bign& b) const { return !(*this < b); }bool operator != (const bign& b) const { return b < *this || *this < b;}bool operator == (const bign& b) const { return !(b != *this); }void operator ++ ();void operator -- ();bign operator + (const int& b);bign operator + (const bign& b);bign operator - (const int& b);bign operator - (const bign& b);bign operator * (const int& b);bign operator * (const bign& b);bign operator / (const int& b);//bign operator / (const bign& b);int operator % (const int& b);
};
/***************************************************/const int N = 10005;
long long n, d, prime[N], cnt[N];
int pn = 0, vis[N];
bign zi, mu;void table() {for (long long i = 2; i < N; i++) {prime[pn++] = i;for (long long j = i * i; j < N; j += i)vis[j] = 1;}
}bign qpow(long long x, long long k) {bign ans = 1;bign tmp = x;while (k) {if (k&1) ans = ans * tmp;tmp = tmp * tmp;k >>= 1;}return ans;
}void solve(long long num, long long val) {for (int i = 0; i < pn && prime[i] <= num; i++) {while (num % prime[i] == 0) {cnt[i] += val;num /= prime[i];}}if (num != 1) {if (val > 0)zi = zi * qpow(num, val);else if (val < 0)mu = mu * qpow(num, (-val));}
}int main() {table();while (~scanf("%lld%lld", &n, &d)) {zi = 1, mu = 1;memset(cnt, 0, sizeof(cnt));solve(d * (d - 1) / 2, 1);solve(n + 4, 2);solve(3, -2);solve(n, -d);for (int i = 0; i < pn; i++) {if (cnt[i] > 0)zi = zi * qpow(prime[i], cnt[i]);else if (cnt[i] < 0)mu = mu * qpow(prime[i], (-cnt[i]));}zi.Put();if (mu != 1) {printf("/");mu.Put();}printf("\n");}return 0;
}/*********************************************/
void bign::DelZero () {while (len && num[len-1] == 0)len--;if (len == 0) {num[len++] = 0;}
}void bign::Put () {for (int i = len-1; i >= 0; i--) printf("%d", num[i]);
}void bign::operator = (char* number) {len = strlen (number);for (int i = 0; i < len; i++)num[i] = number[len-i-1] - '0';DelZero ();
}void bign::operator = (int number) {len = 0;while (number) {num[len++] = number%10;number /= 10;}DelZero ();
}bool bign::operator < (const bign& b) const {if (len != b.len)return len < b.len;for (int i = len-1; i >= 0; i--)if (num[i] != b.num[i])return num[i] < b.num[i];return false;
}void bign::operator ++ () {int s = 1;for (int i = 0; i < len; i++) {s = s + num[i];num[i] = s % 10;s /= 10;if (!s) break;}while (s) {num[len++] = s%10;s /= 10;}
}void bign::operator -- () {if (num[0] == 0 && len == 1) return;int s = -1;for (int i = 0; i < len; i++) {s = s + num[i];num[i] = (s + 10) % 10;if (s >= 0) break;}DelZero ();
}bign bign::operator + (const int& b) {bign a = b;return *this + a;
}bign bign::operator + (const bign& b) {int bignSum = 0;bign ans;for (int i = 0; i < len || i < b.len; i++) {if (i < len) bignSum += num[i];if (i < b.len) bignSum += b.num[i];ans.num[ans.len++] = bignSum % 10;bignSum /= 10;}while (bignSum) {ans.num[ans.len++] = bignSum % 10;bignSum /= 10;}return ans;
}bign bign::operator - (const int& b) {bign a = b;return *this - a;
}bign bign::operator - (const bign& b) {int bignSub = 0;bign ans;for (int i = 0; i < len || i < b.len; i++) {bignSub += num[i];bignSub -= b.num[i];ans.num[ans.len++] = (bignSub + 10) % 10;if (bignSub < 0) bignSub = -1;}ans.DelZero ();return ans;
}bign bign::operator * (const int& b) {long long bignSum = 0;bign ans;ans.len = len;for (int i = 0; i < len; i++) {bignSum += (long long)num[i] * b;ans.num[i] = bignSum % 10;bignSum /= 10;}while (bignSum) {ans.num[ans.len++] = bignSum % 10;bignSum /= 10;}return ans;
}bign bign::operator * (const bign& b) {bign ans;ans.len = 0; for (int i = 0; i < len; i++){ int bignSum = 0; for (int j = 0; j < b.len; j++){ bignSum += num[i] * b.num[j] + ans.num[i+j]; ans.num[i+j] = bignSum % 10; bignSum /= 10;} ans.len = i + b.len; while (bignSum){ ans.num[ans.len++] = bignSum % 10; bignSum /= 10;} } return ans;
}bign bign::operator / (const int& b) {bign ans;int s = 0;for (int i = len-1; i >= 0; i--) {s = s * 10 + num[i];ans.num[i] = s/b;s %= b;}ans.len = len;ans.DelZero ();return ans;
}int bign::operator % (const int& b) {bign ans;int s = 0;for (int i = len-1; i >= 0; i--) {s = s * 10 + num[i];ans.num[i] = s/b;s %= b;}return s;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
转载于:https://www.cnblogs.com/zfyouxi/p/4655795.html
HDU 4873 ZCC Loves Intersection(可能性)相关推荐
- HDU 4873 ZCC Loves Intersection(JAVA、大数、推公式)
在一个D维空间,只有整点,点的每个维度的值是0~n-1 .现每秒生成D条线段,第i条线段与第i维度的轴平行.问D条线段的相交期望. 生成线段[a1,a2]的方法(假设该线段为第i条,即与第i维度的轴平 ...
- hdu 4876 ZCC loves cards(暴力)
题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...
- hdu 4882 ZCC Loves Codefires(数学题+贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ZCC Loves Codefires Time Limit: 2000/1000 MS (Ja ...
- HDU 5228 ZCC loves straight flush( BestCoder Round #41)
题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5230 ZCC loves hacking(DP)
Problem Description Now, a Codefires round is coming to end. ZCC has got C(0≤C≤106) points by solvin ...
- HDU 4879 ZCC loves march (并查集,set,map)
题面以及思路:https://blog.csdn.net/glqac/article/details/38402101 代码: #include <bits/stdc++.h> #defi ...
- hdu 5230 ZCC loves hacking
刚开始滚动数组错了 #include <iostream> #include <algorithm> #include <cstring> #include < ...
- HDOJ 4876 ZCC loves cards
枚举组合,在不考虑连续的情况下推断能否够覆盖L...R,对随机数据是一个非常大的减枝. 通过检測的暴力计算一遍 ZCC loves cards Time Limit: 4000/2000 MS (Ja ...
- ZCC loves cube(cube)
ZCC loves cube(cube) 题目描述 调戏完了狗,ZCC开始玩起了积木.ZCC的面前有一块n*n的棋盘,他要用这些1*1*1的积木在棋盘上搭出一个宏伟的建筑.积木有三种颜色,ZCC认为一 ...
最新文章
- linux 下oracle 的kernel.shmmax,Linux 下kernel.shmmax 的设置问题
- No such file or directory: jupyter-1.0.0.dist-info\\METADATA
- C#访问SQLServer增删改查代码实例
- C/C++通用Makefile
- sql 过滤空值_SQL 编程思想:一切皆关系!
- noip2017提高组初赛c语言,NOIP2017提高组比赛体验篇一(干货)
- ncm在线转换mp3格式
- ppt(office365)之表格使用说明
- app小程序手机端Python爬虫实战11实现自动化登录考研帮app并滑动资讯信息
- php邮箱必填,discuz关闭邮箱注册必填选项
- 看雪CTF.TSRC 2018 团队赛 第二题 半加器 writeup
- 25分钟破亿 首销火爆的moto edge X30给友商们出了个难题
- 大华摄像头网页端控制+web串口(适用任何浏览器,不能用来打我)通讯合集
- Cardano(ADA), EOS, RChain(RHOC), Aeternity(AE) 都是极其好的币
- 爬取西瓜视频影视分类
- 大型欧姆龙PLC NJ系列ST语言Ethercat总线24轴 伺服电池生产线欧姆龙PLC程序大型程序NJ系列
- 破解验证码(2)滑动验证码
- 学长冷月带你怒刷LeetCode之反转链表
- 土地利用现状分类统计表生成
- 首席新媒体黎想教程:抖音代运营服务流程详解
热门文章
- Flutter 项目开发指导 从基础入门到精通使用目录
- React 的 Hello World
- inotify和epoll
- Category类别、继承
- 安装pycharm软件后,打开robot framework怎么默认用pycharm打开
- 一周总结汇总_2016-09-18
- Excel 导入 Sql Server出错——“文本被截断,或者一个或多个字符在目标代码页中没有匹配项”错误的解决...
- 【转】矩阵十大经典题目
- hdu 2188巴什博弈
- 豆米--基于豆瓣API的WP7书籍搜索工具开源啦!