首页 技术 正文
技术 2022年11月18日
0 收藏 447 点赞 4,667 浏览 1121 个字

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 longusing 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 ;
}/*
*/
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295