51nod 1305 Pairwise Sum and Divide
收起
输入
第1行:1个数N,表示数组A的长度(1 <= N <= 100000)。
第2 - N + 1行:每行1个数A[i](1 <= A[i] <= 10^9)。
输出
输出fun(A)的计算结果。
输入样例
3
1 4 1
输出样例
4 暴力应该会超时吧,可以找规律,这样一道题不能说上来就暴力,和除以积向下取整,可以分解(x+y)/x*y = 1/x+1/y,是两个分子为1的分数的和,这样我们发现如果1/x+1/y小于1,那么原分数的值将为0,也就是说原分数取值也就是0,1,2这三种,x和y都是1那么就是取值2,x和y一个是1,另一个不是1,那么就取值1,或者x和y都是2,取值1,其他的都是0.
代码:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
typedef pair<int,int> pa;
int n,sum,a,b;
int s[];
int main() {
scanf("%d",&n);
for(int i = ;i < n;i ++) {
scanf("%d",&s[i]);
if(s[i] == ) a ++;
else if(s[i] == ) b ++;
}
sum = a * (n - ) + b * (b - ) / ;
printf("%d",sum);
}
51nod 1305 Pairwise Sum and Divide的更多相关文章
- 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 = ...
- 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 P1305 Pairwise Sum and Divide ——思路题
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...
- 51nod1305 Pairwise Sum and Divide
题目链接:51nod 1305 Pairwise Sum and Divide 看完题我想都没想就直接暴力做了,AC后突然就反应过来了... Floor( (a+b)/(a*b) )=Floor( ( ...
- 51nod 1305:Pairwise Sum and Divide
1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 有这样一段 ...
- Pairwise Sum and Divide 51nod
1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 有这样 ...
随机推荐
- 【Python开发】PyInstaller打包Python程序
PyInstaller是一个能将Python程序转换成单个可执行文件的程序, 操作系统支持Windows, Linux, Mac OS X, Solaris和AIX.并且很多包都支持开箱即用,不依赖环 ...
- elasticsearch 管理常用命令集合
elasticsearch rest api遵循的格式为: curl -X<REST Verb> <Node>:<Port>/<Index>/<T ...
- Influx Sql系列教程五:insert 添加数据
接下来开始进入influxdb的curd篇,首先我们看一下如何添加数据,也就是insert的使用姿势 在进入本篇之前,对于不了解什么是retention policy, tag, field的同学,有 ...
- javaScript Es6数组与对象的实例方法
个人心得 我们在没有接触Es6方法之前,做一些算法之类的事情是就比较麻烦,在做的过程中也要考虑很多的问题,比较麻烦,而Es6的方法正是来方便我们在平常运用时能够将问题简便化,大大的减少我们的日常代码 ...
- 【转】Lombok介绍、使用方法和总结
链接:http://www.yuanrengu.com/index.php/20180324.html 1 Lombok背景介绍 官方介绍如下: Project Lombok makes java a ...
- PHP字符串替换
$pid = str_replace(',',',',$pid); $pid = str_replace(' ','',$pid); $pid = str_replace(array(',', ' ' ...
- go对elasticsearch的增删改查
环境 elasticsearch 6.8 (6.x版本应该都没问题) go客户端sdk: github.com/elastic/go-elasticsearch/v6 其实自己封装api也行,反正el ...
- Fiddler代理手机抓包
Fiddler代理手机抓包 0. 安装Fiddler 1. 安装HTTPS证书并允许远程连接 Tools - Options 点击OK后重启Fiddler. 确保手机与当前电脑在同一局域网. 然后在手 ...
- tkinter python(图形开发界面) 转自:渔单渠
Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.Tk和Tkinter可以在大多数的Unix平台下使用,同样可以应用在Windows和Macinto ...
- [LOJ2292] [THUSC2016] 成绩单
题目链接 LOJ:https://loj.ac/problem/2292 洛谷:https://www.luogu.org/problemnew/show/P5336 Solution 区间\(\rm ...