UVa 10881Piotr's Ants思維 __acm

來源:互聯網
上載者:User

題目連結

對於每個螞蟻來說,他相對於其他螞蟻的位置是固定的,趕超前面或者被後面的趕超都是要回頭的,所以,假設木棒無限長,位於第一位的永遠在第一位,第二位的永遠在第二位。同時每兩個碰頭的螞蟻其實就是類似於交換了身份繼續前進。所以,先不管他們的碰頭,就讓每個沿著路線繼續走下去。由前面的可以知道,每個螞蟻的最終狀態的位置排列的順序就是一開始螞蟻的編號。

#include <map>#include <set>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <iostream>#include <stack>#include <cmath>#include <string>#include <vector>#include <cstdlib>//#include <bits/stdc++.h>//#define LOACL#define space " "#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef unsigned long long UL;//typedef __int64 Int;typedef pair<int, int> PAI;const int INF = 0x3f3f3f3f;const double ESP = 1e-5;const double PI = acos(-1.0);const int MOD = 1e9 + 7;const int MAXN = 10000 + 10;struct ant {    int dic;    int s, e;    int id;} data[MAXN];int f[MAXN];char str[][10] = {"L", "Turning", "R", "Fell off"};bool cmp(ant x, ant y) {return x.e < y.e;}bool cmp1(ant x, ant y) {return x.s < y.s;}int main() {    int T;    char s[10];    scanf("%d", &T);    int Kcase = 0;    while (T--) {        int L, t, N;        scanf("%d%d%d", &L, &t, &N);        for (int i = 0; i < N; i++) {            scanf("%d%s", &data[i].s, s);            data[i].dic = (s[0] == 'R'? 1: -1);            data[i].id = i;            data[i].e = data[i].s + data[i].dic*t;        }        sort(data, data + N, cmp1);        for (int i = 0; i < N; i++) f[data[i].id] = i;        sort(data, data + N, cmp);        for (int i = 0; i < N; i++) {            if (data[i].e < 0 || data[i].e > L) data[i].dic = 2;            else if (i != 0 && data[i].e == data[i - 1].e) data[i].dic = data[i - 1].dic = 0;        }        printf("Case #%d:\n", ++Kcase);        for (int i = 0; i < N; i++) {            int u = f[i];            int v = data[u].dic;            if (v == 2) printf("Fell off\n");            else printf("%d %s\n", data[u].e, str[v+1]);        }        printf("\n");    }    return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.