zoukankan      html  css  js  c++  java
  • 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
    ",X[i]);
    	for(int i=0;i<pos;i++) printf("%d
    ",X[i]);
    }
    
    int main()
    {
    #ifndef ONLINE_JUDGE
    	freopen("C.in","r",stdin);
    	freopen("C.out","w",stdout);
    #endif
        work();
        return 0;
    }
    //有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。
    

      

  • 相关阅读:
    iframe框架
    HTML 中 id与name 区别
    使用display:inline-block产生间隙
    html5新增语义化标签
    子选择器与后代选择器的区别
    各种居中问题
    腾讯 地图 机器学习岗 春招实习123面(猝)
    腾讯 微信春招nlp实习生一面二面(猝)
    264. Ugly Number II(丑数 剑指offer 34)
    263. Ugly Number(判断是否是丑数 剑指offer34)
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/6870040.html
Copyright © 2011-2022 走看看