从我原来的博客上搬运。原先blog作废。

题目

A long-distance telephone company charges its customers by the following rules:

Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone. Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day). Your job is to prepare the bills for each month, given a set of phone call records.

题解

繁琐,但是不难。合理运用封装能够减少代码量。

剩下的是两个注意事项:1.是连续的on-off算作一个记录。一个例子:

01 on 02 on 03 off 04 off 那么02-03算作一个记录。

2.必须要注意这个情况,就是如果没有合法的记录的话就不打印账单!!!不论是一开始的还是tot Amount!我第二个一开始忘了不打印了!!

以上。

代码

#include <bits/stdc++.h>
using namespace std; #define f1(x,y) for(int x=1;x<=y;++x)
#define f0(x,y) for(int x=0;x!=y;++x)
#define bf1(x,y,z) for(int x=y;x>=z;--x)
#define bf0(x,y,z) for(int x=y;x!=z;--x)
typedef long long ll;
typedef unsigned long long ull;
int fee[25];
int ohrfee[25]={0};//fee of 00:00~i:00
int dayfee=0;
struct Record
{
int month;
int recMin;
bool isOn;
Record(int _m=1,int _r=0,bool _o=true):
month(_m),recMin(_r),isOn(_o)
{}
bool operator < (const Record& rhs) const
{
return recMin<rhs.recMin;
}
};
typedef pair<Record,Record> Call;
struct User
{
string name;
int month;
vector<Record> rec;
vector<Call> cal;
User(string _n):name(_n) {}
void calc()
{
sort(rec.begin(),rec.end());
int marked[1005];
memset(marked,-1,sizeof(marked));
month=rec[0].month;
bool isOk=false;
f0(i,rec.size()) if(rec[i].isOn && i+1<rec.size() && !(rec[i+1].isOn))
{
cal.push_back(make_pair(rec[i],rec[i+1]));
}
return;
}
};
vector<User> u;
map<string,int> idx;
int main()
{
int f;
f0(i,24)
{
scanf("%d",&f);
fee[i]=f;
if(i==0) ohrfee[i]=0;
else ohrfee[i]=ohrfee[i-1]+fee[i-1]*60;
dayfee+=fee[i]*60;
}
int n; scanf("%d",&n);
f1(i,n)
{
char name[25],status[10];
int mon,d,h,minute;
scanf("%s %d:%d:%d:%d %s",name,&mon,&d,&h,&minute,status);
if(idx.find(string(name))==idx.end())
{
u.push_back(User(string(name)));
idx[string(name)]=u.size()-1;
u.back().rec.push_back(Record(mon,d*1440+h*60+minute,status[1]=='n'));
}
else u[idx[string(name)]].rec.push_back(Record(mon,d*1440+h*60+minute,status[1]=='n'));
}
for(auto iter=u.begin();iter!=u.end();++iter) iter->calc();
for(auto iter=idx.begin();iter!=idx.end();++iter)
{
int num=iter->second;
string nam=iter->first;
User& usr=u[num];
vector<Call>& c=usr.cal;
if(c.size()!=0) printf("%s %02d\n",nam.c_str(),usr.month);
int tot=0;//100cents->1$
f0(i,c.size())
{
int fd,fh,fm,sd,sh,sm,cost;
fd=c[i].first.recMin/1440;fh=(c[i].first.recMin%1440)/60;fm=(c[i].first.recMin%60);
sd=c[i].second.recMin/1440;sh=(c[i].second.recMin%1440)/60;sm=(c[i].second.recMin%60);
cost=(sd-fd)*dayfee+(ohrfee[sh]+sm*fee[sh])-(ohrfee[fh]+fm*fee[fh]);
//printf("2:ohrfee[%d]=%d,sm=%d,fee[%d]=%d.\n",sh,ohrfee[sh],sm,sh,fee[sh]);
//printf("1:ohrfee[%d]=%d,sm=%d,fee[%d]=%d.\n",fh,ohrfee[fh],fm,fh,fee[fh]);
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n",fd,fh,fm,
sd,sh,sm,
c[i].second.recMin-c[i].first.recMin,cost/100.0);
tot+=cost;
}
if(c.size()!=0) printf("Total amount: $%.2f\n",tot/100.0);
}
return 0;
}

【题解搬运】PAT_A1016 Phone Bills的更多相关文章

  1. PAT_A1016#Phone Bills

    Source: PAT A1016 Phone Bills (25 分) Description: A long-distance telephone company charges its cust ...

  2. 【题解搬运】PAT_L1-009 N个数求和

    从我原来的博客上搬运.原先blog作废. (伪)水题+1,旨在继续摸清这个blog(囧 题目 就是求N个数字的和.麻烦的是,这些数字是以有理数"分子/分母"的形式给出的,你输出的和 ...

  3. 【题解搬运】PAT_A1020 树的遍历

    题目 Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder an ...

  4. 【BZOJ】【2463】【中山市选2009】谁能赢呢?

    博弈论 这能算博弈论吗…… orz ZYF so sad……窝智商太低 题解搬运: 当n为偶数时,可以被2*1的骨牌完全覆盖,所以每次都走骨牌的另一端,而另一个人只能走新的骨牌,直到没有为止 当n为奇 ...

  5. codevs 3044 矩形面积求并 (扫描线)

    /* 之前一直偷懒离散化+暴力做着题 今天搞一下扫描线 自己按照线段树的一般写法写的有些问题 因为不用于以前的区间sum so 题解搬运者23333 Orz~ 去掉了打标记的过程 同时更新区间的时候先 ...

  6. 「2017 Multi-University Training Contest 1」2017多校训练1

    1001 Add More Zero(签到题) 题目链接 HDU6033 Add More Zero 找出最大的k,使得\(2^m-1\ge 10^k\). 直接取log,-1可以忽略不计. #inc ...

  7. 【SRM-05 B】无题?

    Description 有一个拥有n个城市的国家.这个国家由n-1条边连接起来.有一天国家发生叛乱.叛军已占领了一些城市.如果叛军占领的城市中,存在两个城市之间有边直接相连,则称这种情况是坏的.现在并 ...

  8. Codeforces 1188E - Problem from Red Panda(找性质+组合数学)

    Codeforces 题面传送门 & 洛谷题面传送门 咦,题解搬运人竟是我? 一道很毒的计数题. 先转化下题意,每一次操作我们可以视作选择一种颜色并将其出现次数 \(+k\),之后将所有颜色的 ...

  9. 洛谷 P4708 - 画画(Burnside 引理+组合数学)

    洛谷题面传送门 神仙题 %%%%%%%%%%%%%%%%%%%% 题解搬运人来了 首先看到本质不同(无标号)的图计数咱们可以想到 Burnside 引理,具体来说,我们枚举一个排列 \(p\),并统计 ...

随机推荐

  1. XCode插件因为升级不能用了怎么办?几个步骤教你搞定

    之前XCode安装了自动注释的插件 VVDomenter.升级之后不能使用了怎么办?跟着我做吧. 1.打开xcode插件所在的目录:~/library/Application Support/Deve ...

  2. likelihood(似然) and likelihood function(似然函数)

    知乎上关于似然的一个问题:https://www.zhihu.com/question/54082000 概率(密度)表达给定下样本随机向量的可能性,而似然表达了给定样本下参数(相对于另外的参数)为真 ...

  3. WebSocket消息推送(实现进行聊天)和WebSocket简介

    WebSocket简介 WebSocket是HTML5开始提供的一种浏览器与服务器间进行全双工通讯的网络技术.依靠这种技术可以实现客户端和服务器端的长连接,双向实时通信.特点:事件驱动异步使用ws或者 ...

  4. 我和我的广告前端代码(六):webpack工程合并、也许我不需要gulp

    随着年初开始使用webpack重构公司的广告代码,已经有将近一年的时间了,需求也渐渐的稳定了.我想也是时候将这几个工程整理一下,顺带着处理一些历史问题. 由于当年各个业务线没有整合.需求也没有固定,考 ...

  5. Restframework介绍

    1.REST介绍 REST与技术无关,它代表的是一种软件架构风格,全称Representational State Transfer,中文翻译为“表征状态转移” REST从资源的角度类审视整个网络,它 ...

  6. 菜鸟笔记 -- Chapter 1 计算机从0到1

    进入20世纪第二个十年,计算机已经成为生活中一个必不可小的工具了,但我们真的了解计算机吗?计算机有哪些部分构成?不同的计算机又可以做什么样的事情呢?我们的PC和用来做加减乘除的计算器都属于计算机范畴吗 ...

  7. javascript 六种基本数据类型转换

    javascript 六种基本数据类型转换 1.显式转换 通过手动进行类型转换,Javascript提供了以下转型函数: 转换为数值类型:Number(mix).parseInt(string,rad ...

  8. Struts2中期(这框架目前正处于淘汰状态)

    Struts2的第二天 Struts2的第二天的内容 1. Struts2框架中的Servlet的API的使用 2. Struts2中Action接收请求参数 3. Struts2中自定义拦截器 案例 ...

  9. WebSocket 和socket 的区别

    去年光棍节的时候,我写过一篇 quick-cocos2d-x 中的 socket 技术选择:LuaSocket 和 WebSocket .这篇文章介绍了我为何决定在项目中使用 LuaSocket . ...

  10. 2、开发环境搭建-window平台

    一.搭建ReactNative环境 首先安装node.js和python2.xx版本,不要装python3.xx,这个官方是特别说明的,请注意.NodeJs官方下载:https://nodejs.or ...