Ants on a Circle

感觉这个思路好巧妙啊。

我们能发现不管怎么碰撞,初始态和最终态蚂蚁间的相对顺序都是一样的, 并且所占的格子也是一样的, 那么我们就只需要

找到其中一个蚂蚁的最终位置就能确定所有蚂蚁的位置了, 我们考虑找初始为止离0最近的那个蚂蚁的最终位置,我们能发现

蚂蚁从m-1->0  rk++, 蚂蚁从0->m-1 rk--, 在取模意义下rk就是那个蚂蚁的最终位置。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); LL n, m, t, cnt, X[N], ans[N];
char T[]; struct node {
LL s, d, id;
bool operator < (const node& rhs) const {
return s < rhs.s;
}
} a[N]; int main() {
scanf("%lld%lld%lld", &n, &m, &t);
for(int i = ; i < n; i++) {
scanf("%lld%s", &a[i].s, T);
a[i].s--; a[i].id = i;
if(T[] == 'L') a[i].d = -;
else a[i].d = ;
}
sort(a, a + n);
for(int i = ; i < n; i++) {
if(a[i].d == ) {
X[i] = (a[i].s + t) % m;
cnt = (cnt + (a[i].s + t) / m) % n;
} else {
X[i] = (a[i].s - t) % m;
cnt = (cnt + (a[i].s - t) / m) % n;
if(X[i] < ) X[i] += m, cnt = (cnt - ) % n;
}
}
sort(X, X + n);
cnt = (cnt % n + n) % n;
int now = ;
for(int i = cnt; i < n; i++) ans[a[now++].id] = X[i] + ;
for(int i = ; i < cnt; i++) ans[a[now++].id] = X[i] + ;
for(int i = ; i < n; i++) printf("%lld ", ans[i]);
return ;
} /*
*/

Codeforces 652F Ants on a Circle的更多相关文章

  1. [Educational Round 10][Codeforces 652F. Ants on a Circle]

    题目连接:652F - Ants on a Circle 题目大意:\(n\)个蚂蚁在一个大小为\(m\)的圆上,每个蚂蚁有他的初始位置及初始面向,每个单位时间蚂蚁会朝着当前面向移动一个单位长度,在遇 ...

  2. CF - 652F Ants on a Circle

    题目传送门 题解: 先观察蚂蚁相撞, 可以发现, 如果我们将相撞的2个蚂蚁互换位置的话,蚂蚁相当于没有碰撞体积,直接穿过去了.所以我们可以直接计算出最终哪些位置上会有蚂蚁. 接下来就需要知道蚂蚁们的最 ...

  3. atCoder Ants on a Circle(又是蚂蚁问题。。。)

    atCoder Ants on a Circle(又是蚂蚁问题...) 传送门 题意:一个圈,蚂蚁在上面以相同的速度和不同的方向走,问t秒后它们各自的位置. 解法:和经典的蚂蚁问题一致,把相撞的情况看 ...

  4. codeforces 622E. Ants in Leaves

    题目链接 给一棵有根树, 每个叶子节点上有一只蚂蚁. 在0时刻蚂蚁开始向上爬, 同一时刻, 除了根节点以外, 一个节点上面不能有2个蚂蚁. 问所有的蚂蚁都爬到根节点需要的最短时间. 因为除了根节点, ...

  5. AT2369 Ants on a Circle (思路)

    考虑到蚂蚁们的相对位置不会变化,而且,如果把“相遇后掉头”看作是“相遇后交换编号”的话,也可以得出来最后都有哪些位置有蚂蚁 然后,只要确定哪个位置是“1”就可以了 然后搞一个指针p代表原来第一个位置的 ...

  6. 【AGC013C】Ants on a Circle 弹性碰撞

    题目大意 一个长度为\(lm\)的环上有\(n\)只蚂蚁,告诉你每只蚂蚁的位置和朝向,每只蚂蚁会向前爬,速度为\(1m/s\),两只蚂蚁相遇后都会掉头,问你\(t\)秒后每只蚂蚁的位置. \(n\le ...

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

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

  8. [AT2369] [agc013_c] Ants on a Circle

    题目链接 AtCoder:https://agc013.contest.atcoder.jp/tasks/agc013_c 洛谷:https://www.luogu.org/problemnew/sh ...

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

    题目传送门:https://agc013.contest.atcoder.jp/tasks/agc013_c 题目翻译 给你一个周长为\(L\)的圆,有\(N\)只蚂蚁在圆上爬,速度为一单位距离每秒. ...

随机推荐

  1. CRM 2013发邮件的插件报错Cannot open Sql Encryption Symmetric Key because Symmetric Key password does not exist in Config DB

    解决方法: 1. 依次打开Settings->Data management –> Data Encryption 然后在上面红框里填上任意一个key即可.

  2. 【bzoj4066】 简单题

    http://www.lydsy.com/JudgeOnline/problem.php?id=4066 (题目链接) 题意 维护一个矩阵,两个操作,给某一个元素加上A,求其中一个子矩阵的元素之和.强 ...

  3. for in,Object.keys和Object.getOwnPropertyNames的区别

    var parent = Object.create(Object.prototype, { a: { value: 1, writable: true, enumerable: true, conf ...

  4. vue element-ui 实现点击查看审核记录

    <el-dialog title="审核信息" :visible.sync="seeVisible" width="30%" :bef ...

  5. Google-403-Forbidden

    Author:KillerLegend Date:2014.8.14 From:http://www.cnblogs.com/killerlegend/p/3913554.html www.googl ...

  6. bzoj千题计划291:bzoj3640: JC的小苹果

    http://www.lydsy.com/JudgeOnline/problem.php?id=3640 dp[i][j] 表示i滴血到达j的概率 dp[i][j] = Σ dp[i+val[i]][ ...

  7. Zephir入门教程一

    一.如何安装 zephir-安装和初体验:http://blog.csdn.net/u011142688/article/details/51619811 二.如何使用 需要切到工作目录下,也就是co ...

  8. 流媒体技术学习笔记之(十五)FFmpeg编码遇到的错误、警告、Debug记录

    When encoding H.264 using ffmpeg I get the following type of warnings en masse: Past duration 0.6063 ...

  9. python学习笔记6--操作Mysql

    一.mysql操作 import pymysql #连上mysql ip 端口号 密码 账号 数据库 #建立游标 #执行sql #获取结果 #关闭连接.关闭游标 conn=pymysql.connec ...

  10. MongoDB探索之路(二)——系统设计之CRUD

    1.构造实体类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...