ACM:SCU 4437 Carries - 水题
Description
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 xx and 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 integers a1,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
20
/*/
题意: 给你n个数,问其中任意两个数相加能够有多少次进位。 例子:1+99=100,个位进位一次,十位进位一次,就是两次; 50+50 十位进位一次,就是一次。 思维题,比较水的题目,一开始没有想到,想到了觉得好脑残的题目。 暴力会超时,直接sort再用lower_bound去找边界值,加上边界值就OK了。 AC代码:
/*/
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdlib"
#include"cstdio"
#include"string"
#include"vector"
#include"stack"
#include"queue"
#include"cmath"
#include"map"
using namespace std;
typedef long long LL ;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FK(x) cout<<"["<<x<<"]\n"
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
#define bigfor(T) for(int qq=1;qq<= T ;qq++) const int MX=1e5+1e3; LL num[MX],temp[MX]; int main(){
int n;
while(~scanf("%d",&n)){
LL ans=0,mod=1;
for(int i=1;i<=n;i++){
scanf("%lld",&num[i]);
}
for(int i=1;i<=9;i++){
mod*=10;
for(int i=1;i<=n;i++)temp[i]=num[i]%mod; //按照个位十位百位千位轮着保存所有的数。
sort(temp+1,temp+n+1);//排序
for(int i=1;i<=n;i++)ans+=n-(lower_bound(temp+i+1,temp+n+1,mod-temp[i])-temp)+1;
//如果某个数比此时mod-目标数大,那么这个数加上目标数就会进一位,把这些数个数求和。
}
printf("%lld\n",ans);
}
return 0;
}
ACM:SCU 4437 Carries - 水题的更多相关文章
- SCU 4437 Carries(二分乱搞)题解
题意:问任意两对ai,aj相加的总进位数为多少.比如5,6,95分为(5,6)(5,95)(6,95),进位数 = 1 + 2 + 2 = 5 思路:显然暴力是会超时的.我们可以知道总进位数等于每一位 ...
- ACM水题
ACM小白...非常费劲儿的学习中,我觉得目前我能做出来的都可以划分在水题的范围中...不断做,不断总结,随时更新 POJ: 1004 Financial Management 求平均值 杭电OJ: ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- scu 4436: Easy Math 水题
4436: Easy Math Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.scu.edu.cn/soj/problem.actio ...
- HDU ACM 1073 Online Judge ->字符串水题
分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- acm入门 杭电1001题 有关溢出的考虑
最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...
- Acdream 1111:LSS(水题,字符串处理)
LSS Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others) SubmitStati ...
- ytu 2558: 游起来吧!超妹!(水题,趣味数学题)
2558: 游起来吧!超妹! Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 7 Solved: 3[Submit][Status][Web Board ...
随机推荐
- asp rs开启关闭问题
使用rs.close关闭后,可以直接用rs.open来打开数据表:如果用了set rs = nothing 从内存中清除rs对象,再次加载rs对象就需要使用set rs=server.createob ...
- CSS3实现阴阳鱼
直接上代码: <!doctype html> <html> <head> <meta charset="utf-8" /> < ...
- R语言学习笔记-机器学习1-3章
在折腾完爬虫还有一些感兴趣的内容后,我最近在看用R语言进行简单机器学习的知识,主要参考了<机器学习-实用案例解析>这本书. 这本书是目前市面少有的,纯粹以R语言为基础讲解的机器学习知识,书 ...
- [Scala] 快学Scala A1L1
基础 1.1 声明值和变量 在Scala中,鼓励使用val; 不需要给出值或变量的类型,这个信息可以从初始化表达式推断出来.在必要的时候,可以指定类型. 在Scala中,仅当同一行代码中存在多条语句时 ...
- hibernate中数据库方言
在配置hibernate.cfg.xml时需指定使用数据库的方言: 例: <property name="dialect">org.hibernate.dialect. ...
- liunx中计算机壳层
什么是shell?shell是用C语言编写的程序.既是一种命令语言,又是一种程序设计语言.shell是一种应用程序,这个应用程序提供一个界面,用户通过这个界面访问系统内核的服务.在计算机科学中,She ...
- ACM/ICPC 之 电力网络-EK算法(POJ1459)
按照电站发电(从源点到电站),消费者消费(从消费者到汇点)的想法构建网络,以下是EK解法 //网络流EK算法 //Time:922Ms memory:224K #include<iostream ...
- 初学Redis(1)——认识Redis
Redis官网对Redis的定义是:“Redis is an open source, BSD licensed, advanced key-value cache and store”,可以看出,R ...
- <%#Eval if判断用法
1.绑定Repeater 基础用法 <%#Eval("RoleID")%> 2.简单判断用法 <td> <%# Convert.ToBoolean(E ...
- node04-buffer
目录:node01-创建服务器 node02-util node03-events node04-buffer node05-fs node06-path node07-http node08-exp ...