B. Help Chef Gerasim

B. Help Chef Gerasim
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.

To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.

Input

The first line contains integer n — the number of cups on the royal table (1 ≤ n ≤ 1000). Next n lines contain volumes of juice in each cup — non-negative integers, not exceeding 104.

Output

If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).

Sample test(s)
input
5
270
250
250
230
250
output
20 ml. from cup #4 to cup #1.
input
5
250
250
250
250
250
output
Exemplary pages.
input
5
270
250
249
230
250
output
Unrecoverable configuration.
水题一道,题目大概意思是有一个侍从很顽皮,他把1-n个杯子果汁其中一杯倒进另外一杯中叫你求出是哪个杯子倒入哪个杯子并且倒了多少,不过如果侍从倒了多次或者果汁不能平均分就输出 Unrecoverable configuration.如果侍从没有顽皮即每个杯子的柜子一样多久输出 Exemplary pages.
AC代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>
const int MAX=1001;
using namespace std;
typedef struct Cup
{
    int v;
    int num;
}cup;
cup s[MAX];
bool cmp(cup a,cup b)
{
    return a.v<b.v;
}
int main()
{
    int n,i,j,aver,count,p;
    double sum;
    cin>>n;
    sum=0;
    for(i=1;i<=n;i++)
    {
        cin>>s[i].v;
        s[i].num=i;
        sum+=double(s[i].v);
    }
    aver=int(sum/n);
    if(aver==sum/n)
    {
        count=0;
        for(i=1;i<=n;i++)
        {
            if(s[i].v==aver)
            count+=1;
        }
        if(count==n)
        cout<<"Exemplary pages."<<endl;
        else
        {
            sort(s+1,s+n+1,cmp);
            p=0;
            for(i=1;i<=n/2;i++)
            {
                if(((s[i].v+s[n-i+1].v)/2==aver)&&(s[i].v!=aver&&s[n-i+1].v!=aver))
                {
                    p+=1;
                }
            }
            if(p==1)
            {
                for(i=1;i<=n/2;i++)
                {
                    if(((s[i].v+s[n-i+1].v)/2==aver)&&(s[i].v!=aver&&s[n-i+1].v!=aver))
                    {
                        cout<<(s[n-i+1].v-s[i].v)/2<<" ml. from cup #"<<s[i].num<<" to cup #"<<s[n-i+1].num<<'.'<<endl;
                        break;
                    }
                }
            }
            else
            cout<<"Unrecoverable configuration."<<endl;
        }
    }
    else
    cout<<"Unrecoverable configuration."<<endl;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值