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
View Code
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
相关文章推荐
- Codeforces-352A
- 动态规划,而已! CodeForces 433B - Kuriyama Mirai's Stones
- CodeForces 86D Powerful array
- CodeForces-719B Anatoly and Cockroaches(思维题)
- Codeforces 510D Fox And Jumping【数论+Dp+压缩空间】好题~
- Codeforces 462C C. Appleman and Toastman【贪心】
- CF->CodeForces 256A
- Codeforces 17D Notepad 简单的数论
- CodeForces 638D Three-dimensional Turtle Super Computer
- Codeforces--486B---OR in Matrix思维题
- Codeforces 270A - Fancy Fence
- CodeForces - 859B Lazy Security Guard(思维)
- Codeforces-356C
- CodeForces 363C - Fixing Typos
- codeforces 86D. Powerful array(莫队算法)
- CodeForces 415D Mashmokh and ACM
- CodeForces 605 A.Sorting Railway Cars(贪心)
- Codeforces 322C Ciel and Robot【思维+模拟】细节很多= =
- CodeForces 275C 贪心
- CodeForces 296C Greg and Array (线段树)