[agc013c]Ants on a Circle
来源:互联网 发布:做注册单开淘宝店铺 编辑:程序博客网 时间:2024/05/28 03:03
题目大意
数轴蚂蚁问题升级成环。
做法
如果是数轴是经典问题:
两只蚂蚁相遇后掉头可以看做代替对方继续前行。
相对位置永远不变。
初始坐标刚好递增。
但是现在是环,注意到每当有蚂蚁跨过L-1或0就会使排名进行右/左移。
因此也很方便了。
#include<cstdio>#include<algorithm>#define fo(i,a,b) for(i=a;i<=b;i++)using namespace std;typedef long long ll;const int maxn=100000+10;int x[maxn],xx[maxn],w[maxn];int i,j,k,l,r,s,t,n,m;ll c; int main(){ scanf("%d%d%d",&n,&l,&t); fo(i,1,n) scanf("%d%d",&x[i],&w[i]); fo(i,1,n){ if (w[i]==2) w[i]=-1; r=x[i]+w[i]*t; if (r>0) (c+=r/l)%=n; else if (r<0) (c+=(r+1)/l-1)%=n; xx[i]=(r%l+l)%l; } sort(xx+1,xx+n+1); c=(c+n)%n; fo(i,c+1,n) printf("%d\n",xx[i]); fo(i,1,c) printf("%d\n",xx[i]);}
阅读全文
0 0
- [agc013c]Ants on a Circle
- 【AGC013C】Ants on a Circle 弹性碰撞
- CodeForces 652F. Ants on a Circle
- 【思路题】AtCoder agc013_c Ants on a Circle
- 【思维】AtCoder Grand Contest(013)C[Ants on a Circle]题解
- [HDU4669]Mutiples on a circle
- hdoj 4669 Mutiples on a circle
- hdu 4669 Mutiples on a circle
- HDU - 4669 Mutiples on a circle
- HDOJ 4669 Mutiples on a circle
- hdu 4669 Mutiples on a circle 多校第七场
- HDU 4669 Mutiples on a circle 解题报告
- hdu 4669——Mutiples on a circle
- HDU 4669 Mutiples on a circle (DP , 统计)
- hdu 4669 Mutiples on a circle(按位DP)
- hdu 4669 Mutiples on a circle(高效)
- AT2 Homeomorphism and the group structure on a circle
- Gym 100273A Ants
- shell 括号总结
- Just a Hook
- C++大数操作
- JavaScript+CSS+DIV实现表格变色
- minimum-window-substring
- [agc013c]Ants on a Circle
- 后台开发-58
- 深信服笔试题
- 简单数据库注入式攻击
- 数据缓存(数据库)
- Java类加载机制详解
- 【笔记】抽空重新查看了一遍linux c函数
- HTML调用CSS管理、美化div
- js十大排序算法