这题没名字

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. SpringAOP

    首先导包, 我用的是Spring4.0.4;需要这三个包 Spring-AOP-4.0.4.REALEASE.jar + Spring-aspect-4.0.4.REALEASE.jar +aspec ...

  2. DHCP协议格式、DHCP服务搭建、DHCP协商交互过程入门学习

    相关学习资料 http://www.rfc-editor.org/rfc/rfc2131.txt http://baike.baidu.com/view/7992.htm?fromtitle=DHCP ...

  3. The AndroidManifest.xml File

    manifest (船运的)载货清单 http://www.android-doc.com/guide/topics/manifest/manifest-intro.html Every applic ...

  4. MyEclipse------制作通讯录

    addinfo.java public class addinfo extends HttpServlet { private String url="jdbc:mysql://localh ...

  5. Docker系列之(三):Docker微容器Alpine Linux

    1. 前言 使用Docker创建容器时,基础镜像通常选择Ubuntu或Centos,不管哪个镜像的大小都在100MB以上. Alpine Linux是一个面向安全的轻型的Linux发行版. Alpin ...

  6. mysql gb2312与lanti1

    1.如果数据库编码为lanti1,页面编码utf-8和gb2312均可,并且不用set names,设置就会乱码: 2.如果数据库编码为utf8,页面编码utf-8和gb2312均可,一定要设置好se ...

  7. MySQL 高效分页

    create PROCEDURE USP_GetByPager( _pageindex int, _pagesize int ) BEGIN )*_pagesize; select * from A ...

  8. C# 三种实现抖屏的方式

    //int a = -2; //this.BringToFront(); //for (int i = 0; i < 20; i++) //{ // a = -a; // this.Locati ...

  9. [整理]Code::Blocks使用遇到的问题

    在使用其编写C小程序的过程总会遇到些问题,特整理如下: 1.无法调试 注意的是项目所在的文件路径不能包含中文. 2.头文件接口函数申明引用无效 查看头文件是否处于可编译状态,左侧项目文件列表里是文件名 ...

  10. cocos基础教程(11)事件分发机制

    cocos3.0的事件分发机制: 创建一个事件监听器-用来实现各种触发后的逻辑. 事件监听器添加到事件分发器_eventDispatcher,所有事件监听器有这个分发器统一管理. 事件监听器有以下几种 ...