B. Carries

Time Limit: 1000ms

Memory Limit: 65536KB

frog has n integers a1,a2,…,an, and she wants to add them pairwise.

Unfortunately, frog is somehow afraid of carries (进位). She defines \emph{hardness} h(x,y) for adding x and y the number of carries involved in the calculation. For example, h(1,9)=1,h(1,99)=2.

Find the total hardness adding n integers pairwise. In another word, find

∑1≤i<=j≤n h(ai,aj)

Input

The input consists of multiple tests. For each test:

The first line contains 1 integer n (2≤n≤105). The second line contains n integers a1,a2,…,an. (0≤ai≤109).

Output

For each test, write 1 integer which denotes the total hardness.

Sample Input

2

5 5

10

0 1 2 3 4 5 6 7 8 9

Sample Output

1

20

将其对10,100,1000……进行取余的结果进行排序,如果两个数的和大于他们的取余数,则有进位

#include <bits/stdc++.h>
#define LL long long
#define fread() freopen("in.in","r",stdin)
#define fwrite() freopen("out.out","w",stdout) using namespace std; const int Max = 1e5+100; int a[Max];
int b[Max];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int ans=1;
LL num=0;
for(int i=1;i<=9;i++)
{
ans*=10;
for(int k=0;k<n;k++)
b[k]=a[k]%ans;
sort(b,b+n);
int j=0;
for(int k=n-1;k>=0;k--)
{
for(;j<n;j++)
{
if(b[k]+b[j]>=ans)
{
break;
}
}
if(j<=k)
{
num--;
}
num+=(n-j);
} }
printf("%lld\n",num/2);
}
return 0;
}

2015弱校联盟(1) - B. Carries的更多相关文章

  1. 2015弱校联盟(2) - J. Usoperanto

    J. Usoperanto Time Limit: 8000ms Memory Limit: 256000KB Usoperanto is an artificial spoken language ...

  2. 2015弱校联盟(1) - C. Censor

    C. Censor Time Limit: 2000ms Memory Limit: 65536KB frog is now a editor to censor so-called sensitiv ...

  3. 2015弱校联盟(1) - I. Travel

    I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...

  4. 2015弱校联盟(1) -J. Right turn

    J. Right turn Time Limit: 1000ms Memory Limit: 65536KB frog is trapped in a maze. The maze is infini ...

  5. 2015弱校联盟(1) -A. Easy Math

    A. Easy Math Time Limit: 2000ms Memory Limit: 65536KB Given n integers a1,a2,-,an, check if the sum ...

  6. 2015弱校联盟(1) - E. Rectangle

    E. Rectangle Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class name ...

  7. (2016弱校联盟十一专场10.3) D Parentheses

    题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...

  8. (2016弱校联盟十一专场10.3) B.Help the Princess!

    题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...

  9. (2016弱校联盟十一专场10.3) A.Best Matched Pair

    题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...

随机推荐

  1. AspxSpy2014 Final

    受bin牛委托修改并发布,版权归bin牛所有. Bug/建议提交:zcgonvh@rootkit.net.cn 祝各位马年大吉,财源滚滚. 免责声明: 本程序只用于管理员安全检测,使用前请注意环境与法 ...

  2. string用法

    截取字符串 string strTributeInfo = "1#2#3#4#5#6#7"; vector<string> vecTribute; StringUtil ...

  3. [转]RamDisk导致远程桌面客户端无法启动问题

    在一次重启系统后发现无法运行远程桌面客户端,运行后进行连接即报错. 查看日志有AppCrash错误: 错误应用程序名称: mstsc.exe,版本: 6.1.7600.16385,时间戳: 0x4a5 ...

  4. php的乱码问题

    $content=file_get_contents("http://www.ctsdc.com/");$pattern="/<a\s+href=.*<\/a ...

  5. hibernate学习(3)——api详解对象(2)

    1.   Transaction 事务 事务的操作: 开启事务 beginTransaction() 获得事务 getTransaction() 提交事务:commit() 回滚事务:rollback ...

  6. Boyer-Moore algorithm

    http://www-igm.univ-mlv.fr/~lecroq/string/node14.html Main features performs the comparisons from ri ...

  7. js获取url中参数

      /** * 获取地址栏参数值 * @param name 参数名 * @returns */ $(function () { var url = location.search; //获取url中 ...

  8. support HTML5 in IE8

    <!--this code is used to support HTML5 in IE8--> <!--[if IE]><script type="text/ ...

  9. myEclipse 界面窗口打不开问题

    用的myEclipse版本为2014,在其他工作空间没有此问题,在此工作有此问题. 解决办法: 把当前工作空间视图重置即可

  10. MySql超新手入门

    https://www.kancloud.cn/thinkphp/mysql-tutorial/36457