本文版權歸ljh2000和博客園共有,歡迎轉載,但須保留此聲明,並給出原文連接,謝謝合做。ios
本文做者:ljh2000
做者博客:http://www.cnblogs.com/ljh2000-jump/
轉載請註明出處,侵權必究,保留最終解釋權!spa
題目連接:AGC013Ccode
正解:思惟題blog
解題報告:get
考慮這類螞蟻有關的問題,均可以看做是在相遇的時候穿透而過的,可是同時咱們發現,由於碰撞以後就會回頭,因此相對位置不會改變,那麼我能夠獲得一個最終的位置集合(直接算就行了,而後排個序)。博客
咱們就拿$1$號螞蟻做爲基準點,發現若是有一個螞蟻越過了$L-1$到$0$,那麼$rank++$;反之,$rank--$。string
最後輸出就行了。it
//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; } //有志者,事竟成,破釜沉舟,百二秦關終屬楚;苦心人,天不負,臥薪嚐膽,三千越甲可吞吳。