POJ Costume Party
来源:互联网 发布:上海银行mac控件下载 编辑:程序博客网 时间:2024/04/29 08:01
Description
It's Halloween! Farmer John is taking the cows to a costume party, but unfortunately he only has one costume. The costume fits precisely two cows with a length of S (1 ≤ S ≤ 1,000,000). FJ has Ncows (2 ≤ N ≤ 20,000) conveniently numbered 1..N; cow i has length Li (1 ≤ Li ≤ 1,000,000). Two cows can fit into the costume if the sum of their lengths is no greater than the length of the costume. FJ wants to know how many pairs of two distinct cows will fit into the costume.
Input
* Line 1: Two space-separated integers: N and S
* Lines 2..N+1: Line i+1 contains a single integer: Li
Output
* Line 1: A single integer representing the number of pairs of cows FJ can choose. Note that the order of the two cows does not matter.
Sample Input
4 63521
Sample Output
4
题解
翻译看百度,水题。
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<iostream>#include<algorithm>using namespace std;int n,m,ans,a[20001];int main(){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++) scanf("%d",&a[i]);sort(a+1,a+n+1);for(int i=1;i<n;i++) {if(a[i]+a[i+1]>=m) break; for(int j=i+1;j<=n;j++) {if(a[i]+a[j]<=m) ans++;else break; } }printf("%d\n",ans);return 0;}
- POJ 3663 costume party
- poj 3633 Costume Party
- poj 3663 Costume Party
- POJ 3663 Costume Party
- POJ Costume Party
- POJ-3663-Costume Party
- POJ 3663:Costume Party
- Costume Party POJ
- Costume Party poj 3663 c++
- POJ 3363 Costume Party sort
- POJ 3663 Costume Party G++
- poj 3663 Costume Party 【简单搜索】
- poj 3663 Costume Party(快排)
- POJ 3663 Costume Party (二分查找)
- POJ 3663 Costume Party (二分查找)
- [思路题] poj 3663 Costume Party
- POJ 3663 Costume Party(模拟+减枝)
- Poj-3663-Costume Party-双指针扫描
- Python-- easy_install 的安装
- java.lang.OutOfMemoryError: PermGen space及其解决方案
- #pragma pack(push,1)与#pragma pack(1)的区别
- 二分匹配的讲解
- Simple prefix compression
- POJ Costume Party
- 冷少到底在身边
- ez_setup.py 网址
- Activity的启动、关闭、数据传输
- LeetCode Merge k Sorted Lists
- 2014.5.19 完成DM作业1
- IOS 生成Framwork
- openswan 连接EC2-VPN(Amazon)
- 歌神”张学友