久しぶり!

发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题。。(在大佬题解的帮助下)

原题戳>>https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1305<<

有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整:
fun(A)
    sum = 0
    for i = 1 to A.length
        for j = i+1 to A.length
            sum = sum + Floor((A[i]+A[j])/(A[i]*A[j])) 
    return sum
给出数组A,由你来计算fun(A)的结果。例如:A = {1, 4, 1},fun(A) = [5/4] + [2/1] + [5/4] = 1 + 2 + 1 = 4。
Input
第1行:1个数N,表示数组A的长度(1 <= N <= 100000)。
第2 - N + 1行:每行1个数A[i](1 <= A[i] <= 10^9)。
Output
输出fun(A)的计算结果。
Input示例
3
1 4 1
Output示例
4
一开始看到这个公式,直接脑补到了求并联电路电阻和的公式,然后神TM在这上面找规律。。。然后gg
其实这题的数字中只有1和2是有作用的。从公式里可以看出,两者都大于2的所有组合在向下取整后都会为0
例如5 7 ——>5+7/5x7<1--->0
而2和2组合则是1 2 2——>2+2/2*2=1
1和其他如何数组合都是1
所以这题统计一下3个数据——1的数目、2的数目、其他数数目(总数减前两者)即可。
之后再把他们按前面的结论组合求解即可,代码如下:
#include<iostream>
#include<stdio.h>
using namespace std;
int a[];
int main()
{
int n,i,j,e1=,e2=;
cin>>n;
for(i=;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]==) e1++;
if(a[i]==) e2++;
}
long long ans=;
ans+=(e1-)*(e1-)+(e1-);
ans+=e1*(n-e1);
ans+=((e2-)*(e2-)+(e2-))/;
cout<<ans<<endl;
}




51nod P1305 Pairwise Sum and Divide ——思路题的更多相关文章

  1. 51Nod 1305 Pairwise Sum and Divide | 思维 数学

    Output 输出fun(A)的计算结果. Input示例 3 1 4 1 Output示例 4 first try: #include "bits/stdc++.h" using ...

  2. [51nod] 1305 Pairwise Sum and Divide 数学

    有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整:   fun(A)     sum = 0     for i = 1 to A.length         for j = ...

  3. 51nod 1305 Pairwise Sum and Divide

    有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整:   fun(A)     sum = 0     for i = 1 to A.length         for j = ...

  4. 51nod1305 Pairwise Sum and Divide

    题目链接:51nod 1305 Pairwise Sum and Divide 看完题我想都没想就直接暴力做了,AC后突然就反应过来了... Floor( (a+b)/(a*b) )=Floor( ( ...

  5. Pairwise Sum and Divide 51nod

      1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 有这样 ...

  6. 51nod 1305:Pairwise Sum and Divide

    1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 有这样一段 ...

  7. 1305 Pairwise Sum and Divide

    1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 有这样一段程序,fun会对 ...

  8. 1305 Pairwise Sum and Divide(数学 ,规律)

    HackerRank   1305 Pairwise Sum and Divide   有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整:   fun(A)     sum = ...

  9. 1289 大鱼吃小鱼 1305 Pairwise Sum and Divide 1344 走格子 1347 旋转字符串 1381 硬币游戏

    1289 大鱼吃小鱼 有N条鱼每条鱼的位置及大小均不同,他们沿着X轴游动,有的向左,有的向右.游动的速度是一样的,两条鱼相遇大鱼会吃掉小鱼.从左到右给出每条鱼的大小和游动的方向(0表示向左,1表示向右 ...

随机推荐

  1. P1601 A+B Problem(高精加法)

    [高精度就是一个固定的格式吧] #include<iostream>#include<cstdio>#include<cmath>#include<algor ...

  2. slideDown留言板

    <!doctype html> <html lang="en"> <head> <meta http-equiv="Conten ...

  3. The Little Prince-12/02

    The Little Prince-12/02 What moves me so deeply, about this little prince who is sleeping here, is h ...

  4. centos6二进制安装mysql5.5

    centos 6.5,安装mysql 5.5.60 所需安装包mysql-5.5.60-linux-glibc2.12-x86_64.tar.gz.ncurses-devel-5.7-4.200902 ...

  5. CRC、MD5和SHA1的区别?

    什么是CRC校验?CRC即循环冗余校验码:是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并将 ...

  6. LVS+Keepalived+Mysql+主主数据库架构[2台]

    架构图 安装步骤省略. 158.140 keepalived.conf ! Configuration File for keepalived global_defs { #全局标识模块 notifi ...

  7. python简说(二十二)写日志

    分四个级别 import nnloglog = nnlog.Logger('book_server.log') log.debug('xxx值是什么')log.info('调用了什么xxx')log. ...

  8. C++进程间通信之共享内存

    转载:http://blog.csdn.net/taily_duan/article/details/51692999 转载:http://blog.csdn.net/fengrx/article/d ...

  9. java开发注意点之String使用equals和==的区别

    "=="操作符的作用 1.用于基本数据类型的比较 2.判断引用是否指向堆内存的同一块地址. equals所在位置: 在Object类当中,而Object是所有类的父类,包含在jdk ...

  10. 同时import两个版本的QtQuick【1、2】,默认使用

    在同一个qml文件中,如果同时import了Qtquick1和2,那么谁在后面,谁起作用