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> ...
随机推荐
- php——用for循环打印半金字塔、金字塔、正方形、倒金字塔、菱形、空心图形等
1.半金字塔 $n=5; //控制层数 for($i=1;$i<=$n;$i++){ //控制每层的 “*” 数 for($j=1;$j<=$i;$j++){ echo "*& ...
- graph | hungary
匈牙利算法,求二分图最大匹配. 若P是图G中一条连通两个未匹配顶点的路径,并且属于M的边和不属于M的边(即已匹配和待匹配的边)在P上交替出现,则称P为相对于M的一条增广路径.(M为一个匹配) 由增广路 ...
- 通过方法名(字符串)执行Objective-C方法
SEL selector = NSSelectorFromString(@"方法名"); if ([self respondsToSelector:selector]){ //判断 ...
- Flink - RocksDBStateBackend
如果要考虑易用性和效率,使用rocksDB来替代普通内存的kv是有必要的 有了rocksdb,可以range查询,可以支持columnfamily,可以各种压缩 但是rocksdb本身是一个库,是跑在 ...
- backbone event 事件订阅 和发布 源码小读
nodejs有eventEmitter 类,想到backbone 有个event模块 可以对对象做事件绑定和触发,是backbone的核心模块. backbone event模块 on 添加自定义事 ...
- 《Linux内核设计与实现》CHAPTER4阅读梳理
<Linux内核设计与实现>CHAPTER4阅读梳理 [学习时间:3hours] [学习内容:多任务:进程调度策略:Linux中进程调度的关键问题:抢占] 个人思考部分见[]标出的部分 一 ...
- Android 通过 Wifi 调试 Debug (Android Studio)
参考资料: http://www.cnblogs.com/sunzhenxing19860608/archive/2011/07/14/2106492.html 前提: Android 手机 和 PC ...
- swift项目初体验--教你打造一款个性化图片浏览器(篇幅过大,慎入)
项目需求:做一个图片浏览器,点击图片查看大图,大图模式下,左右滚动能查看不同的图片. 项目的主要核心技术:图片的弹出和消失动画 项目源代码: Photo-Browser 一.对代码进行重构 ...
- 使用Go开发web服务器
原文链接 Go(Golang.org)是在标准库中提供HTTP协议支持的系统语言,通过他可以快速简单的开发一个web服务器.同时,Go语言为开发者提供了很多便利.这本篇博客中我们将列出使用Go开发HT ...
- Js拼Json对象
我们通常会拼字符串,但是拼字符串的话,遇见占位符会出错. 下面分享一个拼js拼json对象的方法: var jsonArr = []; $ ...