NEFU 2016省赛演练一 I题 (模拟题)
这题没名字
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题 (模拟题)的更多相关文章
- NEFU 2016省赛演练一 F题 (高精度加法)
Function1 Problem:F Time Limit:1000ms Memory Limit:65535K Description You know that huicpc0838 has b ...
- NEFU 2016省赛演练一 B题(递推)
HK Problem:B Time Limit:2000ms Memory Limit:65535K Description yy is interested in numbers and yy nu ...
- 2019浙大校赛--A--Thanks, TuSimple!(简单模拟题)
这题前三段都是一堆吹爆赞助商的屁话,正式题目在图片下边,一个简单模拟题. 题目大意: 有n个男生,m个女生在进行舞会,其中一部分男生祥和比自己矮的女生跳舞,一部分男生想和比自己高的女生跳舞,一部分女生 ...
- Codeforces Round #237 (Div. 2) B题模拟题
链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...
- HDOJ-6666(简单题+模拟题)
quailty and ccpc hdoj-6666 题目很简单,按照题目的意思模拟就行了,排序. #include<iostream> #include<cstdio> #i ...
- ZOJ1111:Poker Hands(模拟题)
A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...
- SCNU ACM 2016新生赛决赛 解题报告
新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- 2016湖南省赛----G - Parenthesis (括号匹配)
2016湖南省赛----G - Parenthesis (括号匹配) Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...
随机推荐
- 【poj2079】 Triangle
http://poj.org/problem?id=2079 (题目链接) 题意 求凸包内最大三角形面积 Solution 旋转卡壳. 只会n²的做法,但是竟然过了.就是枚举每一个点,然后旋转卡壳另外 ...
- HDU2096 小明A+B
入门级都没到的水题!看到顺便就做了,AC记录喜+1 Description 小明今年3岁了, 现在他已经能够认识100以内的非负整数, 并且能够进行100以内的非负整数的加法计算. 对于大于等于100 ...
- TCP/IP详解 学习七
静态选路的前提: 1) 网络比较小 2) 网络之间单点连接 3) 网络之间没有多余的路由 动态选路协议,用于路由器之间的通信,有以下几种: 1) ...
- Mac OS X 10.9 Mavericks安装后,Xcode调试时模拟器黑屏的处理方法
请耐心的等下去吧,少年! 装了Mac OS X 10.9 Mavericks的同学,如果碰到Xcode调试App时,模拟器黑屏(重置也无效),请耐心的等下去吧,大约10来分钟左右黑屏就会消失,App启 ...
- POJ2387 Til the Cows Come Home(SPFA + dijkstra + BallemFord 模板)
Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37662 Accepted ...
- 求一元二次方程ax^2+bx+c=0的解
Console.WriteLine("求解方程ax^2+bx+c=0的解."); Console.WriteLine("请分别输入a,b,c的值(注意每输入一个值按一下回 ...
- 生成元(Digit Generator ,ACM/ICPC Seoul 2005 ,UVa 1583)
生成元:如果 x 加上 x 各个数字之和得到y,则说x是y的生成元. n(1<=n<=100000),求最小生成元,无解输出0. 例如:n=216 , 解是:198 198+1+9+8=2 ...
- app 后端技术
app 后端技术 一直以来工作的方向是web server,对app server没有什么了解.虽然没有接触过移动app开发,但对app后端技术还是挺有探索欲望的,app应用和web应用在前端的用户习 ...
- NC反弹CMDSHELL提权总结
Server-U等都不可以用的情况下. 一般都可思考用此方法不过这种方法, 只要对方装了防火墙, 或是屏蔽掉了除常用的那几个端口外的所有端口… 那么这种方法也失效了…. 1:通过shell将上 ...
- html空格小结
按下space键产生的空格.在HTML中,如果你用空格键产生此空格,空格是不会累加的(只算1个).要使用html实体表示才可累加,该空格占据宽度受字体影响明显而强烈. 它叫“半角空格”, 透明 ...