B - Fence Repair - 中南林业科技大学第十一届程序设计大赛

链接:https://www.nowcoder.com/acm/contest/124/B
来源:牛客网

题目描述
Founded in 1958, CSUFT has developed into a multidisciplinary university comprising a wide range of disciplines in science, engineering, agriculture, arts, law, economics, management and education, and has been authorized to offer a comprehensive range of programs including bachelor, master, doctor’s programs and post-doctoral programs. Since its foundation, the university has turned out over 160,000 talents. CSUFT is located in the national historical and cultural city : Changsha.

The above is the history of our school. The next is the description of this problem ^_^.

Giving n numbers,Cyl want to find the answer how many pairs of these numbers meet the condition of Ai *2 = Aj (i < j). Please you tell him.

Please note that there are many groups of samples.
输入描述:
Line 1: Oneinteger N, the number of numbers. (1 < N <= 100)
Lines 2…..N+1: Each line contains a single integer ai. (0< ai < 100)
输出描述:
Line 1: One integer.
示例1
输入

3
1
2
2
输出

2

[分析]
之前有几个数是现在这个数的一半,满足就在ans+上这个数量
所以边输入边计算就好了。

[代码]

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define MOD  1000000007
int main()
{
    int n;
    while (scanf("%d", &n) != EOF)
    {
        int a[100];
        memset(a, 0, sizeof(a));
        int now,ans=0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &now);
            if (now % 2 == 0 && a[now / 2])
            {
                ans +=a[now / 2];
            }
            a[now]++;
        }
        printf("%d\n", ans);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值