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 条边的权值. 思路:树链剖分之修 ...
随机推荐
- centos7 bond双网卡
[root@pay network-scripts]# cat ifcfg-bond0 |grep -v \#TYPE="Ethernet"PROXY_METHOD="n ...
- 《Netlogo多主体建模入门》笔记4
4- 从Langton的蚂蚁看Turtle与Patch的交互 这只蚂蚁从10000步开始,就会自发地 “建桥” Turtle与Patch就好比是,一个方块和一个格子的关系. 一个格子上可以 ...
- WDSL文件中的XML元素
WDSL文件中的XML元素 理解起来其实很简单Types指定类型,当然是在后面的Message中需要的类型Message可以理解为函数中的参数,只不过如果一个函数如果有多个参数的时候应该吧这些参数定义 ...
- CentOS7虚拟机配置、Hadoop搭建、wordCount DEMO运行
安装虚拟机 最开始先安装虚拟机,我是12.5.7版本,如果要跟着我做的话,版本最好和我一致,不然后面可能会出一些莫名其妙的错误,下载链接如下(注册码也在里面了): 链接:https://pan.bai ...
- 物流跟踪 调用快递鸟API
概要:关于调用快递鸟API,我有几句话想说,有几行代码想写 业务需求:就是做做商城,卖卖东西.然后需要做个物流跟踪的功能 需要获取的信息大概就是这个样子 现在看这个快递怎么这么慢 如何实现? 直接调用 ...
- Vue项目中v-for无法渲染数据
在Vue项目中,我们想要实现下面的布局效果 后端返回的数据格式如下,可以看出产品列表五张图的数据位于同一个数组中 而我的html结构如下: 我希望直接渲染左边一张大图,然后右边的四张小图通过v-for ...
- 第1节 IMPALA:8、shell交互窗口使用;9、外部和内部shell参数
impala当中的元数据的同步的问题impala当中创建的数据库表,直接就可以看得到,不用刷新hive当中创建的数据库表,需要刷新元数据才能够看得到 因为impala的catalog的服务,我们需要通 ...
- day02-Python运维开发基础
1. Number 数据类型 2. 容器数据类型-字符串 """ 语法: "字符串" % (值1,值2 ... ) 占位符: %d 整型占位符 %f ...
- jenkins#安装docker
环境:centos7 安装依赖包 yum install -y yum-utils device-mapper-persistent-data lvm2 添加Docker软件包源 yum-config ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-plus
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...