当前位置: 代码迷 >> 综合 >> Cars on Campus (30) 模拟
  详细解决方案

Cars on Campus (30) 模拟

热度:9   发布时间:2023-11-15 10:50:26.0

题目大意:要模拟的东西挺多的,善调用些数据结构就好了.

字典序输出的话借用下set.然后借用下打标记的做法.

#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define ull unsigned long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)#define base 2333
const int mod=1e9+7;
const int maxn=1e3+10;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){if(y==0) return x;return gcd(y,x%y);
}
map<string,int> mp;
map<int,string> mp2;
set<string> st;
set<string>::iterator it;
vector<pii> g[maxn];
string s,t,p,ans[maxn];
int n,m,tot=0,ret[100010],maxv=0;
int rec[maxn];
void output(int x){int p1=x/3600;x%=3600;int p2=x/60;x%=60;int p3=x;if(p1<10) cout<<"0";cout<<p1<<":";if(p2<10) cout<<"0";cout<<p2<<":";if(p3<10) cout<<"0";cout<<p3<<"\n"; 
}
int main(){ios::sync_with_stdio(false);cin>>n>>m;rep(i,0,n){cin>>s>>t>>p;int hh=(t[0]-'0')*10+(t[1]-'0');int mm=(t[3]-'0')*10+(t[4]-'0');int ss=(t[6]-'0')*10+(t[7]-'0');int sta=(p[0]=='o'?-1:1);if(mp[s]==0) mp[s]=++tot;mp2[tot]=s;hh=hh*3600+mm*60+ss;g[mp[s]].push_back(mk(hh,sta));}rep(i,1,tot+1){sort(g[i].begin(),g[i].end());int tmp=0;rep(j,1,g[i].size()) if(g[i][j].se==-1&&g[i][j-1].se==1){ret[g[i][j-1].fi]++,ret[g[i][j].fi]--;tmp+=g[i][j].fi-g[i][j-1].fi;}maxv=max(maxv,tmp);rec[i]=tmp;}rep(i,1,100010) ret[i]+=ret[i-1];rep(i,1,tot+1) if(rec[i]==maxv) st.insert(mp2[i]);rep(i,0,m){cin>>t;int hh=(t[0]-'0')*10+(t[1]-'0');int mm=(t[3]-'0')*10+(t[4]-'0');int ss=(t[6]-'0')*10+(t[7]-'0');hh=hh*3600+mm*60+ss;cout<<ret[hh]<<"\n";}for(it=st.begin();it!=st.end();it++)cout<<*it<<" ";output(maxv);return 0;
}