这题没名字

Problem:I

Time Limit:2000ms

Memory Limit:65535K

Description

Now give you an interger m and a sequence: s[1], s[2], ...... , s[N] in not decreasing order. The length of the sequence is n. Your task is to find out how many pair of a and b satisfy a+b=m. Note that each element of the sequence can use once at most. 

Input

The input consists of multiple test cases. The first line of each test case contains three integers N(0<n<=1000000), M(0<m<=1000000000), which denote the length of the sequence and the sum of a+b, respectively. The next line give n interger(0<s[i]<=10000000)。 Note the input is huge.

Output

For each case, output the num of pairs in one line.

Sample Input

3 3
1 1 2
3 2
1 1 1
5 5
1 1 2 3 4

Sample Output

1
1
2

题意:给定n和m,输入n个数,判断在这些数中有多少组两个数的和为m。
题解:用while跑是最快的,跑n存在风险,跑数组可能超时,跑m一定超时。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll a[];
int main()
{
ll i,n,m,data;
while(scanf("%lld%lld",&n,&m)!=EOF)
{
memset(a,,sizeof(a));
for(i=;i<n;i++)
scanf("%lld",&a[i]);
ll ans=;
sort(a,a+n);
ll l=,r=n-;
while(l<r)
{
if(a[l]+a[r]>m)
r--;
else if(a[l]+a[r]<m)
l++;
else
{
ans++;
r--;
l++;
}
}
printf("%lld\n",ans);
}
return ;
}

NEFU 2016省赛演练一 I题 (模拟题)的更多相关文章

  1. NEFU 2016省赛演练一 F题 (高精度加法)

    Function1 Problem:F Time Limit:1000ms Memory Limit:65535K Description You know that huicpc0838 has b ...

  2. NEFU 2016省赛演练一 B题(递推)

    HK Problem:B Time Limit:2000ms Memory Limit:65535K Description yy is interested in numbers and yy nu ...

  3. 2019浙大校赛--A--Thanks, TuSimple!(简单模拟题)

    这题前三段都是一堆吹爆赞助商的屁话,正式题目在图片下边,一个简单模拟题. 题目大意: 有n个男生,m个女生在进行舞会,其中一部分男生祥和比自己矮的女生跳舞,一部分男生想和比自己高的女生跳舞,一部分女生 ...

  4. Codeforces Round #237 (Div. 2) B题模拟题

    链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...

  5. HDOJ-6666(简单题+模拟题)

    quailty and ccpc hdoj-6666 题目很简单,按照题目的意思模拟就行了,排序. #include<iostream> #include<cstdio> #i ...

  6. ZOJ1111:Poker Hands(模拟题)

    A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...

  7. SCNU ACM 2016新生赛决赛 解题报告

    新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...

  8. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  9. 2016湖南省赛----G - Parenthesis (括号匹配)

    2016湖南省赛----G - Parenthesis (括号匹配)   Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...

随机推荐

  1. TYVJ1939 玉蟾宫

    背景 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. 描述 这片土地被分成N*M个格子,每个格子里写着'R'或者'F',R代 ...

  2. Myeclipse连接mysql数据库

    第一步:下载mysql驱动 驱动地址:http://www.mysql.com/products/connector/ .选择JDBC Driver for MySQL (Connector/J). ...

  3. 学习使用Robot Framework自动化测试框架-web元素定位

    转:http://blog.csdn.net/u012145166/article/details/50342569 1.name和id 其中使用到了name和id定位.但有时候由于开发人员的疏忽或者 ...

  4. C++ STL之stack

    因为总用vector,却忘记了有stack,今天用到栈顶的值才想起来,说起来stack很方便,也很容易用,看下边例子: #include<stack> #include<iostre ...

  5. pthread_create线程创建的过程剖析

    http://blog.csdn.net/wangyin159/article/details/47082125 在Linux环境下,pthread库提供的pthread_create()API函数, ...

  6. Iterator<转>

    Iterator就是迭代器的意思. Iterator是一个接口,利用迭代器主要是获取元素,很少删除元素.有三个方法:    1)hasNext():判断是否有更多的元素,如果有返回true.    2 ...

  7. 新浪微博客户端(10)-切换多个fragment

    ViewController.m #import "ViewController.h" #import "DJOneViewController.h" #imp ...

  8. 【转】linux expr命令参数及用法详解

    在抓包过程中,查看某个设定时间内,数据上下行多少,用命令expr 计算! --------------------------------------------------------------- ...

  9. http 超文本传输协议

    超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准.设计HTTP最初的目的是为了提供一种发布和接 ...

  10. PQ格式化虚拟机硬盘如何生效

    用pq格式化虚拟机硬盘后,安装时,总是从dhcp的网卡启动,没有从硬盘启动 但是用ghost是可以拷贝镜像文件的 这就是说,硬盘有了,但是没有将硬盘"激活",没有将硬盘设为acti ...