Atcoder Grand Contest 013C - Ants on a Circle
2017-04-16 19:25
447 查看
Problem Statement
There is a circle with a circumference of L.Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants.
These ants are numbered 1 through N in
order of increasing coordinate, and ant i is at coordinate Xi.
The N ants have just started
walking. For each ant i, you are given the initial direction Wi.
Ant i is initially walking clockwise if Wi is 1;
counterclockwise if Wi is 2.
Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each
of these two ants will then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds.
Constraints
All input values are integers.1≤N≤105
1≤L≤109
1≤T≤109
0≤X1<X2<…<XN≤L−1
1≤Wi≤2
Input
The input is given from Standard Input in the following format:N L T X1 W1 X2 W2 : XN WN
Output
Print N lines. The i-thline should contain the coordinate of ant i after T seconds.
Here, each coordinate must be between 0 and L−1,
inclusive.
Sample Input 1
Copy3 8 3 0 1 3 2 6 1
Sample Output 1
Copy1 3 0
1.5 seconds after the ants start
walking, ant 1 and 2 bump
into each other at coordinate 1.5. 1 second
after that, ant 1 and 3 bump
into each other at coordinate 0.5. 0.5 seconds
after that, that is, 3 seconds after the ants start walking, ants 1, 2 and 3 are
at coordinates 1, 3 and 0,
respectively.
Sample Input 2
Copy4 20 9 7 2 9 1 12 1 18 1
Sample Output 2
Copy7 18 18 1
题意:在一个环上有N只蚂蚁,它们顺时针或者逆时针走,两只蚂蚁相遇就掉头,问最后每只蚂蚁的相对位置
题解:显然蚂蚁的相对位置不变,然后相遇掉头可以理解为改变编号
也就是说我们最后得到了一个排好序的x数组表示答案,我们只需要第一只蚂蚁的rank即可求出答案
考虑什么时候rank会变化
如果有一只蚂蚁从L-1走到0,那么1号蚂蚁的rank++
如果有一只蚂蚁从0走到L-1,那么1号蚂蚁的rank--
#include <bits/stdc++.h> #define xx first #define yy second #define mp make_pair #define pb push_back #define fill( x, y ) memset( x, y, sizeof x ) #define copy( x, y ) memcpy( x, y, sizeof x ) using namespace std; typedef long long LL; typedef pair < int, int > pa; const int MAXN = 100010; int n, x[MAXN], a[MAXN], w[MAXN], L, T; LL cur; int main() { #ifdef wxh010910 freopen( "data.in", "r", stdin ); #endif scanf( "%d%d%d", &n, &L, &T ); for( int i = 0 ; i < n ; i++ ) { scanf( "%d%d", &a[ i ], &w[ i ] ); if( w[ i ] == 1 ) { x[ i ] = ( a[ i ] + T ) % L; cur += ( a[ i ] + T ) / L; } else { x[ i ] = ( a[ i ] - T ) % L; cur += ( a[ i ] - T ) / L; if( x[ i ] < 0 ) x[ i ] += L, cur--; } } cur = ( cur % n + n ) % n; sort( x, x + n ); for( int i = cur ; i < n ; i++ ) printf( "%d\n", x[ i ] ); for( int i = 0 ; i < cur ; i++ ) printf( "%d\n", x[ i ] ); }
相关文章推荐
- AtCoder Grand Contest 013 C :Ants on a Circle
- 【思维】AtCoder Grand Contest(013)C[Ants on a Circle]题解
- AtCoder Grand Contest 013 C - Ants on a Circle 乱搞
- AtCoder Grand Contest 017 D - Game on Tree
- Atcoder Grand Contest 016 F Games on DAG
- AtCoder Grand Contest 003 E - Sequential operations on Sequence 乱搞
- atCoder Ants on a Circle(又是蚂蚁问题。。。)
- Atcoder Grand Contest 016F - Games on DAG
- 单挑养成计划【2】 AtCoder Grand Contest 005
- AtCoder Grand Contest 013 题解
- AtCoder Grand Contest 020 B - Ice Rink Game(贪心+计算机乘法)
- AtCoder Grand Contest 013 D - Piling Up 动态规划
- AtCoder Grand Contest 010D
- AtCoder Grand Contest 015
- Atcoder Grand Contest 017 F Zigzag
- [AtCoder Grand Contest 016] D: Xor Replace (agc016d)
- AtCoder Grand Contest 072 F - Dam
- 【Atcoder Grand Contest 010】D - Decrementing——博弈论
- AtCoder Grand Contest 018 A - Getting Difference
- AtCoder Grand Contest 018B: Sports Festival 题解