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 ...
随机推荐
- k短路模板 POJ2449
采用A*算法的k短路模板 #include <iostream> #include <cstdio> #include <cstring> #include < ...
- 编写服务器程序时遇到的connect:no route to host的问题
亲测,,ftp服务器:在一台虚拟机上,没有问题.但是在不同的计算机或虚拟机上就会出现这种错误提示.一般是linux防火墙的问题 解决方法: 关闭linux防火墙 在root账户下 命令行:servic ...
- vue项目基本流程
一.做项目基本流程: 1.规划组件结构 Nav.vue Header.vue Home.vue..... 2.编写对应路由 vue-router 3.具体些每个组件功能 一些公共的文件jquery,j ...
- 【原】font-awesome IE6支持代码本人测试成功
<!--[if (gte IE 6)&(lte IE 8)]> <script type="text/javascript" src="js/n ...
- 利用GUID唯一标识符并设置它的过期时间
项目中遇到一个小问题,就是把服务器创建的GUID发送给客户端,客户端接收后,下次访问时带上这个GUID, 服务端这边就进行验证,并做相应的处理. 问题是:项目中还需要这个GUID带过期时间,那是如何设 ...
- js压缩上传图片
初学有不当之处,请多多指点, <body> <div class="cc"> <input type="file" id=&quo ...
- wangeditor Demo
<html> <head> <!--在这里字符集的设定很重要,如果设定不当将会出现乱码--> <meta charset="UTF-8"& ...
- ORACLE数据库SQL优化 not in 与not exits
各个表的数据量: sys_file_convert_queue 65989sys_att_file 73061sys_att_main 84405sys_att_rtf_data 1507 优化前,执 ...
- bzoj 3576[Hnoi2014]江南乐 sg函数+分块预处理
3576: [Hnoi2014]江南乐 Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 1929 Solved: 686[Submit][Status ...
- JS标签的各种事件的举例
1.鼠标单击事件( onclick ) <!DOCTYPE HTML> <html> <head> <meta http-equiv="Conten ...