• L


    ---恢复内容开始---

    You are given a tube which is reflective inside represented as two non-coinciding, but parallel to OxOx lines. Each line has some special integer points — positions of sensors on sides of the tube.

    You are going to emit a laser ray in the tube. To do so, you have to choose two integer points AA and BB on the first and the second line respectively (coordinates can be negative): the point AA is responsible for the position of the laser, and the point BB  — for the direction of the laser ray. The laser ray is a ray starting at AA and directed at BB which will reflect from the sides of the tube (it doesn't matter if there are any sensors at a reflection point or not). A sensor will only register the ray if the ray hits exactly at the position of the sensor.

    Examples of laser rays. Note that image contains two examples. The 3 sensors (denoted by black bold points on the tube sides) will register the blue ray but only 2 will register the red.

    Calculate the maximum number of sensors which can register your ray if you choose points AA and BB on the first and the second lines respectively.

    Input

    The first line contains two integers n and y1 (1n1051≤n≤105 , 0y11090≤y1≤109 ) — number of sensors on the first line and its yy coordinate.

    The second line contains nn integers a1,a2,,an (0ai1090≤ai≤109 ) — xx coordinates of the sensors on the first line in the ascending order.

    The third line contains two integers m and y2 (1m1051≤m≤105 , y1<y2109y1<y2≤109 ) — number of sensors on the second line and its yy coordinate.

    The fourth line contains mm integers b1,b2,,bm(0bi1090≤bi≤109 ) — xx coordinates of the sensors on the second line in the ascending order.

    Output

    Print the only integer — the maximum number of sensors which can register the ray.

    Example

    Input
    3 1
    1 5 6
    1 3
    3
    Output
    3

    Note

    One of the solutions illustrated on the image by pair A2 and B2 .

    题意:

    给出n个点在y1的水平线上,给出m个点在y2的水平面上,有一道光线可以在这两个水平线中折射,并且从任意位置开始,求对多可以经过多少了点

    思路:我们可以枚举光的折射长度,也就是从下界到上界再回到下界的长度,可以发现这样两界面的高度y可以忽略

    另外,我们不可能从1枚举1e9。

    ①显然,任何奇数步长可以有步长1取代

    关键就是偶数步长,任何偶数长度可以有 2n   *  m (n>=1,m为奇数), 因为任何偶数都可以被2整除,那么当商为偶数时,我们可以将商提出2,将2乘上2,这样仍是2的幂次,然后直到商就变成了奇数

    ②偶数可以用2n代替

    综上,枚举长度2 (0 <= n <=  log(1e9)),

    然后我们可以知道,对于一个定长度的步长,然后界面上的点取模2倍步长,余数相同的就是在一条折射线上的,对于另一界面,不能直接取模2倍步长,应该加上步长再取模2倍步长

      

    #include<bits/stdc++.h>
    using namespace std;
    int n,m;
    const int maxn = 1e5+5;
    int a[maxn];
    int b[maxn];
    int tmp[maxn<<1];
    
    int main()
    {
        int val;
        scanf("%d%d",&n,&val);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        scanf("%d%d",&m,&val);
        for(int i=1;i<=m;i++)scanf("%d",&b[i]);
        int ans = 2;
        int tot = n+m;
        tmp[tot+1] = 2e9+1;
        for(int step = 1;step <= int(1e9);step<<=1)
        {
            int mod = step<<1;
            for(int i=1;i<=n;i++)tmp[i] = a[i]%mod;
            for(int i=1;i<=m;i++)tmp[i+n] = (b[i]+step)%mod;
            sort(tmp+1,tmp+1+tot);
            for(int i=1,last=1;i<=tot;i++)
            {
                if(tmp[i+1] != tmp[i])
                {
                    ans = max(ans,i+1-last);
                    last = i+1;
                }
            }
        }
        printf("%d
    ",ans);
    }
    View Code
  • 相关阅读:
    Android新手之旅(5) 网络资源
    Android新手之旅(10) 嵌套布局
    vertest
    Android新手之旅(4) 通过HTTP访问web
    Android新手之旅(6) 与.Net不同之处
    Android新手之旅(7) RadioButton的自定义
    Android新手之旅(9) 自定义的折线图
    Android新手之旅(8) ListView的使用
    ECLIPSE 安装及与CDT 的使用 多线程编程
    Eclipse的代码提示背景是黑色
  • 原文地址:https://www.cnblogs.com/iwannabe/p/10580849.html
Copyright © 2020-2023  润新知