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
求Floor((A[i]+A[j])/(A[i]*A[j])) ,实际上就是求1的数量和2的数量,有多少1就加一个1,有多少个2就是n*(n-1)/2。
我这个代码写麻烦了:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; long long val[100005]; int main()
{ int i,i2,n,pos;
long long j,ans=0;
scanf("%d",&n); for(i=0;i<n;i++)
{
scanf("%lld",val+i);
}
sort(val,val+n); for(i=0;i<n;i++)
{
if(val[i]==1||val[i]==2)
{
for(j=i+1;j<n;j++)
{
ans+=floor((double)((double)(val[i]+val[j])/(double)(val[i]*val[j])));
}
}
else
{
break;
}
}
cout<<ans<<endl;
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
51nod 1305:Pairwise Sum and Divide的更多相关文章
- 1305 Pairwise Sum and Divide
1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 有这样一段程序,fun会对 ...
- Pairwise Sum and Divide 51nod
1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 有这样 ...
- 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 = ...
- 51nod1305 Pairwise Sum and Divide
题目链接:51nod 1305 Pairwise Sum and Divide 看完题我想都没想就直接暴力做了,AC后突然就反应过来了... Floor( (a+b)/(a*b) )=Floor( ( ...
- 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 = ...
- 51nod P1305 Pairwise Sum and Divide ——思路题
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...
随机推荐
- KAZE特征和各向异性扩散滤波
kaze feature: http://www.doc88.com/p-6911376909693.html 各向异性扩散滤波 Scale-space and edge detection usi ...
- Visual Studio中的“build”、“rebuild”、“clean”的区别
区别 rebuild基本相当于clean+build build只针对修改过的文件进行编译,rebuild会对所有文件编译(无论是否修改). clean 删除中间和输出文件,中间文件是指一些生成应用的 ...
- synchronized和锁(ReentrantLock) 区别
synchronized和锁(ReentrantLock) 区别 java的两种同步方式, Synchronized与ReentrantLock的区别 并发(一):理解可重入锁 可重入锁和不可重入锁 ...
- 8个最常用的Python内置函数,小白必备!
题图:Photo by Markus Spiske on Unsplash Python给我们内置了大量功能函数,官方文档上列出了69个,有些是我们是平时开发中经常遇到的,也有一些函数很少被用到,这里 ...
- S7-200 smart输入输出接口试验
工具 西门子 s7-200smart PLC 西门子s7-200 smart 试验 CPU型号是 SR30 这个 编译环境 符号 选择 了 "输入1"以后, 会自动的编地址为I0. ...
- 动手实验01-----vCenter 微软AD认证配置与用户授权
环境说明: AD域-> centaline.net 阅读目录: 1. 配置与AD认证源 2.权限角色 1. 配置与AD认证源 登陆vCenter后,在 系统管理 -> 配置 -> ...
- 获取指定进程号,并kill掉
直接上案例: 例子:获取nginx进程 方法:$ps -aux |grep nginx |grep -v grep |awk '{print $2}' 或者 $ps -ef |grep nginx ...
- php.basic.functions
array_unshift call_user_func_array闭包 下面是学院的代码 class Container { protected $binds; protected $instanc ...
- Hibernate--起步
1.配置对象 配置对象是你在任何 Hibernate 应用程序中创造的第一个 Hibernate 对象,并且经常只在应用程序初始化期间创造.它代表了 Hibernate 所需一个配置或属性文件.配置对 ...
- 7.Python列表
.button, #logout { color: #333; background-color: #fff; border-color: #ccc; } span#login_widget > ...