BZOJ 1416: [NOI2006]神奇的口袋 高精度

1416: [NOI2006]神奇的口袋

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 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

Sample Output

output 1
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 1
1 1
1 1
2 2
3 1

1/12

3 1 2
1 1 1
5 1

1/3
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值