1835:【04NOIP提高组】津津的储蓄计划(1835: [04noip improvement group] Jinjin savings plan)

1835:【04NOIP提高组】津津的储蓄计划

【题目描述】

津津的零花钱一直都是自己管理。每个月的月初妈妈给津津300元钱,津津会预算这个月的花销,并且总能做到实际花销和预算的相同。

为了让津津学习如何储蓄,妈妈提出,津津可以随时把整百的钱存在她那里,到了年末她会加上20%还给津津。因此津津制定了一个储蓄计划:每个月的月初,在得到妈妈给的零花钱后,如果她预计到这个月的月末手中还会有多于100元或恰好100元,她就会把整百的钱存在妈妈那里,剩余的钱留在自己手中。

例如11月初津津手中还有83元,妈妈给了津津300元。津津预计11月的花销是180元,那么她就会在妈妈那里存200元,自己留下183元。到了11月月末,津津手中会剩下3元钱。

津津发现这个储蓄计划的主要风险是,存在妈妈那里的钱在年末之前不能取出。有可能在某个月的月初,津津手中的钱加上这个月妈妈给的钱,不够这个月的原定预算。如果出现这种情况,津津将不得不在这个月省吃俭用,压缩预算。

现在请你根据2004年1月到12月每个月津津的预算,判断会不会出现这种情况。如果不会,计算到2004年年末,妈妈将津津平常存的钱加上20%还给津津之后,津津手中会有多少钱。

【输入】

12行数据,每行包含一个小于350的非负整数,分别表示1月到12月津津的预算。

【输出】

一行,这一行只包含一个整数。如果储蓄计划实施过程中出现某个月钱不够用的情况,输出-X,X表示出现这种情况的第一个月;否则输出到2004年年末津津手中会有多少钱。

【输入样例】

290
230
280
200
300
170
340
50 
90 
80 
200
60

【输出样例】

-7

【提示】

【样例输入2】

290 
230 
280 
200 
300 
170 
330 
50 
90 
80 
200 
60

【样例输出2】

1580

#include<iostream>#include<cstdio>int main(){ int b,sum=0; for(int i=1;i<=12;i++) { int a; scanf(“%d”,&a); sum+=300; if(sum>=a) { b+=(sum-a)%1000-(sum-a)%100; sum-=(sum-a)%1000-(sum-a)%100+a; } else { printf(“%d”,i); return 0; } } double a=sum+b*(1.2*1.0); printf(“%d”,(int)a); return 0;}

————————

1835: [04noip improvement group] Jinjin savings plan

[Title Description]

The pocket money of Jinjin has always been managed by itself. At the beginning of each month, my mother gives 300 yuan to Jinjin. Jinjin will budget the expenses of this month, and always make the actual expenses the same as the budget.

In order to let Jinjin learn how to save, her mother proposed that Jinjin could deposit 100% of her money at any time, and she would return it to Jinjin with 20% at the end of the year. Therefore, Jinjin has formulated a savings plan: at the beginning of each month, after receiving the pocket money given by her mother, if she expects to have more than 100 yuan or exactly 100 yuan in her hand by the end of this month, she will deposit the whole 100 yuan with her mother and leave the rest in her own hands.

For example, in early November, there was 83 yuan in Jinjin’s hand, and her mother gave 300 yuan to Jinjin. Jinjin is expected to spend 180 yuan in November, so she will save 200 yuan from her mother and leave 183 yuan by herself. By the end of November, Jinjin will have 3 yuan left.

Jinjin found that the main risk of the savings plan was that the money stored in her mother could not be withdrawn before the end of the year. It is possible that at the beginning of a month, the money in Jinjin’s hands plus the money given by his mother this month is not enough for the original budget of this month. If this happens, Tianjin will have to live frugally and reduce its budget this month.

Now please judge whether this will happen according to the monthly budget of Tianjin from January to December 2004. If not, by the end of 2004, how much money will there be in Jinjin’s hands after my mother returns the money normally saved in Jinjin plus 20%.

[input]

12 lines of data, each line contains a non negative integer less than 350, representing the budget of Tianjin from January to December respectively.

[output]

A line that contains only one integer. If there is insufficient money in a certain month during the implementation of the savings plan, output – x, and X represents the first month of this situation; Otherwise, how much money will there be in Jinjin’s hands by the end of 2004.

[input example]

290
230
280
200
300
170
340
50 
90 
80 
200
60

[output example]

-7

[tips]

[example input 2]

290 
230 
280 
200 
300 
170 
330 
50 
90 
80 
200 
60

[sample output 2]

1580

#include<iostream>#include<cstdio>int main(){ int b,sum=0; for(int i=1;i<=12;i++) { int a; scanf(“%d”,&a); sum+=300; if(sum>=a) { b+=(sum-a)%1000-(sum-a)%100; sum-=(sum-a)%1000-(sum-a)%100+a; } else { printf(“%d”,i); return 0; } } double a=sum+b*(1.2*1.0); printf(“%d”,(int)a); return 0;}