51nod1305 Pairwise Sum and Divide
题目链接: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的更多相关文章
- Pairwise Sum and Divide 51nod
1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 有这样 ...
- 1305 Pairwise Sum and Divide
1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 有这样一段程序,fun会对 ...
- 1289 大鱼吃小鱼 1305 Pairwise Sum and Divide 1344 走格子 1347 旋转字符串 1381 硬币游戏
1289 大鱼吃小鱼 有N条鱼每条鱼的位置及大小均不同,他们沿着X轴游动,有的向左,有的向右.游动的速度是一样的,两条鱼相遇大鱼会吃掉小鱼.从左到右给出每条鱼的大小和游动的方向(0表示向左,1表示向右 ...
- 1305 Pairwise Sum and Divide(数学 ,规律)
HackerRank 1305 Pairwise Sum and Divide 有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = ...
- 51nod 1305:Pairwise Sum and Divide
1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 有这样一段 ...
- 51nod P1305 Pairwise Sum and Divide ——思路题
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...
- 51Nod 1305 Pairwise Sum and Divide | 思维 数学
Output 输出fun(A)的计算结果. Input示例 3 1 4 1 Output示例 4 first try: #include "bits/stdc++.h" using ...
- [51nod] 1305 Pairwise Sum and Divide 数学
有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = 0 for i = 1 to A.length for j = ...
- 51nod 1305 Pairwise Sum and Divide
有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = 0 for i = 1 to A.length for j = ...
随机推荐
- CSS3中毛玻璃效果的使用方法
今天在使用icloud的时候看到苹果icloud官网的毛玻璃效果非常赞,仔细研究了一下它的实现方式,是使用js配合background-image: -webkit-canvas的形式绘制出的毛玻璃背 ...
- Nginx的安装配置
1.安装PCRE库 $ cd /usr/local/ $ https://sourceforge.net/projects/pcre/files/pcre/8.36/ $ tar -zxvf pcre ...
- 一个ubuntu phper的自我修养(atom)
将atom打造成二十一世纪最装那啥的php IDE 之前在windows平台使用的php IDE一直是eclipse for php,因为之前做java开发,所以对eclipse很有感情,debug. ...
- NSValue 类的使用
NSValue对象是用来存储一个C或者Objective-C数据的简单容器.它可以保存任意类型的数据int,float,char等,也可以是指pointers, structures, and obj ...
- Learning by doing
Learning by doing 绪论:读了娄老师的公众号中--<做中学(Learning By Doing)>这篇文章后,深有感触,我想到很多自己之前的事情,很多都是每每想的很好,总是 ...
- Query Designer:Variable 变量
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- less文件编译成微信小程序wxss文件
2016年9月21日,微信小程序正式开启内测.在微信生态下,触手可及.用完即走的微信小程序引起广泛关注,刷爆朋友圈子.在这样的火爆氛围中,作为一个前端开发者的我,也悄悄地去尝鲜.在做demo小示例的过 ...
- attr和prop区别
今天写了个小程序,获取input[checked]属性,$('#check1').attr('checked'),结果返回undefined,查询了一番, 如果是具有true和false两个属性值的属 ...
- github项目配置
准备工作: 下载一个git: https://git-scm.com/downloads 1.登陆到github 登陆地址:https://github.com/login 2.创建新项目 3.配置 ...
- (原创)Xilinx的ISE生成模块ngc网表文件
ISE中,右击“Synthesize”,选中“Process Properties”,将“Xilinx Specific Options:-iobuf”的对勾取消. 将取消模块的ioBuff,因为模块 ...