设为首页 收藏本站
查看: 1183|回复: 0

[经验分享] B. Help Chef Gerasim

[复制链接]

尚未签到

发表于 2015-11-26 07:18:28 | 显示全部楼层 |阅读模式
B. Help Chef Gerasim
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
[size=1em]
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.
[size=1em]
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
[size=1em]
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
[size=1em]
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.v;
s.num=i;
sum+=double(s.v);
}
aver=int(sum/n);
if(aver==sum/n)
{
count=0;
for(i=1;i<=n;i++)
{
if(s.v==aver)
count+=1;
}
if(count==n)
cout<<&quot;Exemplary pages.&quot;<<endl;
else
{
sort(s+1,s+n+1,cmp);
p=0;
for(i=1;i<=n/2;i++)
{
if(((s.v+s[n-i+1].v)/2==aver)&&(s.v!=aver&&s[n-i+1].v!=aver))
{
p+=1;
}
}
if(p==1)
{
for(i=1;i<=n/2;i++)
{
if(((s.v+s[n-i+1].v)/2==aver)&&(s.v!=aver&&s[n-i+1].v!=aver))
{
cout<<(s[n-i+1].v-s.v)/2<<&quot; ml. from cup #&quot;<<s.num<<&quot; to cup #&quot;<<s[n-i+1].num<<'.'<<endl;
break;
}
}
}
else
cout<<&quot;Unrecoverable configuration.&quot;<<endl;
}
}
else
cout<<&quot;Unrecoverable configuration.&quot;<<endl;
}

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-143580-1-1.html 上篇帖子: 【codechef】 Chef and Piano Scales (简单题) 下篇帖子: Meal,WaitPerson and Chef using Lock and Condition
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表