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 = ...
随机推荐
- 数据库为什么要用B+树结构--MySQL索引结构的实现
原理: http://blog.csdn.net/cangchen/article/details/44818485 http://blog.csdn.net/kennyrose/article/de ...
- vue transition
Vue.js 教程 (9) : 过渡动画 Vue.js 提供非常简单的过渡动画接口.这些过渡动画在 Vue.js 将目标元素插入或移除出 DOM 的时候会自动执行.能够触发动画的指令包括 v-if , ...
- easyui validatebox 验证类型
required: "必选字段", remote: "请修正该字段", email: "请输入正确格式的电子邮件" ...
- Network Wars-ZOJ2676最小割+01规划
Time Limit: 5 Seconds Memory Limit: 32768 KB Special Judge Network of Byteland consists of n servers ...
- Spring获取bean的工具类
package com.tech.jin.util; import org.springframework.context.ApplicationContext; import org.springf ...
- 关于sqlserver 2008 无法远程连接的问题
Sqlserver 2008 无法远程连接,原因无非如下: 1. Sql未配置为允许TCP/IP登录: 2. 防火墙未允许端口1433(或者其他在SQL配置中指定的端口): 3. 命名实例导致的无法连 ...
- javascript 变量提前
1. 未声明变量时,结果是我们预期的结果,报错这个变量没有定义. (function() { // 报错:variable is not defined console.log(variable); ...
- python之路3:
class set(object): """ set() -> new empty set object set(iterable) -> new set o ...
- iOS改变字母的大小写
使用lowercaseString,uppercaseString -(void)test{ NSString * str = @"person"; NSString * str1 ...
- 长时间停留在calculating requirements and dependencies 解决方案
如果Eclipse花费了很长的时间calculating requirements and dependencies(计算需求和依赖性 ) 这个问题通常就是在点击安装之后显示“Calculating ...