Codeforces_492_E

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

 

题目规定了gcd=1,可以在纸上模拟一下,发现每一个起点,都会经历过n个点,n个点都是不同行不同列。可以把这n个点归为一组,一共n组。

我们按照纵坐标来编号,然后求出每一组的数量就可以得出答案了。

 

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define MAX 1000005
using namespace std;

int n,m,dx,dy,a[MAX],ans[MAX];

int main()
{
    scanf("%d%d%d%d",&n,&m,&dx,&dy);
    int x = 0,y = 0;
    for(int i = 1;i <= n;i++)
    {
        a[x] = y;
        x = (x+dx)%n;
        y = (y+dy)%n;
    }
    int maxa = 0,maxy = 0;
    for(int i = 1;i <= m;i++)
    {
        scanf("%d%d",&x,&y);
        int temp = y-a[x];
        if(temp < 0)    temp += n;
        ans[temp]++;
        if(ans[temp] > maxa)
        {
            maxa = ans[temp];
            maxy = temp;
        }
    }
    printf("0 %d\n",maxy);
    return 0;
}

 

posted @ 2016-10-10 17:35  zzzzzzzzhu  阅读(221)  评论(0编辑  收藏  举报