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 xx and 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 nnintegers a1,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 个数,C(n,2) 这两个数可能进位,问,所有的进位次数是多少? //题解: 容易想到,枚举可能进位的位置,最多也就9次么,然后二分找可能进位的个数
答案要LL,还wa了一发
 # include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
#define LL long long
#define lowbit(x) ((x)&(-x))
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MOD 1000000007 inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
#define MX 100005
/**************************/
int n;
int a[MX];
int yu[MX]; int bi_search(int l,int r,int w)
{
int pos = -;
while (l<=r)
{
int mid = (l+r)/;
if (yu[mid]>=w)
{
pos = mid;
r = mid-;
}
else l = mid+;
}
return pos;
} int main()
{
while (scanf("%d",&n)!=EOF)
{
int mmm=;
for (int i=;i<=n;i++)
{
a[i] =scan();
mmm = max(mmm,a[i]);
}
LL ans = ;
int y = ;
while(y)
{
y*=;
for (int i=;i<=n;i++)
yu[i] = a[i]%y;
sort(yu+,yu++n);
for (int i=;i<=n;i++)
{
int pos = bi_search(,n,y-(a[i]%y));
if (pos!=-)
{
int num = n-pos+;
if (a[i]%y<yu[pos]) ans += (LL)num;
else ans += (LL)num-;
}
}
if (y>mmm) break;
}
printf("%lld\n",ans/);
}
return ;
}
 

Carries的更多相关文章

  1. ACM:SCU 4437 Carries - 水题

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

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

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

  3. HDU 4588 Count The Carries 数学

    Count The CarriesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  4. HDU 4588 Count The Carries 计算二进制进位总数

    点击打开链接 Count The Carries Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java ...

  5. Carries SCU - 4437

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

  6. 二分 + 模拟 - Carries

    Carries Problem's Link Mean: 给你n个数,让你计算这n个数两两组合相加的和进位的次数. analyse: 脑洞题. 首先要知道:对于两个数的第k位相加会进位的条件是:a%( ...

  7. HDU 4588 Count The Carries(数学统计)

    Description One day, Implus gets interested in binary addition and binary carry. He will transfer al ...

  8. hdu4588Count The Carries

    链接 去年南京邀请赛的水题,当时找规律过的,看它长得很像数位dp,试了试用数位dp能不能过,d出每位上有多少个1,然后TLE了..然后用规律优化了前4位,勉强过了. 附数位dp代码及找规律代码. #i ...

  9. HDU 4588 Count The Carries(找规律,模拟)

    题目 大意: 求二进制的a加到b的进位数. 思路: 列出前几个2进制,找规律模拟. #include <stdio.h> #include <iostream> #includ ...

随机推荐

  1. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)人机界面Paintbuffer Overflow怎么办

    当在界面上绘制了太多元素时,点击运行会在左上角弹出对话框提示内容容量不够   在英文版的说明中,点击Visualization Manager就可以进行设置     更多教学视频和资料下载,欢迎关注以 ...

  2. JAVA 模块

    commons-lang3 maven repository, 项目主页 fastjson maven repository, 项目主页 fastjson 是阿里巴巴开源的序列化和反序列化 JSON ...

  3. 由friend用法引出的声明与定义那些事儿

    今天遇到了一个问题,大致描述一下就是有两个类A和B.我想达到如下效果:B是A的友元,同时A是B的类类型成员. 第一次尝试,在B.h中包含A.h,在A.h中包含B.h,在A类中声明friend clas ...

  4. JAVA的IO操作:内存操作流

    掌握内存操作流 输入和输出都是从文件中来的,当然,也可将输出的位置设置在内存上,这就需要ByteArrayInputStream和ByteArrayOutputStream ByteArrayInpu ...

  5. (三)Oracle学习笔记—— sql语句

    0. scott 用户默认表介绍 scott用户Tables目录下包含四张表 1. insert(插入)语句 给指定列插入数据: ,'xx'); 插入全部列数据: ,'xx','lll'); 2. u ...

  6. SVN环境搭建(2)

    原文地址:http://www.penglig.com/post-73.html TortoiseSVN的使用. 首先打开VisualSVN Server Manager,如图: 可以在窗口的右边看到 ...

  7. [UIDevice currentDevice].model

    iPhone Simulator iPad Simulator iPod touch iPad iPhone  

  8. tcp/ip ---数据链路层

  9. GroupCoordinator joingroup源码解析

    转发请注明原创地址 http://www.cnblogs.com/dongxiao-yang/p/7463693.html kafka新版consumer所有的group管理工作在服务端都由Group ...

  10. 使用pycharm手动搭建python语言django开发环境(四) django中buffer类型与str类型的联合使用

    在django中,如果用到buffer类型时,buffer的编码格式是utf-8类型.使用str()进行转为字符串类型会异常. 异常会有如下提示:'ascii' codec can't decode ...