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. bzoj2743: [HEOI2012]采花--离线树状数组+差分

    题目大意:给定一个区间,查询子区间里出现次数不小于二的数的个数 此题想了好久没想出来,后来是在网上学习的一个方法 首先按查询区间的右端点进行排序,按右端点从小到大处理 假设pre[a[i]]是与a[i ...

  2. JQ 队列

    <div class="divtt"> <div class="divtest"></div> </div> & ...

  3. 实验四 Android开发基础

    实验四 Android开发基础 实验内容 1.安装Android Studio 2.运行安卓AVD模拟器 3.使用安卓运行出虚拟手机并显示HelloWorld以及自己的学号 (一)SDK的安装 (二) ...

  4. NYOJ-组合数

    #include <stdio.h> #include <malloc.h> int main() { ; ]; scanf("%d%d", &n, ...

  5. IOS彩票第二天设置界面(2)

    *********代码的抽取ILBaseTableViewController.h #import <UIKit/UIKit.h> @interface ILBaseTableViewCo ...

  6. mvn打包idea项目

    首先 通过cmd进入docs 然后用cd命令进入项目文件夹所在路径 然后输入mvn -Dmaven.test.skip=true package//-Dmaven.test.skip=true跳过测试

  7. Jenkins中Jelly基础、超链接、国际化

    Jelly基础 参考:https://wiki.jenkins-ci.org/display/JENKINS/Basic+guide+to+Jelly+usage+in+Jenkins UI Samp ...

  8. ios之json,xml解析

    JSON解析步骤: 1.获取json文件路径 NSString*path = [[NSBundle mainBundle] pathForResource:@"Teacher"of ...

  9. VMware安装Linux第一天

    今天上午下载了VMware-workstation_full_12.1.1.6932,它的Key是5A02H-AU243-TZJ49-GTC7K-3C61N,这些都是网络上搜罗到的. VMWare安装 ...

  10. ++i 与 i++ 区别

    i++返回原来的值 ++i 返回i+1的值   但是i++  i的值也会增加1 但是返回还是原来的值 int i = 1; i = i++; System.out.println(i); 输出 1 i ...