A. Maximum Increase
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.

A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.

Input

The first line contains single positive integer n (1 ≤ n ≤ 105) — the number of integers.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print the maximum length of an increasing subarray of the given array.

Examples
Input
5
1 7 2 11 15
Output
3
Input
6
100 100 100 100 100 100
Output
1
Input
3
1 2 3
Output
3
题意:找到连续的上升子序列;
思路:暴力就行;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=3e3+,M=1e6+,inf=1e9+,mod=;
int a[M];
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
int ans=,sum=,pre=;
for(i=;i<=x;i++)
{
scanf("%d",&y);
if(y>pre)
sum++;
else
sum=;
pre=y;
ans=max(ans,sum);
}
printf("%d\n",ans);
return ;
}
B. Powers of Two
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x).

Input

The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.

Examples
Input
4
7 3 2 1
Output
2
Input
3
1 1 1
Output
3
Note

In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).

In the second example all pairs of indexes (i, j) (where i < j) include in answer.

题意:n个数,选两个相加求为2的阶乘的个数;

思路:两个数相加最大为2e9,一共30个数;枚举二的阶乘;

   复杂度N*30;

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=3e3+,M=1e6+,inf=1e9+,mod=;
int er[];
int a[M];
map<int,int>m;
int main()
{
int x,y,z,i,t;
for(i=;i<=;i++)
er[i]=(<<i);
scanf("%d",&x);
for(i=;i<=x;i++)
scanf("%d",&a[i]),m[a[i]]++;
ll ans=;
for(i=;i<=x;i++)
{
for(t=;t<=;t++)
{
int v=er[t]-a[i];
if(v==a[i])
ans+=m[v]-;
else
ans+=m[v];
}
}
printf("%I64d\n",ans/);
return ;
}
C. Cellular Network
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line — the positions (x-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than r from this tower.

Your task is to find minimal r that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than r.

If r = 0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than r from this tower.

Input

The first line contains two positive integers n and m (1 ≤ n, m ≤ 105) — the number of cities and the number of cellular towers.

The second line contains a sequence of n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates ai are given in non-decreasing order.

The third line contains a sequence of m integers b1, b2, ..., bm ( - 109 ≤ bj ≤ 109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates bj are given in non-decreasing order.

Output

Print minimal r so that each city will be covered by cellular network.

Examples
Input
3 2
-2 2 4
-3 0
Output
4
Input
5 3
1 5 10 14 17
4 11 15
Output
3

题意:在一个数轴上,有n个城市,m个信号塔;给出城市和信号塔的位置,求最小的信号塔影响范围;

思路:二分答案,check一下就行了;注意爆int;

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=3e3+,M=1e6+,inf=1e9+,mod=;
ll a[M];
ll b[M];
int check(ll hh,int x,int y)
{
int u=;
int v=;
while(u<=x)
{
if(v>y)
return ;
if(a[u]>=b[v]-hh&&b[v]+hh>=a[u])
u++;
else
v++;
}
return ;
}
int main()
{
int x,y,z,i,t;
scanf("%d%d",&x,&y);
for(i=;i<=x;i++)
scanf("%I64d",&a[i]);
for(i=;i<=y;i++)
scanf("%I64d",&b[i]);
sort(a+,a++x);
sort(b+,b++y);
ll st=;
ll en=2e9;
while(st<en)
{
ll mid=(st+en)>>;
if(check(mid,x,y))
en=mid;
else
st=mid+;
}
printf("%I64d\n",st);
return ;
}

Educational Codeforces Round 15 A, B , C 暴力 , map , 二分的更多相关文章

  1. Codeforces Educational Codeforces Round 15 A. Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Educational Codeforces Round 8 A. Tennis Tournament 暴力

    A. Tennis Tournament 题目连接: http://www.codeforces.com/contest/628/problem/A Description A tennis tour ...

  3. Codeforces Educational Codeforces Round 15 C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. Educational Codeforces Round 15 (A - E)

    比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...

  5. Educational Codeforces Round 15 C. Cellular Network(二分)

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  6. Educational Codeforces Round 15 C 二分

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  7. Educational Codeforces Round 15 A dp

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

  9. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. 【BZOJ5056】OI游戏 最短路+有向图生成树计数

    [BZOJ5056]OI游戏 Description 小Van的CP最喜欢玩与OI有关的游戏啦~小Van为了讨好她,于是冥思苦想,终于创造了一个新游戏. 下面是小Van的OI游戏规则: 给定一个无向连 ...

  2. org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception

    RabbitMQ   报出的错! org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException ...

  3. 学习 Tornado

    异步编程 预习 lambda Lambda functions can be used wherever function objects are required. They are syntact ...

  4. Exploiting second-order SQL injection 利用二阶注入获取数据库版本信息 SQL Injection Attacks and Defense Second Edition

    w SQL Injection Attacks and Defense  Second Edition Exploiting second-order SQL injection Virtually ...

  5. text files and binary files

    https://en.wikipedia.org/wiki/Text_file https://zh.wikipedia.org/wiki/文本文件

  6. JavaScript跳出iframe框架

    一.window.top top属性返回最顶层的先辈窗口. 该属性返回对一个顶级窗口的只读引用.如果窗口本身就是一个顶级窗口,top属性存放对窗口自身的引用.如果窗口是一个框架,那么top属性引用包含 ...

  7. JVM 指令讲解

    挺有意思的  转载记录下 转载自 https://www.cnblogs.com/f1194361820/p/8524666.html    原作者: 房继诺 JVM 指令 1.Demo 2.Clas ...

  8. GDI+的应用

    在VS中创建窗体 (1)CDI+清除绘画面 在窗体中写入代码: protected override void OnPaint(PaintEventArgs e){ Graphics g=e.Grap ...

  9. OpenCV3计算机视觉+python(三)

    使用OpenCV3处理图像 下面要介绍的内容都与图像处理有关,这时需要修改图像,比如要使用具有艺术性的滤镜.外插(extrapolate)某些部分.分割.粘贴或其他需要的操作. 不同色彩空间的转换 O ...

  10. 联想Y50用U盘改装win7的详细教程

    由于一些原因,部分网友想把自带的win8.1系统改成win7,苦于Y50没有光驱,装系统不方便,下面特意做一个用U盘改装系统的教程,先准备一个8G或更大的U盘,如果里面有重要文件,请先备份,等会要清空 ...