题目传送门:https://agc013.contest.atcoder.jp/tasks/agc013_c

题目翻译

给你一个周长为\(L\)的圆,有\(N\)只蚂蚁在圆上爬,速度为一单位距离每秒。有的蚂蚁是逆时针的,有的蚂蚁是顺时针的,蚂蚁互相碰面会转向,问你\(T\)秒后每只蚂蚁分别在什么地方。\(L,T\leqslant 10^9,N\leqslant 10^5\)

题解

碰面转向相当于不转向交换编号,所以我们可以求出最后每只蚂蚁会在哪个地方。然后只需要关注第一只蚂蚁最后的\(pos\)的排名就行了。容易发现,当有一只蚂蚁从\(N-1\)爬到\(0\)时,\(1\)号蚂蚁的\(rk++\),反着就\(rk--\)。

时间复杂度:\(O(N)\)

空间复杂度:\(O(NlogN)\)

代码如下:

#include <cstdio>
#include <algorithm>
using namespace std; const int maxn=1e5+5; int n,rk,L,T;
int pos[maxn]; int read() {
int x=0,f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
} int main() {
n=read(),L=read(),T=read();
for(int i=1;i<=n;i++) {
int x=read(),w=read();
if(w==2)pos[i]=x-T;
else pos[i]=x+T;
rk+=pos[i]/L;
if(pos[i]%L<0)rk--;
pos[i]=(pos[i]%L+L)%L;
}
sort(pos+1,pos+n+1);
rk=(rk%n+n)%n;
for(int i=rk+1;i<=n;i++)
printf("%d\n",pos[i]);
for(int i=1;i<=rk;i++)
printf("%d\n",pos[i]);
return 0;
}

AtCoder Grand Contest 013 C:Ants on a Circle的更多相关文章

  1. AtCoder Grand Contest 013 C :Ants on a Circle

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  2. AtCoder Grand Contest 013

    这场打得蛮菜的,很晚才出BC,还一堆罚时…… A - Sorted Arrays 题目大意:将给定数列划分成单调不增或单调不减的区间,求最少区间数. 贪心即可. #include<cstdio& ...

  3. AtCoder Grand Contest 009 D:Uninity

    题目传送门:https://agc009.contest.atcoder.jp/tasks/agc009_d 题目翻译 定义只有一个点的树权值为\(0\),若干棵(可以是\(0\)棵)权值为\(k\) ...

  4. AtCoder Grand Contest 009 E:Eternal Average

    题目传送门:https://agc009.contest.atcoder.jp/tasks/agc009_e 题目翻译 纸上写了\(N\)个\(1\)和\(M\)个\(0\),你每次可以选择\(k\) ...

  5. AtCoder Grand Contest 004 C:AND Grid

    题目传送门:https://agc004.contest.atcoder.jp/tasks/agc004_c 题目翻译 给你一张网格图,指定的格子是紫色的,要求你构造出两张网格图,其中一张你可以构造一 ...

  6. AtCoder Grand Contest 014 D:Black and White Tree

    题目传送门:https://agc014.contest.atcoder.jp/tasks/agc014_d 题目翻译 给你一棵树,每次任选一个点染色,先手染白色,后手染黑色.如果最后存在一个白色的点 ...

  7. AtCoder Grand Contest 028 A:Two Abbreviations

    题目传送门:https://agc028.contest.atcoder.jp/tasks/agc028_a 题目翻译 给你两个串\(s\)与\(t\),长度分别为\(n,m\).问你存不存在一个串长 ...

  8. AtCoder Grand Contest 002 F:Leftmost Ball

    题目传送门:https://agc002.contest.atcoder.jp/tasks/agc002_f 题目翻译 你有\(n*k\)个球,这些球一共有\(n\)种颜色,每种颜色有\(k\)个,然 ...

  9. AtCoder Grand Contest 010 C:Cleaning

    题目传送门:https://agc010.contest.atcoder.jp/tasks/agc010_c 题目翻译 给你一棵树,每个点有个权值,每次操作可以选择两个度数为\(1\)的结点,然后让这 ...

随机推荐

  1. 创业神人&当时钢铁侠:Elon Musk

    Steve Jobs的光环已经随着他的离去而淡褪,短期内,世上恐怕再难有人像他这样惊世骇俗般的改变了世界.但是如果你了解到一个人,一个来自南非年仅40岁的企业家,在短短的20年里,在全世界最酷的三个领 ...

  2. beego介绍

    beego 简介 beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API.Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计灵感来源于 tornado ...

  3. asp.net 后台多线程异步处理时的 进度条实现一(Ajax+Ashx实现以及封装成控件的实现)

    (更新:有的同学说源代码不想看,说明也不想看,只想要一个demo,这边提供一下:http://url.cn/LPT50k (密码:TPHU)) 工作好长时间了,这期间许多功能也写成了不少的控件来使用, ...

  4. &lt;LeetCode OJ&gt; 121. /122. Best Time to Buy and Sell Stock(I / II)

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

  5. iOS 逆向 - Class-dump 安装和使用方法

    1.下载安装包 http://stevenygard.com/projects/class-dump/,这里我下载的是 class-dump-3.5.dmp.然后把下载下来的 dmg 打开,复制文件里 ...

  6. python 基础 8.0 regex 正则表达式--常用的正则表达式

    一. python 中常用的正则表达式         二. 正则表达式的网站,可以进行在线正则匹配 https://regex101.com/   1. 使用方法及正则介绍 1> ‘.’  匹 ...

  7. iOS UIWebview添加请求头的两种方式

    1.在UIWebviewDelegate的方法中拦截request,设置request的请求头,废话不多说看代码: - (BOOL)webView:(UIWebView *)webView shoul ...

  8. ast.literal_eval(jsonStr) json格式字符串转dict 2种方式

    json.loads(jsonStr, encoding='utf-8')import ast ast.literal_eval(jsonStr)

  9. 【题解】POJ1934 Trip (DP+记录方案)

    [题解]POJ1934 Trip (DP+记录方案) 题意: 传送门 刚开始我是这么设状态的(谁叫我DP没学好) \(dp(i,j)\)表示钦定选择\(i\)和\(j\)的LCS,然而你会发现这样钦定 ...

  10. PHP通过session id 实现session共享和登录验证的代码

    先说说,这个机制的用途吧,到现在为止战地知道这个机制有两个方面的用途: 首先,多服务器共享session问题,这个大家应该都能够理解的,当一个网站的用户量过大,就会使用服务器集群,例如专门有一个登录用 ...