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 条边的权值. 思路:树链剖分之修 ...
随机推荐
- Java中的协变与逆变
Java作为面向对象的典型语言,相比于C++而言,对类的继承和派生有着更简洁的设计(比如单根继承). 在继承派生的过程中,是符合Liskov替换原则(LSP)的.LSP总结起来,就一句话: 所有引用基 ...
- 如何确定Redis集群中各个节点的主从关系
1.首先通过命令(以192.168.203.141为例,-c代表集群的意思) ./redis-cli -h 192.168.203.141 -p 8001 -c 2.然后在输入 cluster no ...
- 多选按钮CheckBox
main.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...
- Day3-C-Radar Installation POJ1328
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. ...
- express写的接口在疯狂刷新几十次后,服务器挂掉
用到的命令行: show status like 'Threads%'; show variables like '%max_connections%'; show global status lik ...
- Jquery插件---渐隐轮播
//需求:打开网页时,每秒钟自动切换下一张图片内容.也可以用鼠标点导航按钮进行图片切换 //代码如下 <!DOCTYPE html> <html lang="en" ...
- JavaScript深入理解对象方法——Object.entries()
Object.entries()方法返回一个给定对象自身可枚举属性的键值对数组,其排列与使用 for...in 循环遍历该对象时返回的顺序一致(区别在于 for-in 循环也枚举原型链中的属性) 示例 ...
- 032.SAP上用户无法打开PPE模块,查看并开通用户的PPE权限
01. 用户使用PPE模块之后,提示没有为iPPE工作台分配一个用户参数,如图所示: 02. 如果是管理员账号,则可以点击右下角的问号,来到下面界面 03.点击iPPE 用户分配者几个蓝色的字,进入下 ...
- 002. 使用IDEA创建MyBatis的JAVAWEB项目 ,每一步都有详细过程,完美绕过各种坑能正常运行
001. 我们新建一个Module,相当于一个工程里面的一个项目 002.选择空白的JAVA程序 003.输入项目的名字为mybatis001 004.我们对这个项目添加Support,各种框架依赖 ...
- 015.Delphi插件之QPlugins,FMX插件窗口
内嵌FMX的插件窗口,效果还是很可以的.退出时,会报错,很诡异啊. 主窗口代码如下 unit Frm_Main; interface uses Winapi.Windows, Winapi.Messa ...