日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/18 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 atCoder Ants on a Circle(又是蚂蚁问题。。。) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

atCoder Ants on a Circle(又是螞蟻問題。。。)

傳送門

題意:一個圈,螞蟻在上面以相同的速度和不同的方向走,問t秒后它們各自的位置。

解法:和經典的螞蟻問題一致,把相撞的情況看做是穿過,我們不需要關心穿過的螞蟻去哪兒了,它們的位置是相對不變的。然而。。。這里的路線是一個圈,勢必會出現原本排在第一的螞蟻跑到了尾部,又或是排在尾部的螞蟻跑到了第一,也就是說位置是會變得。但是我們只需要將首部的螞蟻移動<0看做是這只螞蟻被頂了上去,某只螞蟻移動>=l看做試將一系列螞蟻頂了回去。就能鎖定原本首部螞蟻的位置,答案也就出來了

import java.io.*; import java.util.*;class MyInputStream extends InputStream {public BufferedInputStream bis = new BufferedInputStream(System.in);public int read() throws IOException {int i;while ((i = bis.read()) < 48)if (i == -1)return -1;int temp = 0;while (i > 47) {temp = temp * 10 + i - 48;i = bis.read();}return temp;} }public class Main {static final int N = 100005;static final int inf = 0x3f3f3f3f;static final double eps = 1e-6;static int a[] = new int[N];public static void main(String[] args) throws IOException {MyInputStream cin = new MyInputStream();int n = cin.read(), l = cin.read(), t = cin.read();int tmp, cnt = 0, d;for (int i = 0; i < n; i++) {a[i] = cin.read();d = cin.read();if (d == 1) {tmp = a[i] + t;a[i] = tmp % l;cnt += tmp / l;} else {tmp = a[i] - t;a[i] = tmp % l;cnt += tmp / l;if (a[i] < 0) {a[i] += l;cnt--;}}}Arrays.sort(a, 0, n);cnt %= n;if (cnt < 0)cnt += n;cnt %= n;for (int i = cnt; i < cnt + n; i++) {int j = i % n;System.out.println(a[j]);}cin.close();} }

轉載于:https://www.cnblogs.com/zsyacm666666/p/6729618.html

總結

以上是生活随笔為你收集整理的atCoder Ants on a Circle(又是蚂蚁问题。。。)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。