源:CNUOJ-0384 http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=354

题目分析:当时拿到这道题第一个想法就是排序后n^2暴力枚举,充分利用好有序这一特性随时“短路”。

 1 read(n);read(m);
 2     int temp;
 3     
 4     for(int i = 0; i < n; i++)
 5     {
 6         read(temp);
 7         if(temp <= m) 
 8         {
 9               p[tot].v = temp;
10               p[tot++].num = i;
11         }
12     }
13     
14     sort(p, p + tot);
15     
16     for(int i = 0; i < tot - 1; i++)
17     {
18         for(int j = i + 1; j < tot; j++)
19         {
20             if(p[i].v + p[j].v > m) break;
21             else if(p[i].num < p[j].num) ans++;
22         }
23         ans %= 1000000007;
24     }
25     
26     printf("%d\n", ans);
27     
28     return 0;
算法1

相关文章:

  • 2021-07-24
  • 2022-12-23
  • 2021-12-04
  • 2021-11-10
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
相关资源
相似解决方案