Bzoj1498&1416: [NOI2006]神奇的口袋
什么鬼双倍经验题???
Sol
考虑在第\(k\)次摸到\(y\)的概率
- 如果上次摸到\(y\),目前有\(sum\)个球,\(y\)有\(a[y]\)个,那么概率就是\(\frac{a[y]+d}{sum+d}*\frac{a[y]}{sum}\)
- 如果上次没摸到\(y\),那么概率就是\(\frac{a[y]}{sum+d}*\frac{sum-a[y]}{sum}\)
合在一起就是\(\frac{a[y]}{sum}\)
那么就是直接这样写
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
const int _(2005);
typedef long long ll;
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int t, n, d, a[_], sum;
ll p1 = 1, p2 = 1;
IL ll Gcd(RG ll x, RG ll y){
return !y ? x : Gcd(y, x % y);
}
int main(RG int argc, RG char* argv[]){
t = Input(), n = Input(), d = Input();
for(RG int i = 1; i <= t; ++i) a[i] = Input(), sum += a[i];
for(RG int i = 1, y; i <= n; ++i){
Input(), y = Input();
p1 *= a[y], p2 *= sum;
sum += d, a[y] += d;
}
RG ll d = Gcd(p1, p2);
printf("%lld/%lld\n", p1 / d, p2 / d);
return 0;
}
然后显然要高精度,为防止高精度\(Gcd\)
所以可以直接分解质因数,然后乘法
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
const int _(2005);
const int __(2e5 + 1);
const int SZ(1e4);
typedef long long ll;
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int t, n, d, a[_], sum;
int prime[__], num, isprime[__];
struct Int{
int fac[__], len, a[__];
IL void Add(RG int x){
for(RG int i = 1; i <= num && prime[i] <= x; ++i)
while(!(x % prime[i])) x /= prime[i], ++fac[i];
}
IL void Mul(RG int x){
RG int ud = 0;
for(RG int i = 1; i <= len; ++i)
a[i] = a[i] * x + ud, ud = a[i] / SZ, a[i] %= SZ;
while(ud) a[++len] = ud % SZ, ud /= SZ;
}
IL void Print(){
printf("%d", a[len]);
for(RG int i = len - 1; i; --i) printf("%04d", a[i]);
}
} P1, P2;
IL void Sieve(){
isprime[1] = 1;
for(RG int i = 2; i < __; ++i){
if(!isprime[i]) prime[++num] = i;
for(RG int j = 1; j <= num && i * prime[j] < __; ++j){
isprime[i * prime[j]] = 1;
if(!(i % prime[j])) break;
}
}
}
int main(RG int argc, RG char* argv[]){
Sieve(), P1.len = P2.len = P1.a[1] = P2.a[1] = 1;
t = Input(), n = Input(), d = Input();
for(RG int i = 1; i <= t; ++i) a[i] = Input(), sum += a[i];
for(RG int i = 1, y; i <= n; ++i){
Input(), y = Input();
if(!a[y]) return puts("0/1"), 0;
P1.Add(a[y]), P2.Add(sum);
sum += d, a[y] += d;
}
for(RG int i = 1; i <= num; ++i){
if(P2.fac[i] >= P1.fac[i]) P2.fac[i] -= P1.fac[i], P1.fac[i] = 0;
else P1.fac[i] -= P2.fac[i], P2.fac[i] = 0;
for(RG int j = 1; j <= P1.fac[i]; ++j) P1.Mul(prime[i]);
for(RG int j = 1; j <= P2.fac[i]; ++j) P2.Mul(prime[i]);
}
P1.Print(), putchar('/'), P2.Print();
return puts(""), 0;
}
Bzoj1498&1416: [NOI2006]神奇的口袋的更多相关文章
- BZOJ 1416: [NOI2006]神奇的口袋( 高精度 )
把x1~xn当成是1~n, 答案是不会变的. 然后直接模拟就行了...... P.S 双倍经验... BZOJ1416 && BZOJ1498 -------------------- ...
- ●BZOJ 1416 [NOI2006]神奇的口袋
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1416题解: Pòlya瓦罐模型: 给定罐子里每种颜色的球的个数A[i],按题目要求随机操作若 ...
- 【BZOJ1416/1498】【NOI2006】神奇的口袋(数论,概率)
[BZOJ1416/1498][NOI2006]神奇的口袋(数论,概率) 题面 BZOJ1416 BZOJ1498 洛谷 题面都是图片形式是什么鬼.. 题解 考虑以下性质 1.\(x[1],x[2]. ...
- 神奇的口袋(dp)
有一个神奇的口袋,总的容积是40,用这个口袋可以变出一 些物品,这些物品的总体积必须是40. John现在有n(1≤n ≤ 20)个想要得到的物品,每个物品 的体积分别是a1,a2……an.John可 ...
- [codeup] 2044 神奇的口袋
题目描述 有一个神奇的口袋,总的容积是40,用这个口袋可以变出一些物品,这些物品的总体积必须是40.John现在有n个想要得到的物品,每个物品的体积分别是a1,a2--an.John可以从这些物品中选 ...
- dp 神奇的口袋
有一个神奇的口袋,总的容积是40,用这个口袋可以变出一 些物品,这些物品的总体积必须是40. John现在有n(1≤n ≤ 20)个想要得到的物品,每个物品 的体积分别是a1,a2--an.Joh ...
- 九度OJ 1114:神奇的口袋 (DFS、DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:948 解决:554 题目描述: 有一个神奇的口袋,总的容积是40,用这个口袋可以变出一些物品,这些物品的总体积必须是40.John现在有n个 ...
- 九度oj 题目1114:神奇的口袋
题目描述: 有一个神奇的口袋,总的容积是40,用这个口袋可以变出一些物品,这些物品的总体积必须是40.John现在有n个想要得到的物品,每个物品的体积分别是a1,a2……an.John可以从这些物品中 ...
- 百练2755:神奇的口袋(简单dp)
描述有一个神奇的口袋,总的容积是40,用这个口袋可以变出一些物品,这些物品的总体积必须是40.John现在有n个想要得到的物品,每个物品的体积分别是a1,a2……an.John可以从这些物品中选择一些 ...
随机推荐
- javascript中children,childNodes等节点属性
1.children与childNodes children: 获取子元素节点,无兼容问题 childnNodes: IE:获取子元素节点 非IE(chrome,Firefox等):获取子节点,包括元 ...
- lexical or preprocessor issue file not found in Xcode
The very last suggestion is all I needed to fix this issue. Close & re-open Xcode.
- Opencv3.0: undefined reference to cv::imread(cv::String const&, int)
使用opencv,编译出错: undefined reference to cv::imread(cv::String const&, int) 自opencv3.0之后,图像读取相关代码在i ...
- 求最大公因数(辗转相除法&更相减损术)
求最大公因数(辗转相除法&更相减损术) 辗转相除法 又名欧几里得算法 ,其原理其实是基于这个定理:\(gcd(a,b)=gcd(b,a\%b)\),详细证明,而任何数与0的最大公约数是它本身 ...
- linux rpm 安装包制作
今天的任务是把make好的install作成rpm. 3GPP 的重要性, 不必多言 例1. unpackaged if [ -z "`ps -ef|grep kamailio.pid|gr ...
- EPC sequence
nps-epc-term-2.7.0 eNodeB: /root/b2b/eutran/01/bin ./clean_log.sh ./set_ip.sh [root@CEN6- bin]# ./cl ...
- jquery ajax的getJSON使用
getJSON的定义和用法 通过 HTTP GET 请求载入 JSON 数据. 在 jQuery 1.2 中,您可以通过使用 JSONP 形式的回调函数来加载其他网域的 JSON 数据,如 " ...
- Java 的多态
1 多态的概念 多态(?) 可以理解为多种状态/多种形态 同一事物,由于条件不同,产生的结果不同 程序中的多态 同一引用类型,使用不同的实例而执行结果不同的. 同:同一个类型,一般指父类. ...
- javascript 正则表达式校验方式写法
if(/[0-9]/.test(value)){return true; } if(/[a-z]/.test(value)){return true; } if(/[A-Z]/.test(value) ...
- URL中参数为数组
今天写代码时候碰到了一个需要在URL中传递数组类型的参数,记录一下. var urlstr = "http://test"; var test = new Array(); for ...