• Codeforces Round #280 (Div. 2) E. Vanya and Field 数学


    E. Vanya and Field

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/492/problem/E

    Description

    Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates(xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell . The following condition is satisfied for the vector: , where  is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.

    Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.

    Input

    The first line contains integers n, m, dx, dy(1 ≤ n ≤ 106, 1 ≤ m ≤ 105, 1 ≤ dx, dy ≤ n) — the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 ≤ xi, yi ≤ n - 1) — the coordinates of apples. One cell may contain multiple apple trees.

    Output

    Print two space-separated numbers — the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.

    Sample Input

    5 5 2 3
    0 0
    1 2
    1 3
    2 4
    3 1

    Sample Output

    1 3

    HINT

    题意

    有一个n*n的方格,有m棵苹果树

    一开始假设在(x,y),那么下一次可以在(x+dx,y+dy)位置,可以无限走

    然后问你起点定在什么位置,可以如果最多的苹果树

    题解:

    题目说了,gcd(n,dx)=0,那么很显然,这个集合里面有n个元素(这个可以用exgcd证明

    那么也很容易证明,每一行的每个元素都属于不同的集合

    然后我们就可以先暴力找到一个集合,然后这个苹果树和这个集合偏移多少,那么这个苹果树就属于第几个集合

    代码

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    #define maxn 1000006
    int X[maxn];
    int ans[maxn];
    int main()
    {
        int n,m,dx,dy;
        scanf("%d%d%d%d",&n,&m,&dx,&dy);
        int xx=0,yy=0;
        for(int i=0;i<n;i++)
        {
            X[xx]=yy;
            xx+=dx;
            yy+=dy;
            if(xx>=n)xx-=n;
            if(yy>=n)yy-=n;
        }
        int ans1=0,ans2=0,ans3=0;
        for(int i=0;i<m;i++)
        {
            int x,y;scanf("%d%d",&x,&y);
            int tmp = y-X[x];if(tmp<0)tmp+=n;
            ans[tmp]++;
            if(ans[tmp]>=ans3)
            {
                ans3=ans[tmp];
                ans1=0,ans2=tmp;
            }
        }
        printf("%d %d
    ",ans1,ans2);
    
    }
  • 相关阅读:
    [日常摸鱼]一些素数筛法(暴力筛/埃氏筛/欧拉筛)与复杂度证明
    [日常摸鱼]一些博弈题
    [日常摸鱼]博弈论入门/经典模型/SG函数
    [日常摸鱼]整点正多边形,HDU6055,Pick公式,证明
    [日常摸鱼]一些DP题(2)各种背包——01背包/二维背包/背包前K优解
    [学习笔记]程设作业的一些YY,高精度除法/FFT/Karastuba/牛顿迭代
    [比赛记录]2020-2021 Summer Petrozavodsk Camp, Day 6: Korean Contest
    [日常摸鱼]一些DP题(1)
    [日常摸鱼]poj3179-Corral the Cows——离散化+二维前缀和/KD-Tree
    《HDU-1028》
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4970538.html
Copyright © 2020-2023  润新知