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. 读取Properties配置文件, 四种方式都可以得到webroot/WEB-INF/classes这个路径

    下面四种方式都可以得到webroot/WEB-INF/classes这个路径,有什么区别,哪种方式最好? String path = this.getClass().getResource(" ...

  2. Selenium webdriver Java 操作chrome 浏览器

    Step1: 下载chromedriver. 下载路径: http://chromedriver.storage.googleapis.com/index.html 选择一个合适的下载即可.我下载的是 ...

  3. MySQL 创建数据库及数据表

    1.创建数据库 (1) 命令行创建 [root@host]# mysqladmin -u root -p create RUNOOB Enter password:****** (2) php创建 语 ...

  4. CoolHash数据库引擎压测对比报告

    Coolhash 当前性能指标:读写吞吐量超过百万,千万级别查询1秒完成,连续48小时打满CPU强压力运行稳定.redis官方公布读写性能在10万 tps,leveldb官方公布写性能在40万tps, ...

  5. atitit.Atitit.检测文本文件的编码 java  与php版  。Net

    atitit.Atitit.检测文本文件的编码 java  与php版  .Net 1 检测编码原理 Utf8>>gbk 在此转会gbk>>utf 2 工具检测编码 不能使用l ...

  6. C语言基础(17)-作用域

    一个C语言变量的作用域可以是代码块 作用域,函数作用域或者文件作用域. 不推荐写法 int a; // 出现了语法的二义性,可能是声明也可能是定义,所以最好定义完成之后声明 void func();  ...

  7. ubuntu 下查看某个包是否 安装

    dpkg -l   dpkg -l|grep package-name   dpkg --status package-name   查看/var/lib/dpkg/status 内容

  8. jquery中绑定点击事件

    $("body").on("click",".tab-contentBox td",function(){}; $(".tab-c ...

  9. iOS Socket/Tcp编程 GCDAsyncSocket的实战(带回调)

    很多同学一听到Socket TCP UDP 这几个字眼感觉特别害怕,很怕在工作当中使用,因为他们太底层了.下面我把我在工作中使用Socket类库GCDAsyncSocket进行一次实战 文章中只适用于 ...

  10. Vim使用技巧(4) -- 命令行模式 【持续更新】

    基本保存,退出,帮助 :help //帮助 :w //保存 :q //退出 :wq //保存后退出 :q! //强制不保存退出 %s/a/b/g //将当前文件的a全部替换成b /abc //正向查找 ...