题意:
输入两个正整数N和K(N<=1e4,K<=8e4),接着输入N行数据每行包括三个字符串表示车牌号,当前时间,进入或离开的状态。接着输入K次询问,输出当下停留在学校里的车辆数量。最后一行输出总计停留时间最长的车牌号(字典序升序输出)和停留总时。

AAAAAccepted code:

//因为一天只有86400秒,所以可以用一个car数组在统计车辆停留时间时在进入时间+1,离开时间-1。再用一个sum数组扫一遍,sum[i]=sum[i-1]+car[i],即可表示当下时间有多少辆车还在停留在校园内。

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
vector<pair<string,int> >v[];
int sum[],car[];
int t[];
map<int,string>id;
vector<string>name;
int a[];
void clear(string&s){
string ss;
swap(s,ss);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k;
cin>>n>>k;
int cnt=;
for(int i=;i<=n;++i){
string s;
cin>>s;
string t;
cin>>t;
string f;
cin>>f;
if(!mp[s])
mp[s]=++cnt;
id[mp[s]]=s;
int flag=;
if(f[]=='i')
flag=;
v[mp[s]].push_back({t,flag});
}
for(int i=;i<=cnt;++i){
sort(v[i].begin(),v[i].end());
string now;
int flag=;
for(int j=;j<v[i].size();++j){
if(v[i][j].second==){
now=v[i][j].first;
flag=;
}
else{
if(flag){
string tamp=v[i][j].first;
int start=(now[]-'')*+(now[]-'')*+(now[]-'')*+(now[]-'')*+(now[]-'')*+(now[]-'');
int over=(tamp[]-'')*+(tamp[]-'')*+(tamp[]-'')*+(tamp[]-'')*+(tamp[]-'')*+(tamp[]-'');
++car[start];
--car[over];
flag=;
clear(now);
t[i]+=over-start;
}
}
}
}
sum[]+=car[];
for(int i=;i<;++i)
sum[i]=sum[i-]+car[i];
for(int i=;i<=k;++i){
string tamp;
cin>>tamp;
int tt=(tamp[]-'')*+(tamp[]-'')*+(tamp[]-'')*+(tamp[]-'')*+(tamp[]-'')*+(tamp[]-'');
cout<<sum[tt]<<"\n";
}
int mx=;
for(int i=;i<=cnt;++i)
mx=max(mx,t[i]);
for(int i=;i<=cnt;++i)
if(mx==t[i])
name.push_back(id[i]);
sort(name.begin(),name.end());
for(int i=;i<name.size();++i)
cout<<name[i]<<" ";
a[]=mx/;
mx%=;
a[]=mx/;
mx%=;
a[]=mx/;
mx%=;
a[]=mx/;
mx%=;
a[]=mx/;
mx%=;
a[]=mx;
cout<<a[]<<a[]<<":"<<a[]<<a[]<<":"<<a[]<<a[];
return ;
}

【PAT甲级】1095 Cars on Campus (30 分)的更多相关文章

  1. PAT甲级1095. Cars on Campus

    PAT甲级1095. Cars on Campus 题意: 浙江大学有6个校区和很多门.从每个门口,我们可以收集穿过大门的汽车的进/出时间和车牌号码.现在有了所有的信息,你应该在任何特定的时间点告诉在 ...

  2. PAT甲级——1095 Cars on Campus (排序、映射、字符串操作、题意理解)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93135047 1095 Cars on Campus (30 分 ...

  3. PAT甲级——1131 Subway Map (30 分)

    可以转到我的CSDN查看同样的文章https://blog.csdn.net/weixin_44385565/article/details/89003683 1131 Subway Map (30  ...

  4. PAT 甲级 1076 Forwards on Weibo (30分)(bfs较简单)

    1076 Forwards on Weibo (30分)   Weibo is known as the Chinese version of Twitter. One user on Weibo m ...

  5. PAT 甲级 1068 Find More Coins (30 分) (dp,01背包问题记录最佳选择方案)***

    1068 Find More Coins (30 分)   Eva loves to collect coins from all over the universe, including some ...

  6. PAT 甲级 1045 Favorite Color Stripe (30 分)(思维dp,最长有序子序列)

    1045 Favorite Color Stripe (30 分)   Eva is trying to make her own color stripe out of a given one. S ...

  7. PAT 甲级 1018 Public Bike Management (30 分)(dijstra+dfs,dfs记录路径,做了两天)

    1018 Public Bike Management (30 分)   There is a public bike service in Hangzhou City which provides ...

  8. PAT 甲级 1014 Waiting in Line (30 分)(queue的使用,模拟题,有个大坑)

    1014 Waiting in Line (30 分)   Suppose a bank has N windows open for service. There is a yellow line ...

  9. PAT (Advanced Level) Practise - 1095. Cars on Campus (30)

    http://www.patest.cn/contests/pat-a-practise/1095 Zhejiang University has 6 campuses and a lot of ga ...

随机推荐

  1. JS 抖动函数封装

    原生JS实现封装的抖动函数框架 <style> ul{ margin-top: 100px; } li { float: left; margin-left: 20px; position ...

  2. 面试题:HashSet、TreeSet 和HashMap 的实现与原理

    说下 TreeSet 和 HashSet 什么区别呢? 它们的区别点主要在他们的底层数据结构不同,HashSet 使用的是 HashMap 来实现,而 TreeSet 使用的是 TreeMap 来实现 ...

  3. DE1-soc软件实验”hello_word"

    此实验需要工具:win32disk,路由器,sd卡,Embeed Design suite, Putty,usb to uart 驱动 选择文件,在拷贝到sd卡中去:烧写的文件是官方提供的SD卡的程序 ...

  4. docker跨主机链接

    三种方式 一,使用网桥实现跨主机容器连接

  5. 第三十三篇 玩转数据结构——红黑树(Read Black Tree)

    1.. 图解2-3树维持绝对平衡的原理: 2.. 红黑树与2-3树是等价的 3.. 红黑树的特点 简要概括如下: 所有节点非黑即红:根节点为黑:NULL节点为黑:红节点孩子为黑:黑平衡 4.. 实现红 ...

  6. mysql(5):主从复制和分库分表

    主从复制集群 概念:主从复制是指数据可以从一个MySQL数据库服务器主节点复制到一个或多个从节点. 使用场景: 读写分离:使用主从复制,让主库负责写,从库负责读,这样,即使主库出现了锁表的情景,通过读 ...

  7. php设计模式之工厂方法实例代码

    实现不修改原代码,扩展新功能 <?php header("Content-type:text/html;charset=utf-8"); /** * db接口 * 实现连接数 ...

  8. bootstrap联动校验(转载)

    接触bootstrapvalidator时间不久,最近需要多个字段共同验证,网上查了一下未找到,查阅api文档,发现确实可以实现. 先看dom <div class="form-gro ...

  9. Go操作influxDB

      influxDB 安装 下载 https://portal.influxdata.com/downloads/ 这里需要注意因为这个网站引用了google的api所以国内点页面的按钮是没反应的,怎 ...

  10. Cut Ribbon

    Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the follo ...