POJ 3663:Costume Party
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 12607 | Accepted: 4977 |
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 N cows (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 6
3
5
2
1
Sample Output
4
这两天做水题真是做的够了,这尼玛水平完全没有什么提高。
题意是给出的数组中判断有多少个两个数的和小于等于给定的数。
一开始觉得so easy,结果TLE。。。
之后sort一下,判断大于的就跳出才能符合要求。
代码:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
using namespace std; int num[20005]; int main()
{
int N,S,i,j;
scanf("%d%d",&N,&S);
int result=0;
for(i=1;i<=N;i++)
{
scanf("%d",&num[i]);
} sort(num+1,num+N+1); for(i=1;i<=N;i++)
{
for(j=1;j<i;j++)
{
if(num[i]+num[j]<=S)
{
result++;
}
else
{
break;
}
}
} printf("%d\n",result); return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 3663:Costume Party的更多相关文章
- POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- POJ 1459:Power Network(最大流)
http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...
- POJ 3436:ACM Computer Factory(最大流记录路径)
http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...
- POJ 2195:Going Home(最小费用最大流)
http://poj.org/problem?id=2195 题意:有一个地图里面有N个人和N个家,每走一格的花费是1,问让这N个人分别到这N个家的最小花费是多少. 思路:通过这个题目学了最小费用最大 ...
- POJ 3281:Dining(最大流)
http://poj.org/problem?id=3281 题意:有n头牛,f种食物,d种饮料,每头牛有fnum种喜欢的食物,dnum种喜欢的饮料,每种食物如果给一头牛吃了,那么另一个牛就不能吃这种 ...
- POJ 3580:SuperMemo(Splay)
http://poj.org/problem?id=3580 题意:有6种操作,其中有两种之前没做过,就是Revolve操作和Min操作.Revolve一开始想着一个一个删一个一个插,觉得太暴力了,后 ...
- POJ 3237:Tree(树链剖分)
http://poj.org/problem?id=3237 题意:树链剖分.操作有三种:改变一条边的边权,将 a 到 b 的每条边的边权都翻转(即 w[i] = -w[i]),询问 a 到 b 的最 ...
- POJ 2763:Housewife Wind(树链剖分)
http://poj.org/problem?id=2763 题意:给出 n 个点, n-1 条带权边, 询问是询问 s 到 v 的权值, 修改是修改存储时候的第 i 条边的权值. 思路:树链剖分之修 ...
随机推荐
- flutter JSON序列化出现冲突
[SEVERE] Conflicting outputs were detected and the build is unable to prompt for permission to remov ...
- django 配置404,500页面
JSP CURL session COOKIE diango 自定义404 500页面 1.首先将settings设置debug=false; 2.设置static路径 ...
- python异常处理(学习)
异常处理可以保证程序在恶劣的环境也能运行,或者给用户相关的提示 如下是运行异常的情况 如无异常 也可以创建异常处理类型
- IdentityServer4专题之三:OAuth、SSO和OpenID
一.oauth 典型案例:如果一个用户R拥有两项服务:一项服务是图片在线存储服务A,另一个是图片在线打印服务B.由于服务A与服务B是由两家不同的服务提供商提供的,所以用户在这两家服务提供商的网站上各自 ...
- CSS-fontface
@font-face { font-family: <identifier>; src: <fontsrc> [, <fontsrc>]*; <font> ...
- NFC性价比高频读卡器首选方案:FM17550
FM17550具有低电压.低功耗.驱动能力强.多接口支持.多协议支持等特点.适用于低功耗.低电压.低成本要求的非接触读写器应用,及NFC协议兼容的NFC设备. FM17550是一款高度集成的工作在13 ...
- ROS大型工程学习(四)一键安装所有缺失的依赖!!!
在正文之前,我必须向rosdep道个歉,前面那篇常用命令行中没有它的位置,现在单独写一篇补充!! 突然发现rosdep有个惊人的功能, rosdep install --from-paths src ...
- 机器学习(ML)八之正向传播、反向传播和计算图,及数值稳定性和模型初始化
正向传播 正向传播的计算图 通常绘制计算图来可视化运算符和变量在计算中的依赖关系.下图绘制了本节中样例模型正向传播的计算图,其中左下角是输入,右上角是输出.可以看到,图中箭头方向大多是向右和向上,其中 ...
- C++代做,C++编程代做,C++程序代做,留学生C++ Lab代写
C++代做,C++编程代做,C++程序代做 我们主要面向留学生,广泛接美加澳国内港台等地编程作业代写,中英文均可. C语言代写 C++代写 Python代写 Golang代写 Java代写 一年半的时 ...
- 015.Oracle数据库,取本月月初,取本月月末
/*取本月月初,取本月月末*/ SELECT trunc( SYSDATE, 'mm' ) AS 月初 , last_day(trunc(sysdate)) AS 月末 FROM dual; 修改如下 ...