Pairwise Sum and Divide

题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1305

统计1和2的数量

1-1是2 1-x(不为1)是1 2-2是1

时间复杂度O(n)

#include<iostream>
using namespace std;

const int maxn=1e5+5;
int a[maxn],n,n1=0,n2=0;

int main()
{
    __int64 sum;

    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==1)
            n1++;
        else if(a[i]==2)
            n2++;
    }
    int n11=n1*(n1-1)/2,n1x=n1*(n-n1),n22=n2*(n2-1)/2;
    sum=n11*2+n22+n1x;
    cout<<sum;
}
时间: 2024-08-01 06:36:04

Pairwise Sum and Divide的相关文章

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的个数就行了. 1 #include<cstdio> 2 #include<algorithm> 3 using namespace std;

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

1289 大鱼吃小鱼 有N条鱼每条鱼的位置及大小均不同,他们沿着X轴游动,有的向左,有的向右.游动的速度是一样的,两条鱼相遇大鱼会吃掉小鱼.从左到右给出每条鱼的大小和游动的方向(0表示向左,1表示向右).问足够长的时间之后,能剩下多少条鱼? Input 第1行:1个数N,表示鱼的数量(1 <= N <= 100000). 第2 - N + 1行:每行两个数A[i], B[i],中间用空格分隔,分别表示鱼的大小及游动的方向(1 <= A[i] <= 10^9,B[i] = 0 或 1

51nod 1305 Pairwise Sum and Divide(数学分析题)

1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 取消关注 有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = 0 for i = 1 to A.length for j = i+1 to A.length sum = sum + Floor((A[i]+A[j])/(A[i]*A[j])) return sum

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

HackerRank 1305 Pairwise Sum and Divide 有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = 0 for i = 1 to A.length for j = i+1 to A.length sum = sum + Floor((A[i]+A[j])/(A[i]*A[j])) return sum 给出数组A,由你来计算fun(A)的结果.例如:A = {1, 4, 1},fun(A) = [5/4] + [2

1305 Pairwise Sum and Divide

基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = 0 for i = 1 to A.length for j = i+1 to A.length sum = sum + Floor((A[i]+A[j])/(A[i]*A[j])) return sum 给出数组A,由你来计算fun(A)的结果.例如:A = {1, 4, 1},fun(A) = [5/4] + [

[51nod] 1305 Pairwise Sum and Divide 数学

有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = 0 for i = 1 to A.length for j = i+1 to A.length sum = sum + Floor((A[i]+A[j])/(A[i]*A[j])) return sum 给出数组A,由你来计算fun(A)的结果.例如:A = {1, 4, 1},fun(A) = [5/4] + [2/1] + [5/4] = 1 + 2 + 1 = 4. Input 第1行:1

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

Output 输出fun(A)的计算结果. Input示例 3 1 4 1 Output示例 4 first try: #include "bits/stdc++.h" using namespace std; #define LL long long #define INF 0x3f3f3f3f3f #define PI acos(-1) #define N 100010 #define MOD 10 LL arr[N]; LL fun(int n){ LL sum=0; for(i

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

久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1305<< 有这样一段程序,fun会对整数数组A进行求值,其中Floor表示向下取整: fun(A) sum = 0 for i = 1 to A.length for j = i+1 to A.length sum = sum + Floor(

ACDream - Divide Sum

先上题目: Divide Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0;for(int i = 1; i <= n; i ++)    for(int j = 1; j <= n; j ++)        ans += a[i] / a[j];给出n,a[1]...a[