码迷,mamicode.com
首页 > 其他好文 > 详细

scu4437(二分)

时间:2017-04-17 16:48:54      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:int   test   code   printf   algo   problem   fine   cst   algorithm   

题目链接:https://cn.vjudge.net/contest/159024#problem/B

暴力超时,用二分优化。。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #define ll long long
 6 using namespace std;
 7 const int maxn=1e5+10;
 8 int n;
 9 int B[maxn];
10 int num[maxn];
11 int main()
12 {
13     while(scanf("%d",&n)!=EOF)
14     {
15         for(int i=0;i<n;i++)
16             scanf("%d",&num[i]);
17         int m=1;
18         ll ans=0;
19         for(int i=1;i<10;i++)
20         {
21             m*=10;
22             for(int i=0;i<n;i++)
23                 B[i]=num[i]%m;
24             sort(B,B+n);
25             for(int i=0;i<n;i++)
26             {
27                 int pos=lower_bound(B+i+1,B+n,m-B[i])-B;
28                 ans=ans+(n-pos);
29             }
30         }
31         printf("%lld\n",ans);
32     }
33 
34 }

 

scu4437(二分)

标签:int   test   code   printf   algo   problem   fine   cst   algorithm   

原文地址:http://www.cnblogs.com/yijiull/p/6723591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!