A. Reconnaissance
来源:互联网 发布:mac 梦幻西游手游网页 编辑:程序博客网 时间:2024/05/28 15:27
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights area1,?a2,?...,?an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1,?2) and (2,?1) should be regarded as different.
The first line contains two integers n and d (1?≤?n?≤?1000,?1?≤?d?≤?109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
5 10
10 20 50 60 65
6
5 1
55 30 29 31 55
6
/* ***********************************************
Author :
Created Time :2015/6/14 11:33:10
File Name :7.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
int a[maxn];
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n,d;
while(cin>>n>>d){
for(int i=1;i<=n;i++)
cin>>a[i];
int ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(abs(a[i]-a[j])<=d&&i!=j)ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
- A. Reconnaissance
- A. Reconnaissance 2
- A. Reconnaissance 2
- 【水排序】#32 A. Reconnaissance
- CodeForces 34A Reconnaissance 2
- CODEFORCES, 34A,Reconnaissance 2
- Reconnaissance
- Directory traversal as a reconnaissance tool
- A - Reconnaissance 2 士兵 立正啦…
- 【水数组】#34 A. Reconnaissance 2
- Codeforce 34A-Reconnaissance 2(水)
- Reconnaissance 2(水题)
- Review: SANS SEC550 Information Reconnaissance
- Testing: Conduct search engine discovery/reconnaissance for information leakage (OTG-INFO-001)
- a
- a
- a
- a
- A. Next Test
- Oracle内置表二
- A. Spit Problem
- A. Accounting
- A. Worms Evolution
- A. Reconnaissance
- 重新认识——CSS Position定位
- A. What is for dinner?
- 设计模式:建造者模式(Builder)
- A. Reconnaissance 2
- A. Shell Game
- A. Extra-terrestrial Intelligence
- A. Towers
- A. Find Color