您的位置:首页 > 其它

Codeforces 492E Vanya and Field

2014-12-04 19:30 267 查看
E. Vanya and Field

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef pair<LL,int> pii;
const int N = 2000011 ;
const int M = 1000000 ;
const int inf = 1e9+7;
#define X first
#define Y second

int n , m , dx , dy , x
, y
,  cnt
, id ;
vector<pii>e;
void test() {
for( int i = 0 ; i < n ; ++i ) cout << x[i] << ' ' ; cout <<endl ;
for( int i = 0 ; i < n ; ++i ) cout << y[i] << ' ' ; cout <<endl ;
}
void Run() {

memset( cnt , 0 , sizeof cnt ) ;
x[0] = 0 ; id = 1 ; for( int i = dx ; i != 0 ; i = (i+dx)%n ) x[i] = id++;
y[0] = 0 ; id = 1 ; for( int i = dy ; i != 0 ; i = (i+dy)%n ) y[i] = id++;
//    test();
e.resize(m);
for( int i = 0 ; i < m ; ++i ) {
cin >> e[i].X >> e[i].Y ;
int disx = ( x[e[i].X] + n ) % n ;
int disy = ( y[e[i].Y] + n ) % n ;
cnt[ (disx + n - disy)%n  ] ++ ;
}
LL ans = 0 ;
for( int i = 0; i < n ; ++i ) {
if( cnt[ans] < cnt[i] ) ans = i;
}
cout << ( ans*dx ) % n << " 0"<< endl ;
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
while( cin >> n >> m >> dx >> dy ) Run();
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: