zoukankan      html  css  js  c++  java
  • ACM:SCU 4437 Carries

    SCU 4437  Carries
    Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

    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

    1i<jnh(ai,aj)∑1≤i<j≤nh(ai,aj)
    .

    Input

    The input consists of multiple tests. For each test:

    The first line contains 11 integer nn (2n1052≤n≤105). The second line contains nn integers a1,a2,,ana1,a2,…,an. (0ai1090≤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<<"]
    "
    #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
    ",ans);
    	}	
    	return 0;
    } 
    
    
    

      

     
     
  • 相关阅读:
    全内存的redis用习惯了?那能突破内存限制类redis产品ssdb呢?
    multi_compile
    MVVM
    Gamma Correction
    Animator状态快速切换问题
    SVN 不显示状态图标--解决方法
    Rendering with Replaced Shaders
    MySql权威指南
    Effective C++
    帧同步
  • 原文地址:https://www.cnblogs.com/HDMaxfun/p/5785254.html
Copyright © 2011-2022 走看看