AtCoder Grand Contest 013 C :Ants on a Circle

本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

 

 

本文作者:ljh2000
作者博客:http://www.cnblogs.com/ljh2000-jump/
转载请注明出处,侵权必究,保留最终解释权!

 

题目链接:AGC013C

正解:思维题

解题报告:

  考虑这类蚂蚁有关的问题,都可以看作是在相遇的时候穿透而过的,但是同时我们发现,因为碰撞之后就会回头,所以相对位置不会改变,那么我可以得到一个最终的位置集合(直接算就好了,然后排个序)。

   我们就拿$1$号蚂蚁作为基准点,发现如果有一个蚂蚁越过了$L-1$到$0$,那么$rank++$;反之,$rank--$。

  最后输出就好了。

 

//It is made by ljh2000
//有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long LL;
const int MAXN = 100011;
int n,L,T,X[MAXN];

inline int getint(){
    int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
    if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
}

inline void work(){
	n=getint(); L=getint(); T=getint();
	int pos=0,x,w;
	for(int i=0;i<n;i++) {
		x=getint();	w=getint(); 
		if(w==1) {
			X[i]=x+T; X[i]%=L;
			pos+=(x+T)/L;
		}
		else {
			X[i]=x-T; X[i]%=L;
			pos+=(x-T)/L;
			if(X[i]<0) {
				X[i]+=L;
				pos--;
			}
		}
	}
	sort(X,X+n);
	pos%=n; pos+=n; pos%=n;//!!!
	for(int i=pos;i<n;i++) printf("%d\n",X[i]);
	for(int i=0;i<pos;i++) printf("%d\n",X[i]);
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
#endif
    work();
    return 0;
}
//有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。

  

posted @ 2017-05-17 23:06  ljh_2000  阅读(507)  评论(0编辑  收藏  举报