http://poj.org/problem?id=3663

二分查找

 #include <stdio.h>
#include <stdlib.h> int a[]; int bs(int l, int r, int v)
{
int m;
while(l < r)
{
m = (l + r) >> ;
if(a[m] < v)
{
l = m + ;
}
else
{
r = m;
}
}
return l;
} int cmp0(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
} int main()
{
int n, s;
int i, count = ;
int temp;
scanf("%d%d", &n, &s);
for(i=; i<=n; i++)
{
scanf("%d", a+i);
}
qsort(a+, n, sizeof(a[]), cmp0);
a[n+] = (<<) - ;
for(i=; i<=n; i++)
{
if(a[i] < s)
{
temp = bs(i+, n+, s-a[i]+);
count += temp-i-;
//printf("%d %d\n", i, temp-i-1);
}
}
printf("%d\n", count);
return ;
}

pku3663 Costume Party的更多相关文章

  1. POJ 3663:Costume Party

    Costume Party Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12607   Accepted: 4977 De ...

  2. Lesson 17 Always young

    Text My aunt Jennifer is an actress. She must be at least thirty-five years old. In spit of this, sh ...

  3. C#设计模式之建造者模式

    建造者模式可以将部件本身和它们的组装过程分开,关注如何一步步创建一个包含多个组成部分的复杂对象,用户只需要指定复杂对象的类型即可得到该对象,而无须知道其内部的具体构造细节. 建造者模式:将一个复杂对象 ...

  4. Hollister Outlet Store

    (link to hollisterco site), It's a major try. After a photographer's viewpoint, Which roughly splend ...

  5. Lightoj 题目1422 - Halloween Costumes(区间DP)

    1422 - Halloween Costumes   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  6. Chinese culture

      文房四宝 笔墨纸砚是中国古代文人书房中必备的宝贝,被称为“文房四宝”.用笔墨书写绘画在 中国可追溯到五千年前.秦(前221---前206)时已用不同硬度的毛和竹管制笔:汉代(前206—公元220) ...

  7. News common vocabulary

    英语新闻常用词汇与短语 经济篇 accumulated deficit 累计赤字 active trade balance 贸易顺差 adverse trade balance 贸易逆差 aid 援助 ...

  8. [zz]The Royal Treatment

    http://www.cgw.com/Publications/CGW/2012/Volume-35-Issue-4-June-July-2012/The-Royal-Treatment.aspx T ...

  9. 【Origin】jquery.barddialog.js

    /// <reference path="jquery-2.1.1.min.js" /> /** * @license jquery.bardDialog 1.0.0 ...

随机推荐

  1. 运行所有sdk目录下的示例,查看它们的功能,方便以后查寻

    运行所有sdk目录下的示例,查看它们的功能,方便以后查寻

  2. HDU 1253 (简单三维广搜) 胜利大逃亡

    奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz 而且我也优化过了的啊,尼玛还是一直爆! 先把代码贴上睡觉去了,明天再来弄 //#define LOCAL #include <ios ...

  3. Asp.Net验证码3

    using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System. ...

  4. BZOJ 4557 侦查守卫

    好迷的树形dp... #include<iostream> #include<cstdio> #include<cstring> #include<algor ...

  5. 51nod 最长递增子序列

    nlogn版最长递增子序列.线段树.(其实常数蛮大的....) #include<iostream> #include<cstring> #include<algorit ...

  6. tornado 实践 - 目录结构

    . ├── README.md └── store_management ├── Session.vim ├── auth │   ├── __init__.py │   ├── views.py ├ ...

  7. SQLServer的最大连接数 超时时间已到 但是尚未从池中获取连接

    很多做架构设计.程序开发.运维.技术管理的朋友可能或多或少有这样的困惑: SQLServer到底支持多少连接数的并发? SQLServer是否可以满足现有的应用吗? 现有的技术架构支持多少连接数的并发 ...

  8. 【英语】Bingo口语笔记(54) - how to date a foreigner

  9. AIX 第3章 指令记录

    [ssdb01.shz.hn|oracle|/home/oracle]$oslevel -rq  --查看系统已安装的维护级别 Known Recommended Maintenance Levels ...

  10. Btn要记得对状态进行设置

    self.catBtn = [UIButtonbuttonWithType:UIButtonTypeSystem]; self.catBtn.backgroundColor = [UIColorred ...