链接: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);
}
}