BZOJ 1416: [NOI2006]神奇的口袋 高精度
来源:互联网 发布:3tier数据 编辑:程序博客网 时间:2024/05/14 05:42
1416: [NOI2006]神奇的口袋
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 528 Solved: 332
[Submit][Status][Discuss]
Description
Input
Output
0/1,概率为1 应输出1/1。
Sample Input
input 1
2 3 1
1 1
1 1
2 2
3 1
input 2
3 1 2
1 1 1
5 1
2 3 1
1 1
1 1
2 2
3 1
input 2
3 1 2
1 1 1
5 1
Sample Output
output 1
1/12
output 2
1/3
1/12
output 2
1/3
HINT
1≤t,n≤1000, 1≤ak ,d≤10, 1≤x1
BJ又一次用分解质因数水了高精度。。。。
话说,现在代码很清真了,连register 都不用了。。。
#include<cmath>#include<ctime>#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<bitset>#include<string>#include<queue>#include<set>#include<map>using namespace std;typedef long long ll;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}void print(int x){if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}const int N=200100,rab=1000;int prime[N],pos[N],pcnt;bool book[N];void initial(){pcnt=0;for(int i=2;i<N;++i){if(!book[i])prime[++pcnt]=i,pos[i]=pcnt;for(int j=1;j<=pcnt&&prime[j]*i<N;++j){book[prime[j]*i]=1;if(i%prime[j]==0)break;}}}int num[N];inline void solve(int x,int p){for(int i=1;prime[i]<=x;++i){while(x%prime[i]==0){x/=prime[i];num[i]+=p;}if(!book[x]){num[pos[x]]+=p;return ;}}}struct bint{int a[2000];friend bint operator *(bint &x,int y){for(int i=1;i<=x.a[0];++i)x.a[i]*=y;for(int i=1;i<=x.a[0];++i)if(x.a[i]>=rab){if(i==x.a[0])x.a[0]++;x.a[i+1]+=x.a[i]/rab;x.a[i]%=rab;}return x;}friend void out(bint &x){printf("%d",x.a[x.a[0]]);for(int i=x.a[0]-1;i;i--)printf("%03d",x.a[i]);}};int a[N];int main(){initial();int n=read(),Q=read(),D=read();int sum=0;for(int i=1;i<=n;++i)a[i]=read(),sum+=a[i];while(Q--){int y=read();y=read();if(y>n){puts("0/1");return 0;}solve(sum,-1);solve(a[y],1);sum+=D;a[y]+=D;}bint son,mother;memset(son.a,0,sizeof(son.a));memset(mother.a,0,sizeof(mother.a));son.a[0]=mother.a[0]=son.a[1]=mother.a[1]=1;for(int i=1;i<=pcnt;++i)if(num[i]){if(num[i]>0){while(num[i]--)son=son*prime[i];}else {while(num[i]++)mother=mother*prime[i];}}out(son);putchar('/');out(mother);putchar('\n');return 0;}/*2 3 11 11 12 23 11/123 1 21 1 15 11/3*/
阅读全文
0 0
- BZOJ 1416: [NOI2006]神奇的口袋 高精度
- BZOJ 1416: [NOI2006]神奇的口袋 分数重载,模拟
- 【模拟】【高精度乘法】【NOI2006】神奇口袋
- bzoj1416&1498: [NOI2006]神奇的口袋
- noi2006神奇口袋
- OJ_1114 神奇的口袋
- OpenJudge_P1757 神奇的口袋
- dp 神奇的口袋
- 1114神奇的口袋
- 神奇的口袋
- 神奇的口袋
- 1757:神奇的口袋
- 神奇的口袋
- openjudge1757:神奇的口袋
- 神奇的口袋
- 题目1114:神奇的口袋
- 题目1114:神奇的口袋
- 题目1114:神奇的口袋
- Http协议详解②
- ES5数组对象的forEach, map, filter方法
- Leetcode 算法题05
- 二维数组逆序
- 栈
- BZOJ 1416: [NOI2006]神奇的口袋 高精度
- js判断文档是否存在
- Java(7-4)
- Java8 Lambda简单使用
- 判断两字符串是否互为变形词Python版
- C语言-链表建立、合并、打印
- 17112
- Query 效果函数动画
- Selenium学习笔记(FireFox插件Selenium IDE)