[AT2369] [agc013_c] Ants on a Circle
生活随笔
收集整理的這篇文章主要介紹了
[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-1\sim 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('\n');}#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; }轉載于:https://www.cnblogs.com/hbyer/p/10717599.html
總結
以上是生活随笔為你收集整理的[AT2369] [agc013_c] Ants on a Circle的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: luogu P5292 [HNOI201
- 下一篇: python 面向对象学习