题目链接:51nod 1305 Pairwise Sum and Divide

看完题我想都没想就直接暴力做了,AC后突然就反应过来了。。。

Floor( (a+b)/(a*b) )=Floor( (1/b)+(1/a) )

当a=1时:若b=1,则该式等于2,否则该式等于1

当a=b=2时:该式等于1

其余情况都等于0,所以只需要统计1和2的个数就行了。

 #include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
int n, i, a;
int s1 = , s2 = , ss = ;
scanf("%d", &n);
for(i = ; i < n; ++i){
scanf("%d", &a);
if(a == ) s1++;
else if(a == ) s2++;
else ss++;
}
ll ans = (ll)s1*(s1-) + (ll)s1*(s2+ss) + (ll)s2*(s2-)/;
printf("%lld\n", ans);
return ;
}

51nod1305 Pairwise Sum and Divide的更多相关文章

  1. Pairwise Sum and Divide 51nod

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

  2. 1305 Pairwise Sum and Divide

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

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

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

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

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

  5. 51nod 1305:Pairwise Sum and Divide

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

  6. 51nod P1305 Pairwise Sum and Divide ——思路题

    久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...

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

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

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

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

  9. 51nod 1305 Pairwise Sum and Divide

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

随机推荐

  1. python :表单验证--对每一个输入框进行验证

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  2. 如何在RCP程序中添加一个banner栏

    前言:这段时间还算比较空闲,我准备把过去做过的有些形形色色,甚至有些奇怪的研究总结一下,也许刚好有人用的着也不一定,不枉为之抓耳挠腮的时光和浪费的电力.以前有个客户提出要在RCP程序中添加一个bann ...

  3. shell脚本自动化部署XX的案例(附数组使用)

    #!/bin/sh #Auto Make install MFS Files # cat <<EOF ++++++++++++++++Welcome To Use Auto Install ...

  4. javaScript 将json字符串转换为json对象的方法解析

    JSON字符串: var str1 = '{ "name": "cxh", "sex": "man" }'; JSON对 ...

  5. XMLHttpRequest简介

    要真正实现这种绚丽的奇迹,必须非常熟悉一个 JavaScript 对象,即 XMLHttpRequest. 下面给出将要用于该对象的很少的几个 方法和属性. ·open():建立到服务器的新请求. · ...

  6. php数据类型及转换

  7. rabbitmq 3.6 延时消息

    rabbitmq-plugins enable rabbitmq_delayed_message_exchange #安装插件 https://github.com/rabbitmq/rabbitmq ...

  8. Ajax --- 数据请求

    下面主要介绍(JS原生)数据请求的主要步骤: Ajax 数据请求步骤: 1.创建XMLHttpRequest对象 2.准备数据发送 3.执行发送 4.指定回掉函数 第一步:创建XMLHttpReque ...

  9. IE9 打不开界面也不报错,只有打开控制台才会显示 - console

    IE9下,打开界面不报错也不展示数据,打开控制台时就能加载出数据,有可能是代码中有console

  10. localhost访问错误Forbidden You don't have permission to access / on this server.解决办法(亲测)

    在httpd.conf文件下找到这段: <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow D ...