Carries

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

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

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

∑1≤i<j≤nh(ai,aj)∑1≤i<j≤nh(ai,aj)

.

Input

The input consists of multiple tests. For each test:

The first line contains 11 integer nn (2≤n≤1052≤n≤105). The second line contains nn integersa1,a2,…,ana1,a2,…,an. (0≤ai≤1090≤ai≤109).

Output

For each test, write 11 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
这题题目简单粗暴 ,给你一个长度为n的数组,求出这个数组中任意两个数相加进位的次数
这题是一个想法题,把一个数的每一位都分离出来,进行处理也就是取模运算
int cnt=lower_bound(b,b+n,temp)-b; lower_bound的返回值是一个元素的指针,b为头指针
两者相减就是这个元素与头元素之间有多少个元素。
 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
long long a[],b[];
int main() {
int n;
while(scanf("%d",&n)!=EOF){
for (int i= ;i<n ;i++){
scanf("%lld",&a[i]);
}
long long s=,ans=;
for (int k= ;k< ;k++ ,s=s*){
for (int i= ;i<n ;i++ ){
b[i]=a[i]%s;
}
sort(b,b+n);
long long temp;
for (int i= ;i<n ;i++){
temp=s-b[i];
if (b[n-]>=temp){
int cnt=lower_bound(b,b+n,temp)-b;
if (cnt>i) ans+=n-cnt;
else ans+=n--i;
}
}
}
printf("%lld\n",ans);
}
return ;
}
												

Carries SCU - 4437的更多相关文章

  1. ACM:SCU 4437 Carries - 水题

    SCU 4437  Carries Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice  ...

  2. SCU 4437 Carries(二分乱搞)题解

    题意:问任意两对ai,aj相加的总进位数为多少.比如5,6,95分为(5,6)(5,95)(6,95),进位数 = 1 + 2 + 2 = 5 思路:显然暴力是会超时的.我们可以知道总进位数等于每一位 ...

  3. ACM: SCU 4438 Censor - KMP

     SCU 4438 Censor Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice D ...

  4. ACM: SCU 4440 Rectangle - 暴力

     SCU 4440 Rectangle Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practic ...

  5. 2015弱校联盟(1) - B. Carries

    B. Carries Time Limit: 1000ms Memory Limit: 65536KB frog has n integers a1,a2,-,an, and she wants to ...

  6. SCU 4424(求子集排列数)

    A - A Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice ...

  7. SCU 2941 I NEED A OFFER!(01背包变形)

    I NEED A OFFER!     64bit IO Format: %lld & %llu Submit Status Description Description Speakless ...

  8. SCU 4440 分类: ACM 2015-06-20 23:58 16人阅读 评论(0) 收藏

    SCU - 4440 Rectangle Time Limit: Unknown   Memory Limit: Unknown   64bit IO Format: %lld & %llu ...

  9. scu 4436: Easy Math 水题

    4436: Easy Math Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.scu.edu.cn/soj/problem.actio ...

随机推荐

  1. 洛谷 [p2294] [HNOI2005] 狡猾的商人

    差分约束做法 又是一道转换成前缀和的差分约束题,已知从s月到t月的收入w,设数组pre[i]代表从开始到第i个月的总收入 构造差分不等式 $ pre[s-1]-pre[t]==w $ 为了满足松弛操作 ...

  2. Selenium_chromedriver与chrome版本映射表(更新至v2)

    chromedriver.exe下载地址:http://chromedriver.storage.googleapis.com/index.html chromedriver版本 支持的Chrome版 ...

  3. Google 搜索引擎语法

    Google Hack原理很简单,就是利用搜索引擎强大的搜索能力,来查找一些存在漏洞的网站.要利用Google来查找网站的漏洞自然要学会Google这个搜索引擎的语法了.下面先给大家讲解一下Googl ...

  4. LNMP搭建02 -- 编译安装Nginx

    [编译安装Nginx]   为了顺利安装Nginx,先安装下面这些: [CentOS 编译 nginx 前要做的事情] yum install gcc gcc-c++ kernel-devel yum ...

  5. 某控股公司OA系统ORACLE DG搭建

    *此处安装ORACLE DATAGUARD是利用ORACLE RMAN DUPLICATE方式安装.*可以搭建好ORACLE DG再来impdp生产数据,也可以先导入主库数据再来做DG*注意看下面的配 ...

  6. [NOIP2001提高组]数的划分

    题目描述 将整数n分成k份,且每份不能为空,任意两个方案不相同(不考虑顺序). 例如:n=7,k=3,下面三种分法被认为是相同的. 1,1,5; 1,5,1; 5,1,1; 问有多少种不同的分法. 输 ...

  7. CentOS 挂载 cdrom, iso文件作为源

    在生产系统环境中的机器都没有连接互联网,因此都是使用本地源. 首先,需要将cdrom, 或 iso文件挂载到本地目录. 1.挂载光驱: 将cdrom 放入光驱. $  mkdir /media/cdr ...

  8. 老男孩Python全栈开发(92天全)视频教程 自学笔记21

    day21课程内容:  json: #序列化 把对象(变量)从内存中 编程可存储和可传输的过程 称为序列化import jsondic={'name':'abc','age':18}with open ...

  9. CodeForces-749A

    要求组成n的素数最多,根据n的奇偶讨论:如果n是偶数,直接打印n/2个数字'2'就可以了:如果n是基数,则先打印一个'3',再打印(n-3)/2个数字'2'就可以了. AC代码: #include&l ...

  10. Jmeter简单介绍与搭配Jenkins实现自动化

    Jmeter简介 Apache JMeter 是 Apache 组织开发的基于 Java 的压力测试工具.用于对软件做压力测试,它最初被设计用于 Web应用测试,但后来扩展到其他测试领域. 它可以用于 ...