【思维】AtCoder Grand Contest(013)C[Ants on a Circle]题解
来源:互联网 发布:3d studio max mac版 编辑:程序博客网 时间:2024/05/17 07:41
题目概述
有
解题报告
栽了不知道多少次的题目……首先老套路,蚂蚁相撞看作穿过,最后相对位置不变。
但是环是什么鬼?想一下发现其实就是让我们确定某一只蚂蚁,从而确定所有的蚂蚁。
方便起见,我们用第一只蚂蚁来分析。刚开始,第一只蚂蚁位置最靠前,如果没有任何一只蚂蚁走过了临界点
示例程序
#include<cstdio>#include<cctype>#include<algorithm>using namespace std;const int maxn=100000;int n,L,T,a[maxn+5],ans[maxn+5];#define Eoln(x) ((x)==10||(x)==13||(x)==EOF)inline char readc(){ static char buf[100000],*l=buf,*r=buf; if (l==r) r=(l=buf)+fread(buf,1,100000,stdin); if (l==r) return EOF;return *l++;}inline int readi(int &x){ int tot=0,f=1;char ch=readc(),lst='+'; while (!isdigit(ch)) {if (ch==EOF) return EOF;lst=ch;ch=readc();} if (lst=='-') f=-f; while (isdigit(ch)) tot=(tot<<3)+(tot<<1)+ch-48,ch=readc(); return x=tot*f,Eoln(ch); }int main(){ freopen("ants.in","r",stdin); freopen("ants.out","w",stdout); readi(n);readi(L);readi(T);int fst=0; for (int i=0,x,f;i<n;i++) { readi(x);readi(f); if (f==1) ans[i]=x+T,fst+=ans[i]/L,ans[i]%=L; else {ans[i]=x-T;fst+=ans[i]/L;ans[i]%=L;if (ans[i]<0) fst--,ans[i]+=L;} } sort(ans,ans+n);fst=(fst%n+n)%n; for (int i=fst;i<n;i++) printf("%d\n",ans[i]); for (int i=0;i<fst;i++) printf("%d\n",ans[i]); return 0;}
阅读全文
0 0
- 【思维】AtCoder Grand Contest(013)C[Ants on a Circle]题解
- 题解Atcoder Grand Contest C
- AtCoder Grand Contest 013 题解
- Atcoder Grand Contest 013C
- 【思路题】AtCoder agc013_c Ants on a Circle
- AtCoder Grand Contest 012 题解
- 【题解】AtCoder Grand Contest 016
- Atcoder Grand Contest 19 题解
- AtCoder Grand Contest 014C: Closed Rooms 题解
- 【贪心+堆】AtCoder Grand Contest(018)C[Coins]题解
- AtCoder Grand Contest 012 A
- AtCoder Grand Contest 017-A
- AtCoder Grand Contest 018 A
- atcoder grand Contest 018 A
- AtCoder Grand Contest 018 A
- AtCoder Grand Contest 017 C
- 【AtCoder】 Grand Contest 018 C
- AtCoder Grand Contest 019 C
- python基础班学习-day1
- DNA Sequence LightOJ
- 分布式事物管理
- Uber终于消停了,新CEO说要带飞
- java1.8 常用集合源码学习:TreeSet
- 【思维】AtCoder Grand Contest(013)C[Ants on a Circle]题解
- 关于Shell的实用技巧分享
- 动态规划之小偷打劫房间
- 15nod1572-模拟&前缀和&枚举-宝岛地图
- 近期任务规划
- delete、truncate和drop清空表数据的区别?
- java函数的重载
- java1.8 过时集合源码学习:Vector
- 补提交卡 hihoCoder1051