Educational Codeforces Round 15 A, B , C 暴力 , map , 二分

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+10,M=1e6+10,inf=1e9+10,mod=1000000007;
int a[M];
int main()
{
    int x,y,z,i,t;
    scanf("%d",&x);
    int ans=0,sum=0,pre=0;
    for(i=1;i<=x;i++)
    {
        scanf("%d",&y);
        if(y>pre)
        sum++;
        else
        sum=1;
        pre=y;
        ans=max(ans,sum);
    }
    printf("%d\n",ans);
    return 0;
}

 

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+10,M=1e6+10,inf=1e9+10,mod=1000000007;
int er[50];
int a[M];
map<int,int>m;
int main()
{
    int x,y,z,i,t;
    for(i=1;i<=30;i++)
    er[i]=(1<<i);
    scanf("%d",&x);
    for(i=1;i<=x;i++)
    scanf("%d",&a[i]),m[a[i]]++;
    ll ans=0;
    for(i=1;i<=x;i++)
    {
        for(t=1;t<=30;t++)
        {
            int v=er[t]-a[i];
            if(v==a[i])
            ans+=m[v]-1;
            else
            ans+=m[v];
        }
    }
    printf("%I64d\n",ans/2);
    return 0;
}
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+10,M=1e6+10,inf=1e9+10,mod=1000000007;
ll a[M];
ll b[M];
int check(ll hh,int x,int y)
{
    int u=1;
    int v=1;
    while(u<=x)
    {
        if(v>y)
        return 0;
        if(a[u]>=b[v]-hh&&b[v]+hh>=a[u])
        u++;
        else
        v++;
    }
    return 1;
}
int main()
{
    int x,y,z,i,t;
    scanf("%d%d",&x,&y);
    for(i=1;i<=x;i++)
    scanf("%I64d",&a[i]);
    for(i=1;i<=y;i++)
    scanf("%I64d",&b[i]);
    sort(a+1,a+1+x);
    sort(b+1,b+1+y);
    ll st=0;
    ll en=2e9;
    while(st<en)
    {
        ll mid=(st+en)>>1;
        if(check(mid,x,y))
        en=mid;
        else
        st=mid+1;
    }
    printf("%I64d\n",st);
    return 0;
}

 

 

转载于:https://www.cnblogs.com/jhz033/p/5746229.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值