zoukankan      html  css  js  c++  java
  • [AT2369] [agc013_c] Ants on a Circle

    题目链接

    AtCoder:https://agc013.contest.atcoder.jp/tasks/agc013_c

    洛谷:https://www.luogu.org/problemnew/show/AT2369

    Solution

    首先可以注意到他们的相对位置是不变的。

    然后两只蚂蚁相遇可以看作是他们穿过了彼此然后交换编号。

    那么我们就可以得到最后的位置了,只需要确定编号就好了。

    注意到如果有一只蚂蚁穿过了(l-1sim 0)之间,所有编号都会左移(右移)一格。

    那么我们只需要处理出他们编号是怎么移的就好了。

    #include<bits/stdc++.h>
    using namespace std;
    
    #define int long long 
    
    void read(int &x) {
        x=0;int f=1;char ch=getchar();
        for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
        for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
    }
    
    void print(int x) {
        if(x<0) putchar('-'),x=-x;
        if(!x) return ;print(x/10),putchar(x%10+48);
    }
    void write(int x) {if(!x) putchar('0');else print(x);putchar('
    ');}
    
    #define lf double
    #define ll long long 
    
    const int maxn = 1e5+10;
    const int inf = 1e9;
    const lf eps = 1e-8;
    
    int p[maxn],n,c,l,t;
    
    signed main() {
        read(n),read(l),read(t);
        for(int i=1,x;i<=n;i++) {
            read(p[i]),read(x);x=x==2?-1:x;p[i]+=x*t;
            if(p[i]>0) c+=p[i]/l;
            else if(p[i]<0) c+=(p[i]+1)/l-1;p[i]=(p[i]%l+l)%l;
        }sort(p+1,p+n+1);
        c=(c%n+n)%n;
        for(int i=c+1;i<=n;i++) write(p[i]);
        for(int i=1;i<=c;i++) write(p[i]);
        return 0;
    }
    
  • 相关阅读:
    linux常用命令笔记
    head first html与css
    多线程编程核心技术日记
    nio
    排序算法
    随笔
    数据库读写分离
    购物网站设计
    http
    servlet初始化
  • 原文地址:https://www.cnblogs.com/hbyer/p/10717599.html
Copyright © 2011-2022 走看看