SRM 149 1A2AB 2013.12.3

SRM 149 1A2AB 2013.12.3

DIV1

250

Problem Statement

    

BigBurger Inc. wants to see if having asingle person at the counter both to take orders and to serve them is feasible.At each BigBurger, customers will arrive and get in line. When they get to thehead of the line they will place their order, which will be assembled andserved to them. Then they will leave the BigBurger and the next person in linewill be able to order.

We need to know how long a customer may beforced to wait before he or she can place an order. Given a script that listseach customer for a typical day, we want to calculate the maximum customerwaiting time. Each customer in the script is characterized by an arrival time(measured in minutes after the store opened) and a service duration (the numberof minutes between ordering and getting the food).

Create a class BigBurger that containsmethod maxWait that is given a vector <int> arrival and a vector<int> service describing all the customers and returns the maximum timespent by a customer between arriving and placing the order. Correspondingelements of arrival and service refer to the same customer, and they are givenin the order in which they arrive at the store (arrival is in non-descendingorder).

If multiple customers arrive at the sametime they will all join the line at the same time, with the ones listed earlierahead of ones appearing later in the list.

Definition

    

Class:

BigBurger

Method:

maxWait

Parameters:

vector <int>, vector <int>

Returns:

int

Method signature:

int maxWait(vector <int> arrival,vector <int> service)

(be sure your method is public)

    

 

Constraints

-

arrival will contain between 1 and 50elements inclusive

-

service will contain the same number ofelements as arrival

-

the elements of arrival will be innon-decreasing order

-

each element of arrival will be between 1and 720 inclusive

-

each element of service will be between 1and 15 inclusive

Examples

0)

 

    

{3,3,9}

{2,15,14}

Returns: 11

Two customers arrive at time 3. The firstone waits 0 time, orders, and is served after 2 minutes, leaving at time 5. Thesecond one then orders and is served at time 20. Meanwhile a customer arrivesat time 9 and waits until the second customer leaves. This last customer thenorders at time 20, and is served and leaves at time 20+14 = 34. The firstcustomer waited 0 minutes, the second waited 2 minutes (from time 3 to time 5),and the last customer waited 11 minutes (from time 9 to time 20).

1)

 

    

{182}

{11}

Returns: 0

The first customer never needs to wait.

2)

 

    

{2,10,11}

{3,4,3}

Returns: 3

The third customer needs to wait from time11 to time 14. Neither of the other customers needs to wait at all.

3)

 

    

{2,10,12}

{15,1,15}

Returns: 7

The second customer waits the longest.

This problem statement is the exclusive andproprietary property of TopCoder, Inc. Any unauthorized use or reproduction ofthis information without the prior written consent of TopCoder, Inc. is strictlyprohibited. (c)2003, TopCoder, Inc. All rights reserved.

 

199.44

#include<iostream>

#include<string>

#include<vector>

 

using namespace std;

 

class BigBurger

{

public:int maxWait(vector <int>arrival, vector <int> service)

         {

                      int ans=0;

                      int last=arrival[0]+service[0];

                      for(int i=1;i<arrival.size();i++)

                      {

                               int temp=last-arrival[i];

                               if (temp<0) temp=0;

                               ans+=temp;

                               last=arrival[i]+service[i];

                      }

                      return ans;

         }

};

 

DIV2

250

Problem Statement

    

In documents, it is frequently necessary towrite monetary amounts in a standard format. We have decided to format amountsas follows:

the amount must start with '$'

the amount should have a leading '0' if andonly if it is less then 1 dollar.

the amount must end with a decimal pointand exactly 2 following digits.

the digits to the left of the decimal pointmust be separated into groups of three by commas (a group of one or two digitsmay appear on the left).

Create a class FormatAmt that contains amethod amount that takes two int's, dollars and cents, as inputs and returnsthe properly formatted string.

Definition

    

Class:

FormatAmt

Method:

amount

Parameters:

int, int

Returns:

string

Method signature:

string amount(int dollars, int cents)

(be sure your method is public)

    

 

Notes

-

One dollar is equal to 100 cents.

Constraints

-

dollars will be between 0 and 2,000,000,000inclusive

-

cents will be between 0 and 99 inclusive

Examples

0)

 

    

123456

0

Returns: "$123,456.00"

Note that there is no space between the $and the first digit.

1)

 

    

49734321

9

Returns: "$49,734,321.09"

 

2)

 

    

0

99

Returns: "$0.99"

Note the leading 0.

3)

 

    

249

30

Returns: "$249.30"

 

4)

 

    

1000

1

Returns: "$1,000.01"

 

This problem statement is the exclusive andproprietary property of TopCoder, Inc. Any unauthorized use or reproduction ofthis information without the prior written consent of TopCoder, Inc. isstrictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

 

191.48

#include<iostream>

#include<string>

#include<vector>

#include<sstream>

 

using namespace std;

 

class FormatAmt

{

public:string amount(int dollars, intcents)

         {

                      stringstream ans,sdollars,scents;

                      ans<<"$";

                      sdollars<<dollars;

                      if (cents<10)scents<<"0";

                      scents<<cents;

                      if (dollars==0) ans<<"0";

                      else

                      {

                      string d = sdollars.str();

                      int len=d.size();

                      int key=len%3;

                      if (key!=0)

                      {

                              for(int j=0;j<key;j++)

                                        ans<<d[j];

                              ans<<",";

                    }

                      int count=0;

                      for(int i=key;i<len-1;i++)

                      {

                               count++;

                               ans<<d[i];

                               if (count%3==0) ans<<",";

                      }

                      ans<<d[len-1];

                      }

                      ans<<".";

                      ans<<scents.str();

                      return ans.str();

 

         }

};

 

500 同DIV 1 A

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
org.csource.common.MyException: getStoreStorage fail, errno code: 2 at org.csource.fastdfs.StorageClient.newReadableStorageConnection(StorageClient.java:1767) at org.csource.fastdfs.StorageClient.download_file(StorageClient.java:1219) at org.csource.fastdfs.StorageClient.download_file(StorageClient.java:1206) at com.wzdigit.framework.utils.FastDFSUtil.downFile(FastDFSUtil.java:209) at com.wzdigit.srm.dsr.utils.FileUtil.getSingleFile(FileUtil.java:51) at com.wzdigit.srm.dsr.service.bidding.BiddingorderService.getVendorQuotation(BiddingorderService.java:796) at com.wzdigit.srm.dsr.service.bidding.BiddingorderService.sendEmail(BiddingorderService.java:746) at com.wzdigit.srm.dsr.service.bidding.BiddingorderService$$FastClassBySpringCGLIB$$ebfcbd5a.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at com.alibaba.druid.support.spring.stat.DruidStatInterceptor.invoke(DruidStatInterceptor.java:73) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691) at com.wzdigit.srm.dsr.service.bidding.BiddingorderService$$EnhancerBySpringCGLIB$$80ace30.sendEmail(<generated>) at com.wzdigit.srm.dsr.service.bidding.BiddingorderService$$FastClassBySpringCGLIB$$ebfcbd5a.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
最新发布
06-13

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值