标签:des style blog http color java 使用 os
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 573 Accepted Submission(s): 201
1 #include <cstdio> 2 #include <cstring> 3 4 const int LEN = 40040; 5 6 int arr[LEN]; 7 int table1[LEN]; 8 int table2[LEN]; 9 10 int main() 11 { 12 int n, m; 13 while(scanf("%d %d", &n, &m) != EOF){ 14 memset(table1, 0, sizeof(table1)); 15 memset(table2, 0, sizeof(table2)); 16 int t = -1; 17 for(int i = 0; i < n; i++){ //读入并记录m的位置 18 scanf("%d", arr+i); 19 if (arr[i] == m) 20 t = i; 21 } 22 int ans = 0; 23 if (t != -1) //如果m不在序列中则ans = 0 否则为1,即只有他本身时的情况 24 ans = 1; 25 int ma = 0; 26 int mi = 0; 27 for(int i = t-1; i >= 0; i--){ 28 if (arr[i] < arr[t]) 29 mi++; 30 else 31 ma++; 32 int tmp = ma - mi; //哈希记录tmp。 33 if (tmp < 0) 34 table1[-tmp]++; 35 else 36 table2[tmp]++; 37 if (ma == mi) //特判t = 0的情况 38 ans++; 39 } 40 41 ma = 0; 42 mi = 0; 43 for(int i = t+1; i < n; i++){ 44 if (arr[i] < arr[t]) 45 mi++; 46 else 47 ma++; 48 int tmp = mi - ma; 49 if (tmp < 0) 50 ans += table1[-tmp]; //查询有没有出现过,若有,则加上出现的次数 51 else 52 ans += table2[tmp]; 53 if (ma == mi) //特判t = 0 54 ans++; 55 } 56 printf("%d\n", ans); 57 } 58 return 0; 59 }
【HDU】4908 (杭电 BC #3 1002题)BestCoder Sequence ——哈希,布布扣,bubuko.com
【HDU】4908 (杭电 BC #3 1002题)BestCoder Sequence ——哈希
标签:des style blog http color java 使用 os
原文地址:http://www.cnblogs.com/kevince/p/3890442.html