2015弱校联盟(1) - B. Carries
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的更多相关文章
- 2015弱校联盟(2) - J. Usoperanto
J. Usoperanto Time Limit: 8000ms Memory Limit: 256000KB Usoperanto is an artificial spoken language ...
- 2015弱校联盟(1) - C. Censor
C. Censor Time Limit: 2000ms Memory Limit: 65536KB frog is now a editor to censor so-called sensitiv ...
- 2015弱校联盟(1) - I. Travel
I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...
- 2015弱校联盟(1) -J. Right turn
J. Right turn Time Limit: 1000ms Memory Limit: 65536KB frog is trapped in a maze. The maze is infini ...
- 2015弱校联盟(1) -A. Easy Math
A. Easy Math Time Limit: 2000ms Memory Limit: 65536KB Given n integers a1,a2,-,an, check if the sum ...
- 2015弱校联盟(1) - E. Rectangle
E. Rectangle Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class name ...
- (2016弱校联盟十一专场10.3) D Parentheses
题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...
- (2016弱校联盟十一专场10.3) B.Help the Princess!
题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...
- (2016弱校联盟十一专场10.3) A.Best Matched Pair
题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...
随机推荐
- js 节点属性
节点属性 在文档对象模型 (DOM) 中,每个节点都是一个对象.DOM 节点有三个重要的属性 : 1. nodeName : 节点的名称 2. nodeValue :节点的值 3. nodeType ...
- shell 常用正则
shell常用正则表达式 “^\d+$” //非负整数(正整数 + 0) “^[0-9]*[1-9][0-9]*$” //正整数 “^((-\d+)|(0+))$” //非正整数(负整数 ...
- centos6.6 安装 LXC
LXC,简称Linux containers是docker基础,无奈只能先学习LXC.LXC用途就不多讲,这里只讲LXC的安装以及用途吧! LXC 需要用在内核2.6.27以上 这个可以用 uname ...
- A Great Alchemist
Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB ProblemCarol is a great alchemist. In ...
- Oracle 常用数据类型(转)
varchar2(6) 张三 --在jbk中是两个字节,在utm中是三个字节char(6) 张 三 --可以确定长度的用charclob --大存储,没事少用,当多余4000字节时,会用lob来存储, ...
- 【代码升级】【iCore3 双核心板】例程二十八:FSMC实验——读写FPGA
实验指导书及代码包下载: http://pan.baidu.com/s/1qXAxwgk iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- JSP Standard Tag Library JSP标准标签库
了解了基本的标签的底层实现,可以看系统定义的强大的标准标签 1.首先引入两个jar包 2.基本语法 <%@ taglib prefix="c" uri="http: ...
- 淘宝天猫网站停止支持IE6、IE7浏览器,你还在用xp吗?
2016年4月14日,是科比正式告别篮球的最后一场球赛.大家都在忙着各种纪念和怀念着看科比打球的青葱岁月.不过已经完美谢幕.而我们今天要说的是微软的IE6.IE7浏览器.淘宝网和天猫商城正式停止支持I ...
- Pinyin 输入法安装 opensuse 13 gnome
1 安装 拼音输入法 zypper in pinyin (scim 包含) 2 安装包 scim,scim-m17n,scim-pinyin,scim-qtimm,scim-tables,s ...
- 将一个query后面的参数转为数组
function detailUri($params) { $returnParams = array(); if (isset($params)) { $arParams = explode(&qu ...