HDU 5328 Problem Killer

xiaoxiao2021-02-27  321

这道题写了几个小时,一直T,有两方面原因

1,这题目时限卡的很紧,多一个常数都不行,这实在是太无聊了。

2,自己太蠢了,这道题目虽然没有说明n>=1,但是自己应该猜到,我把读入第一个数字放在了if(n==1)后面,导致了一直TLE,因为你下一个读入读n的时候就会读到这个序列的第一个数字,使得整个数据没有读完然后就出不来结果。

代码如下:

#include<algorithm> #include<cstdio> #include<stdlib.h> #include<math.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { int T, n; int a, b; int ap, ap_max, ap_cnt; double gp; int gp_max, gp_cnt; int tmp_ap; double tmp_gp; scanf("%d", &T); while(T--) { ap = INF; ap_max = 0; ap_cnt = 2; gp = INF; gp_max = 0; gp_cnt = 2; scanf("%d", &n); scanf("%d", &a); if(n == 1) { printf("1\n"); continue; } for(int i = 1; i < n; i++) { scanf("%d", &b); tmp_ap = b - a; if(tmp_ap != ap) { ap = tmp_ap; ap_max = max(ap_max, ap_cnt); ap_cnt = 2; } else ap_cnt++; tmp_gp = (double)b / a; if(tmp_gp != gp) { gp = tmp_gp; gp_max = max(gp_max, gp_cnt); gp_cnt = 2; } else gp_cnt++; a = b; } ap_max = max(ap_max, ap_cnt); gp_max = max(gp_max, gp_cnt); printf("%d\n", max(ap_max, gp_max)); } return 0; }

转载请注明原文地址: https://www.6miu.com/read-3555.html

最新回复(0)