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> ...
随机推荐
- unity3d插件Daikon Forge GUI 中文教程6-高级控件richtextlabel的使用
3.5.richtextlabel文本 可以像Word文档一样编辑出多样的内容,图片,字体颜色大小下划线.超链接背景等等. Defaults: 默认字体 默认图集 Blank Texture :空白的 ...
- ckeditor简单的演示
先把ckeditor文件添加到项目中 然后在页面上引用 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml& ...
- SQL异常:ORA-00936: missing expression
select * from t_user where id in()当条件in的内容为空时抛 java.sql.SQLException: ORA-00936: missing expression ...
- java web重定向与转发
首先定义一下这两个词: 重定向是将用户从当前页面或servlet定向到另外一个jsp页面或者servlet 转发是将用户对当前jsp页面或者servlet对象的请求转发给另外一个jsp页面或者serv ...
- error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCR...
http://blog.csdn.net/playstudy/article/details/6661868 一,问题描述MSVCRTD.lib(crtexew.obj) : error LNK201 ...
- HashMap实现原理分析
1. HashMap的数据结构 数据结构中有数组和链表来实现对数据的存储,但这两者基本上是两个极端. 数组 数组存储区间是连续的,占用内存严重,故空间复杂的很大.但数组的二分查找时间复杂度小,为O(1 ...
- Choose Concurrency-Friendly Data Structures
What is a high-performance data structure? To answer that question, we're used to applying normal co ...
- Asp.net DropDownList 自定义样式(想怎么改就怎么改!)
最近在做一个asp.net的项目,需要对默认的dropdownlist样式进行美化,固有的dropdownlist的小箭头实在让人无法接受,于是开始在百度,google 上下求索,天不负有心人,终于找 ...
- Java 实现MapReduce函数
明白了MapReduce程序的工作原理之后,下一步就是写代码来实现它.我们需要三样东西:一个map函数.一个reduce函数和一些用来运行作业的代码.map函数由Mapper类来表示,后者声明一个ma ...
- Oracle 参数之_small_table_threshold
SQL> select * from v$version; BANNER ------------------------------------------------------------ ...