hiho一下 第五十九周 题目1 : Performance Log

2024-05-14 11:48

本文主要是介绍hiho一下 第五十九周 题目1 : Performance Log,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目1 : Performance Log

时间限制: 8000ms
单点时限: 1000ms
内存限制: 256MB

描述

You are given a txt file, which is performance logs of a single-threaded program.

Each line has three columns as follow:

[Function Name] [TimeStamp] [Action]

[FunctionName] is a string of length between 1~255

[TimeStamp] format is hh:mm:ss

Valid values for "Action" column are START or END, marking the start or end of a function call.

Each function will only be called once.

Output the depth-first traversal result of the call graph with the total time of each function call. However, sometimes the performance log isn't correct and at that time you just need to output "Incorrect performance log".

输入

The input only contains 1 case, first line is a positive number N representing the number of logs(1 <= N <= 20000), then there are N lines in next, each line is the log info containing [Function Name] [TimeStamp] [Action], [Function Name] is a string, you can assume the [Function Name] is distinct and the length between 1~255.

输出

Output the depth-first traversal result of the call graph with the total time of each function call for the correct performance, or output "Incorrect performance log".

提示

A call graph is a directed graph that represents calling relationships between subroutines in a computer program.

Call graph for the sample input is shown as below:


Another sample test case.

Sample InputSample Output
8
FuncA 00:00:01 START
FuncB 00:00:02 START
FuncC 00:00:03 START
FuncA 00:00:04 END
FuncB 00:00:05 END
FuncD 00:00:06 START
FuncD 00:00:07 END
FuncC 00:00:08 END
Incorrect performance log









样例输入
8
FuncA 00:00:01 START
FuncB 00:00:02 START
FuncC 00:00:03 START
FuncC 00:00:04 END
FuncB 00:00:05 END
FuncD 00:00:06 START
FuncD 00:00:07 END
FuncA 00:00:08 END
样例输出
FuncA 00:00:07
FuncB 00:00:03
FuncC 00:00:01
FuncD 00:00:01

题意,给出一个函数调用的日志,判定是否正确,和输出,深度优先搜索出来的函数先后用的时间。

看似很容易,实际坑很多。

1.时间不一定递增,要计算出来后,比较。

2.start end不一定是按顺序,也不一定相匹配,也不一定是唯一,这就要用一个map存起来就可以判定了。

3.输出,就是按栈中出现的顺序,输出来就可以了。但还有一个坑就是,最终不一定,栈为空。

#define N 20050
#define M 256
#define maxn 205
#define MOD 1000000000000000007
int n,allN,ansNum,id[N],ans[N];
map<string,int> mymap;
stack<int> mystack;
char name[N][260],times[N][20],state[N][10],ansS[20];
int getNum(char s[]){return   ((s[0] - '0') * 10 + (s[1] - '0')) * 3600+((s[3] - '0') * 10 + (s[4] - '0')) * 60+((s[6] - '0') * 10 + (s[7] - '0')) * 1 ;
}
int getTime(char s[],char e[]){return getNum(e) - getNum(s);
}
char * getS(int sid){int s1 = sid % 60,s2 = (sid/60) % 60 ,s3 = (sid/3600);ansS[2] = ansS[5] = ':';ansS[8] = '\0';ansS[0] = '0' + s3/10;ansS[1] = '0' + s3%10;ansS[3] = '0' + s2/10;ansS[4] = '0' + s2%10;ansS[6] = '0' + s1/10;ansS[7] = '0' + s1%10;return ansS;
}
int main()
{while(S(n)!=EOF){mymap.clear();allN = 0;while(!mystack.empty()) mystack.pop();fill(ans,-1);bool flag = true;ansNum = 0;FI(n){SS(name[i]);SS(times[i]);SS(state[i]);if(i >= 1 && getNum(times[i]) < getNum(times[i-1]))flag = false;if(flag){if(mymap.count(name[i])){if(state[i][0] != 'E'){flag = false;}int ind = mymap[name[i]];if(mystack.empty() || ind != mystack.top()){flag = false;}else {mystack.pop();}if(ans[ind] != -1) flag = false;ans[ind] = getTime(times[id[ind]],times[i]);}else{if(state[i][0] != 'S'){flag = false;}mymap[name[i]] = allN;id[allN] = i;mystack.push(allN);allN++;}}}if(!mystack.empty())flag = false;if(flag){FI(allN){printf("%s %s\n",name[id[i]],getS(ans[i]));}}else {printf("Incorrect performance log\n");}}return 0;
}


这篇关于hiho一下 第五十九周 题目1 : Performance Log的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/988667

相关文章

内核启动时减少log的方式

内核引导选项 内核引导选项大体上可以分为两类:一类与设备无关、另一类与设备有关。与设备有关的引导选项多如牛毛,需要你自己阅读内核中的相应驱动程序源码以获取其能够接受的引导选项。比如,如果你想知道可以向 AHA1542 SCSI 驱动程序传递哪些引导选项,那么就查看 drivers/scsi/aha1542.c 文件,一般在前面 100 行注释里就可以找到所接受的引导选项说明。大多数选项是通过"_

题目1254:N皇后问题

题目1254:N皇后问题 时间限制:1 秒 内存限制:128 兆 特殊判题:否 题目描述: N皇后问题,即在N*N的方格棋盘内放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在同一斜线上。因为皇后可以直走,横走和斜走如下图)。 你的任务是,对于给定的N,求出有多少种合法的放置方法。输出N皇后问题所有不同的摆放情况个数。 输入

题目1380:lucky number

题目1380:lucky number 时间限制:3 秒 内存限制:3 兆 特殊判题:否 提交:2839 解决:300 题目描述: 每个人有自己的lucky number,小A也一样。不过他的lucky number定义不一样。他认为一个序列中某些数出现的次数为n的话,都是他的lucky number。但是,现在这个序列很大,他无法快速找到所有lucky number。既然

【408数据结构】散列 (哈希)知识点集合复习考点题目

苏泽  “弃工从研”的路上很孤独,于是我记下了些许笔记相伴,希望能够帮助到大家    知识点 1. 散列查找 散列查找是一种高效的查找方法,它通过散列函数将关键字映射到数组的一个位置,从而实现快速查找。这种方法的时间复杂度平均为(

【详细介绍一下GEE】

GEE(Google Earth Engine)是一个强大的云计算平台,它允许用户处理和分析大规模的地球科学数据集,如卫星图像、气候模型输出等。以下是对GEE用法的详细介绍: 一、平台访问与账户设置 访问GEE平台: 用户可以通过访问Google Earth Engine的官方网站来开始使用GEE。 创建账户: 用户需要注册并登录Google账户,然后申请访问GEE平台。申请过程可能需要提

ImportError: cannot import name ‘print_log‘ from ‘logging‘

mmcv升级到2.+后删除了很多 解决 查FAQ文档,找到 添加到mmcv.utils下即可

DAY16:什么是慢查询,导致的原因,优化方法 | undo log、redo log、binlog的用处 | MySQL有哪些锁

目录 什么是慢查询,导致的原因,优化方法 undo log、redo log、binlog的用处  MySQL有哪些锁   什么是慢查询,导致的原因,优化方法 数据库查询的执行时间超过指定的超时时间时,就被称为慢查询。 导致的原因: 查询语句比较复杂:查询涉及多个表,包含复杂的连接和子查询,可能导致执行时间较长。查询数据量大:当查询的数据量庞大时,即使查询本身并不复杂,也可能导致

码蹄集部分题目(2024OJ赛9.4-9.8;线段树+树状数组)

1🐋🐋配对最小值(王者;树状数组) 时间限制:1秒 占用内存:64M 🐟题目思路 MT3065 配对最小值_哔哩哔哩_bilibili 🐟代码 #include<bits/stdc++.h> using namespace std;const int N=1e5+7;int a[N],b[N],c[N],n,q;struct QUERY{int l,r,id;}que

多数据源的事务处理总是打印很多无用的log日志

之前做了一个项目,需要用到多数据源以及事务处理,在使用事务处理,服务器总是打印很多关于事务处理的log日志(com.atomikos.logging.Slf4jLogger),但是我们根本不会用到这些log日志,反而使得查询一些有用的log日志变得困难。那要如何屏蔽这些log日志呢? 之前的项目是提高项目打印log日志的级别,后来觉得这样治标不治本。 现在有一个更好的方法: 我使用的是log

2024 年高教社杯全国大学生数学建模竞赛题目——2024 年高教社杯全国大学生数学建模竞赛题目的求解

2024 年高教社杯全国大学生数学建模竞赛题目 (请先阅读“ 全国大学生数学建模竞赛论文格式规范 ”) 2024 年高教社杯全国大学生数学建模竞赛题目 随着城市化进程的加快、机动车的快速普及, 以及人们活动范围的不断扩大,城市道 路交通拥堵问题日渐严重,即使在一些非中心城市,道路交通拥堵问题也成为影响地方经 济发展和百姓幸福感的一个“痛点”,是相关部门的棘手难题之一。 考虑一个拥有知名景区