zoukankan      html  css  js  c++  java
  • 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
    ",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
    ",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
    ",st);
        return 0;
    }
  • 相关阅读:
    Git:本地文件到远程仓库
    logstash.conf 配置:input kafka,filter,output elasticsearch/mysql
    PowerDesigner根据Excel设计数据表结构 Excel表结构导入PowerDesigner
    VBScript PowerDesigner使用手册
    PowerDesigner导出数据表结构到Excel 一个表一个Sheet 带链接目录
    PowerDesigner导出数据表结构到Excel 所有表结构在同一个Sheet中
    Windows下如何用virtualenv创建虚拟环境
    解决ValueError: day is out of range for month的问题
    正则表达式
    移动端库和框架
  • 原文地址:https://www.cnblogs.com/jhz033/p/5746229.html
Copyright © 2011-2022 走看看