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 条边的权值. 思路:树链剖分之修 ...
随机推荐
- 还是应该立个flag
6月份 开通博客的想法很简单,就是决定要学习C++和算法,写博客作为督促自己的一个方式,因为还没有系统的学习,自认为写博客或见解有些力所不及,决定先从自己的一篇随笔开始,因为我知道自己一旦开始,就会坚 ...
- 「Luogu1231」教辅的组成
传送门 Luogu 解题思路 看到种匹配问题,马上想到最大流所以这就是一道SB题. 但是有一个小问题,就是每一本书都只能匹配一次,那么我们对所有书进行拆点即可,这个操作类似于这题 细节注意事项 细节有 ...
- 094、Java中String类之直接赋值时的堆内存自动引用
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- Python 矩阵相关
Python 中矩阵运算主要使用numpy库.NumPy的主要对象是同种元素的多维数组.这是一个所有的元素都是一种类型.通过一个正整数索引的元素表格(通常是元素是数字).因此对于随机查找来说,比pyt ...
- Xilinx COE文件格式小记
官方的参考文档是:https://www.xilinx.com/support/documentation/sw_manuals/xilinx11/cgn_r_coe_file_syntax.htm ...
- 2017北京网络赛 F Secret Poems 蛇形回路输出
#1632 : Secret Poems 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The Yongzheng Emperor (13 December 1678 – ...
- HDFS 命令行基本操作
1.hdfs命令行 (1)查看帮助 hdfs dfs -help (2)查看当前目录信息 hdfs dfs -ls / (3)上传文件 hdfs dfs -put /本地路径 /hdfs路径 (4)剪 ...
- POJ1471 Tree/洛谷P4178 Tree
Tree P4178 Tree 点分治板子. 点分治就是直接找树的重心进行暴力计算,每次树的深度不会超过子树深度的\(\frac{1}{2}\),计算完就消除影响,找下一个重心. 所以伪代码: voi ...
- Rolling Update【转】
滚动更新是一次只更新一小部分副本,成功后,再更新更多的副本,最终完成所有副本的更新.滚动更新的最大的好处是零停机,整个更新过程始终有副本在运行,从而保证了业务的连续性. 下面我们部署三副本应用,初始镜 ...
- 51nod 1441:士兵的数字游戏
1441 士兵的数字游戏 题目来源: CodeForces 基准时间限制:4 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 取消关注 两个士兵正在玩一个游戏,游戏开始的时 ...