题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1416
解法:话说这个题目鬼畜了吧,神坑啊。我很快写完交上去wa了,实在改不出来,自己写了数据生成器想和网上的ac代
码拍一下,拍了大概10组随机数据发现答案完全一样啊,这能WA??? 想了很久,乱几把改了改还是WA??? 怒交了一发
网上的ac代码??? 返回WA??? 这数据出问题了吧。。。。
附上代码和数据生成器
//BZOJ 1416
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50010;
typedef long long LL;
struct Fraction{
LL a, b; //a代表分子,b代表分母
Fraction(){
a = 0; b = 1;
}
void reduction(){
if(a == 0){
b = 1;
return;
}
LL gcdnum = __gcd(a, b);
a /= gcdnum;
b /= gcdnum;
}
Fraction(LL num){ //整数
a = num; b = 1;
}
Fraction(LL x, LL y){
a = x, b = y;
this->reduction();
}
void operator = (const LL &num){
a = num; b = 1;
this -> reduction();
}
void operator = (const Fraction &y){
a = y.a; b = y.b;
this -> reduction();
}
Fraction operator + (const Fraction &y) const{
LL gcdnum = __gcd(b, y.b);
Fraction tmp = Fraction(a * (y.b / gcdnum) + y.a * (b / gcdnum) , b / gcdnum * y.b);
tmp.reduction();
return tmp;
}
Fraction operator + (const LL &y) const{
return ((*this) + Fraction(y));
}
Fraction operator - (const Fraction &y) const{
return ((*this) + Fraction(-y.a, y.b));
}
Fraction operator - (const LL &y) const{
return ((*this) - Fraction(y));
}
Fraction operator * (const Fraction &y) const{
Fraction tmp = Fraction(a * y.a, b * y.b);
tmp.reduction();
return tmp;
}
Fraction operator / (const Fraction &y) const{
return ((*this) * Fraction(y.b, y.a));
}
void print(){
printf("%lld/%lld\n",a,b);
}
};
int t, n, d, x, y;
long long tot;
int a[maxn];
int main(){
//freopen("1.txt", "r", stdin);
//freopen("1.out", "w", stdout);
Fraction aa;
tot = 0;
aa=(1,1);
scanf("%d%d%d", &t,&n,&d);
for(int i=1; i<=t; i++){
scanf("%d", &a[i]);
tot+=1LL*a[i];
}
while(n--){
long long x,y;
scanf("%lld%lld",&x,&y);
aa = aa*Fraction(a[y], tot);
tot+=d;
a[y]+=d;
}
aa.print();
return 0;
}
数据生成器:
#include <bits/stdc++.h>
using namespace std;
int main()
{
//freopen("1.txt", "w", stdout);
//int t, n, d;
srand(time(NULL));
int t = rand()%1000;
if(t==0) t=1;
int n = rand()%1000;
if(n==0) n=10;
int d=rand()%10;
if(d==0) d=2;
printf("%d %d %d\n", t, n, d);
for(int i = 0; i < t; i++){
int x = rand()%t;
if(x==0) x=1;
printf("%d%c",x,i==n-1?'\n':' ');
}
for(int i=1; i<=n; i++){
int x = rand()%t;
if(x==0) x=1;
printf("%d %d\n", i, x);
}
return 0;
}