Codeforces 652F 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的更多相关文章
- [Educational Round 10][Codeforces 652F. Ants on a Circle]
题目连接:652F - Ants on a Circle 题目大意:\(n\)个蚂蚁在一个大小为\(m\)的圆上,每个蚂蚁有他的初始位置及初始面向,每个单位时间蚂蚁会朝着当前面向移动一个单位长度,在遇 ...
- CF - 652F Ants on a Circle
题目传送门 题解: 先观察蚂蚁相撞, 可以发现, 如果我们将相撞的2个蚂蚁互换位置的话,蚂蚁相当于没有碰撞体积,直接穿过去了.所以我们可以直接计算出最终哪些位置上会有蚂蚁. 接下来就需要知道蚂蚁们的最 ...
- atCoder Ants on a Circle(又是蚂蚁问题。。。)
atCoder Ants on a Circle(又是蚂蚁问题...) 传送门 题意:一个圈,蚂蚁在上面以相同的速度和不同的方向走,问t秒后它们各自的位置. 解法:和经典的蚂蚁问题一致,把相撞的情况看 ...
- codeforces 622E. Ants in Leaves
题目链接 给一棵有根树, 每个叶子节点上有一只蚂蚁. 在0时刻蚂蚁开始向上爬, 同一时刻, 除了根节点以外, 一个节点上面不能有2个蚂蚁. 问所有的蚂蚁都爬到根节点需要的最短时间. 因为除了根节点, ...
- AT2369 Ants on a Circle (思路)
考虑到蚂蚁们的相对位置不会变化,而且,如果把“相遇后掉头”看作是“相遇后交换编号”的话,也可以得出来最后都有哪些位置有蚂蚁 然后,只要确定哪个位置是“1”就可以了 然后搞一个指针p代表原来第一个位置的 ...
- 【AGC013C】Ants on a Circle 弹性碰撞
题目大意 一个长度为\(lm\)的环上有\(n\)只蚂蚁,告诉你每只蚂蚁的位置和朝向,每只蚂蚁会向前爬,速度为\(1m/s\),两只蚂蚁相遇后都会掉头,问你\(t\)秒后每只蚂蚁的位置. \(n\le ...
- AtCoder Grand Contest 013 C :Ants on a Circle
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- [AT2369] [agc013_c] Ants on a Circle
题目链接 AtCoder:https://agc013.contest.atcoder.jp/tasks/agc013_c 洛谷:https://www.luogu.org/problemnew/sh ...
- AtCoder Grand Contest 013 C:Ants on a Circle
题目传送门:https://agc013.contest.atcoder.jp/tasks/agc013_c 题目翻译 给你一个周长为\(L\)的圆,有\(N\)只蚂蚁在圆上爬,速度为一单位距离每秒. ...
随机推荐
- 【拓扑 字符串还原 + 线段树维护】奇洛金卡达(father)
奇洛金卡达(father) Description 阿良良木历将要迎来人生(不,是吸血鬼生涯)的第三次战斗——与身为人类的奇洛金卡达在直江津高中的操场solo,以取回Heartunderblade 的 ...
- loj6253/luogu4062-Yazid的新生舞会
先考虑部分分(只有01/只有0~7)做法:枚举每个数,把和他相同的设为1,不同的设为-1,然后这个数作为众数贡献的个数就是区间和>0的个数 推着做,树状数组记前缀和<=x的区间的数量就可以 ...
- 【bzoj3932】 CQOI2015—任务查询系统
http://www.lydsy.com/JudgeOnline/problem.php?id=3932 (题目链接) 题意 给出$m$个区间,每个区间有一个权值,$n$组询问,每次询问在位置$x$权 ...
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- bug5 Debug:This kind of launch is configured to openthe debug perspective when it解决办法
启动tomcat时,myeclipse报错: This kind of launch is configured to openthe debug perspective when itsuspend ...
- list对象指针与指针类型list
#include <string> #include <cctype> #include <algorithm> #include <iostream> ...
- react入门-组件方法、数据和生命周期
react组件也像vue一样,有data和methods,但是写法就很不同了: <!DOCTYPE html> <html lang="en"> <h ...
- 流媒体技术学习笔记之(四)解决问题video.js 播放m3u8格式的文件,根据官方的文档添加videojs-contrib-hls也不行的原因解决了
源码地址:https://github.com/Tinywan/PHP_Experience 总结: 说明: 测试环境:本测试全部来自阿里云直播和OSS存储点播以及本地服务器直播和点播 播放器:Vid ...
- [整理].net中的延迟初始化器
LazyInitializer类 private void EnsureInitialized() { LazyInitializer.EnsureInitialized(ref _initializ ...
- 如何使用 grunt
1>. 首先要有nodejs环境, 至少0.8.0版本: 2>. 转到 项目文件夹下: >npm install –g grunt-cli >npm init #生成一个基本的 ...