zoukankan      html  css  js  c++  java
  • "巴卡斯杯" 中国大学生程序设计竞赛

    Participants of the Luck Competition choose a non-negative integer no more than 100 in their mind. After choosing their number, let KK be the average of all numbers, and MM be the result of K×23K×23. Then the lucky person is the one who choose the highest number no more than MM. If there are several such people, the lucky person is chosen randomly. 

    If you are given a chance to know how many people are participating the competition and what their numbers are, calculate the highest number with the highest probability to win assuming that you're joining the competition. 

    Input

    There are several test cases and the first line contains the number of test cases T(T≤10)T(T≤10). 

    Each test case begins with an integer N(1<N≤100)N(1<N≤100), denoting the number of participants. And next line contains N−1N−1 numbers representing the numbers chosen by other participants. 
     

    Output

    For each test case, output an integer which you have chosen and the probability of winning (round to two digits after the decimal point), seperated by space. 
     

    Sample Input

    3
    4
    1 2 3
    4
    1 1 2
    4
    20 30 40

    Sample Output

    1 0.50
    0 1.00
    18 1.00
    #include<iostream>
    using namespace std;
    int a[1000]; 
    int main()
    {
    	int n,m,j,k,i,T;
    	cin>>T;
    	while (T--)
    	{
    		int sum=0;
    		scanf("%d",&n);
    		for (i=0;i<n-1;i++)
    		{
    			cin>>a[i];
    			sum+=a[i];
    		}
    			
    		int SUM=1;
    		int ans = (double)2.0*sum/(3.0*n-2.0);
    		for (i=0;i<n-1;i++)
    		{
    			if (a[i]==ans)
    			SUM++;
    		}
    		double ANS = 1.0/double(SUM);
    		printf("%d %.2lf
    ",ans,ANS);
    	}
    	
    	return 0;
     } 
  • 相关阅读:
    实现LNMP
    iptabes的用法
    实现LAMP
    实现https
    硬盘信息和磁盘分区管理
    awk
    【BZOJ 2288】 2288: 【POJ Challenge】生日礼物 (贪心+优先队列+双向链表)
    【BZOJ 1150】 1150: [CTSC2007]数据备份Backup (贪心+优先队列+双向链表)
    【BZOJ 1216】 1216: [HNOI2003]操作系统 (模拟+优先队列)
    【BZOJ 1528】 1528: [POI2005]sam-Toy Cars (贪心+堆)
  • 原文地址:https://www.cnblogs.com/Romantic-Chopin/p/12451354.html
Copyright © 2011-2022 走看看