标签:style blog http color io os ar for sp
1 //Accepted 1688 KB 0 ms 2 //概率简单题 3 //假设我们在n个门前加个起点,在n个门后加个终点,起点可以到达n个门, 4 //为正的门可以到达终点,为负的回到起点 5 //则假设我们从起点到终点的期望时间为e 6 //那么e=1/n*sum(x1)+1/n*sum((x2+e)) ,x1>0 x2<0 7 //两边同时乘n后,化简即可 8 #include <cstdio> 9 #include <cstring> 10 #include <iostream> 11 #include <queue> 12 #include <cmath> 13 #include <algorithm> 14 using namespace std; 15 /** 16 * This is a documentation comment block 17 * 如果有一天你坚持不下去了,就想想你为什么走到这儿! 18 * @authr songt 19 */ 20 21 int gcd(int a,int b) 22 { 23 if (b==0) return a; 24 return gcd(b,a%b); 25 } 26 int sum; 27 int n; 28 int x; 29 int num; 30 int main() 31 { 32 int T; 33 int t=0; 34 scanf("%d",&T); 35 while (T--) 36 { 37 scanf("%d",&n); 38 sum=0; 39 num=0; 40 for (int i=0;i<n;i++) 41 { 42 scanf("%d",&x); 43 sum+=abs(x); 44 if (x>0) num++; 45 } 46 printf("Case %d: ",++t); 47 if (num==0) 48 { 49 printf("inf\n"); 50 continue; 51 } 52 int d=gcd(sum,num); 53 printf("%d/%d\n",sum/d,num/d); 54 } 55 return 0; 56 }
标签:style blog http color io os ar for sp
原文地址:http://www.cnblogs.com/djingjing/p/4003029.html