Carries SCU - 4437
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 xxand 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
.
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 nn integersa1,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这题题目简单粗暴 ,给你一个长度为n的数组,求出这个数组中任意两个数相加进位的次数
20
这题是一个想法题,把一个数的每一位都分离出来,进行处理也就是取模运算
int cnt=lower_bound(b,b+n,temp)-b; lower_bound的返回值是一个元素的指针,b为头指针
两者相减就是这个元素与头元素之间有多少个元素。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
long long a[],b[];
int main() {
int n;
while(scanf("%d",&n)!=EOF){
for (int i= ;i<n ;i++){
scanf("%lld",&a[i]);
}
long long s=,ans=;
for (int k= ;k< ;k++ ,s=s*){
for (int i= ;i<n ;i++ ){
b[i]=a[i]%s;
}
sort(b,b+n);
long long temp;
for (int i= ;i<n ;i++){
temp=s-b[i];
if (b[n-]>=temp){
int cnt=lower_bound(b,b+n,temp)-b;
if (cnt>i) ans+=n-cnt;
else ans+=n--i;
}
}
}
printf("%lld\n",ans);
}
return ;
}
Carries SCU - 4437的更多相关文章
- ACM:SCU 4437 Carries - 水题
SCU 4437 Carries Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice ...
- SCU 4437 Carries(二分乱搞)题解
题意:问任意两对ai,aj相加的总进位数为多少.比如5,6,95分为(5,6)(5,95)(6,95),进位数 = 1 + 2 + 2 = 5 思路:显然暴力是会超时的.我们可以知道总进位数等于每一位 ...
- ACM: SCU 4438 Censor - KMP
SCU 4438 Censor Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice D ...
- ACM: SCU 4440 Rectangle - 暴力
SCU 4440 Rectangle Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practic ...
- 2015弱校联盟(1) - B. Carries
B. Carries Time Limit: 1000ms Memory Limit: 65536KB frog has n integers a1,a2,-,an, and she wants to ...
- SCU 4424(求子集排列数)
A - A Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice ...
- SCU 2941 I NEED A OFFER!(01背包变形)
I NEED A OFFER! 64bit IO Format: %lld & %llu Submit Status Description Description Speakless ...
- SCU 4440 分类: ACM 2015-06-20 23:58 16人阅读 评论(0) 收藏
SCU - 4440 Rectangle Time Limit: Unknown Memory Limit: Unknown 64bit IO Format: %lld & %llu ...
- scu 4436: Easy Math 水题
4436: Easy Math Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.scu.edu.cn/soj/problem.actio ...
随机推荐
- bzoj 4869: [Shoi2017]相逢是问候 [扩展欧拉定理 线段树]
4869: [Shoi2017]相逢是问候 题意:一个序列,支持区间\(a_i \leftarrow c^{a_i}\),区间求和.在模p意义下. 类似于开根操作,每次取phi在log次后就不变了. ...
- BZOJ 4698: Sdoi2008 Sandy的卡片 [后缀自动机]
4698: Sdoi2008 Sandy的卡片 题意:差分后就是多个串LCS SAM+map大法好 模板打错 智力-2 #include <iostream> #include <c ...
- POJ 3348 Cows [凸包 面积]
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9022 Accepted: 3992 Description ...
- BZOJ 1367: [Baltic2004]sequence [可并堆 中位数]
1367: [Baltic2004]sequence Time Limit: 20 Sec Memory Limit: 64 MBSubmit: 1111 Solved: 439[Submit][ ...
- Go终端读写
终端读写 操作终端相关文件句柄常量 os.Stdin:标准输入 os.Stdout:标准输出 os.Stderr:标准错误输出 终端读写实例: package main import ( " ...
- [代码]JS原生Ajax,GET和POST
javascript/js的ajax的GET请求: <script type="text/javascript"> /* 创建 XMLHttpRequest 对象 */ ...
- 什么是 lnmp 实现原理。
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构. Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统.代表版本有:debian.centos ...
- python通过一个语句分析几个常用函数和概念
前言 过年也没完全闲着,每天用一点点时间学点东西,本文为大家介绍几个python操作的细节,包含all.any.for in等操作,以及介绍我解决问题的思路. 一.开篇 先从我看到的一个简单的语句开始 ...
- HTTP入门
请求报文图解: 请求报文 图片 响应报文图解: 响应报文
- linux服务器ssh、公匙和密钥实战详解
一..我们先建好一上haiwen用户用来,做为密码钥和SSH对像 二.修改vi /etc/ssh/sshd_config 文件,禁用ROOT远程直接登录. 三.ssh的公钥认证配置,只能用密匙才能登录 ...