Yuyuko and Youmu
来源:互联网 发布:java求1到200内的素数 编辑:程序博客网 时间:2024/05/19 00:17
Saigyouji Yuyuko (西行寺幽々子), the ghost from the calamitous nirvana, is the princess of Hakugyokurou (白玉楼) in the Netherworld, while Konpaku Youmu (魂魄妖夢), half-human half-phantom, is the gardener of Hakugyokurou. Yuyuko is famous as a "hungry ghost" having an immense appetite. So Youmu is alway busy preparing enough food for her.
For the coming n days, knowing the amount of food Yuyuko needs and the amount of food Youmu can prepare at each day, Youmu wants to make an arrangement so that Yuyuko can eat enough food everyday, and the food is as fresh as possible. There are no food remained in Hakugyokurou currently.
Input
There are multiple cases. The first line of each case contains a integer n (1 ≤ n ≤ 1000). The second line contains n integers (1 ≤ ai ≤ 1000000), the amount of food Yuyuko needs at each day. The third line contains n integers (1 ≤ bi ≤ 1000000), the amount of food Youmu can prepare at each day.
Output
If an arrangement exists, output n integers, the amount of food Youmu should prepare at each day. If not, output a line of "Myon".
Sample Input
510 10 100 10 1050 50 50 50 5091 2 4 8 16 32 64 128 25610 10 10 10 10 10 10 10 10
Sample Output
20 50 50 10 10Myon
题意:这个人每天要吃一定数量的食物,但是他每天也能采集一定数量的食物,但是他又想吃最新鲜的食物(其实就是最小值),问他每天要采集多少食物才不会被饿死。
题目比较水,稍加分析就行。
分析:从最后一天倒着往前走。第n天要采集的量是第n天要吃的量加上前一天没采集够的量。如果要采集的量小于这一天能采集的最大量,那么剩余的那部分就是0,否则向前累加。最后检查第一天要采集的量和他能采集的最大量就行。
#include<iostream>#include<string>#include<stdio.h>#include<string.h>using namespace std;int main(){int n,i,k,sum;int a[1010],b[1010],c[1010];int max;while(~scanf("%d",&n)){sum=0;memset(c,0,sizeof(c));for(i=0;i<n;i++){scanf("%d",&a[i]);if(max<a[i]){k=i;max=a[i];}}for(i=0;i<n;i++){scanf("%d",&b[i]);}for(i=n-1;i>0;i--){if(a[i]+sum<b[i])//就是这里是代码的核心。{c[i]=a[i]+sum;sum=0;}else{sum=a[i]-b[i]+sum;c[i]=b[i];}}if(a[0]+sum>b[0]){cout<<"Myon"<<endl;}else{c[0]=a[i]+sum;for(i=0;i<n;i++){if(i<n-1)cout<<c[i]<<" ";else{cout<<c[i]<<endl;}}}}}
- Yuyuko and Youmu
- " and '
- $* and $@
- AND
- AND
- & and &&
- ""and ‘’
- GetMessage () and PeekMessage () and SendMessage () and PostMessage ()
- eval and $()/``and typeset and xargs
- # and #line and __FILE__ and __LINE__
- 这样的东东怎么翻译:and and and And?
- Metalearning and ...?
- .And
- between...and
- 初学and
- '&' and '*' (C++)?
- and or
- grep && and ||
- C语言变量内存分布
- 字符串面试题系列之六:在字符串中删除特定的字符
- Windows 8 Tools - windows 8 小工具有大功能,帮你轻松搞定新系统
- 状态模式
- 了解GCC C++ C
- Yuyuko and Youmu
- 杭电oj题目分类
- 对已经得到的DataTable进行分组
- 自动化信任机制脚本
- ScrollView滚动到底部和顶部的检测
- hadoop日志【5】----存储迁移之后
- openstack创建虚拟机
- hdu 2503 1713 1108 最小公倍数&最大公约数
- 【转】HTML中的form表单的两种enctype属性