WA求解
查看原帖
WA求解
970168
Wight_sl楼主2024/6/14 18:40
#include<bits/stdc++.h>
#include<queue>
#define IOS ios::sync_with_stdio(false)
#define CT cin.tie(NULL)
#define Ct cout.tie(NULL) 
#define f first
#define s second
#define l_queue priority_queue <int,vector<int>,greater<int> >
#define p_queue priority_queue <int>
inline void read(int& a){int s1=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}a=s*w;}
void write(int x){if(x<0) putchar('-'),x=-x;if(x>9) write(x/10);putchar(x%10+'0');}
using namespace std;
int a,s,n,ans,cnt,gys;
//通分 
int c(int x,int y,int z){
	return x*y+z;
}
int _c(int x,int y){
	return x*y;
}
signed main(){
	IOS;CT;Ct;
	read(n);
	for(int i=1;i<=n;i++){
		read(s);
		ans=1;cnt=0;
		for(int j=1;j<=s;j++){
			read(a);
			cnt=c(cnt,a,ans);
			ans=_c(ans,a);
			 //约分
			gys=__gcd(ans,cnt);
			ans/=gys;cnt/=gys;
		}
		ans*=s;
		//约分
		gys=__gcd(ans,cnt); 
		ans/=gys;
		cnt/=gys;
		printf("Case ");
		write(i);
		printf(": ");
		write(ans);
		putchar('/');
		write(cnt);
		putchar('\n');
		//这输出是真*** 
	}
    return 0;
}
2024/6/14 18:40
加载中...