uvalive 5781 Chain of Fools

竟然没有读懂题意,一个很简单的题到比赛结束都没有写。。。

算是一个教训吧。

/*
 * Author: stormdpzh
 * Created Time: 2012/5/26 21:01:58
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>

#define sz(v) ((int)(v).size())
#define rep(i, n) for(int i = 0; i < n; i++)
#define repf(i, a, b) for(int i = a; i <= b; i++)
#define repd(i, a, b) for(int i = a; i >= b; i--)
#define out(n) printf("%d\n", n)
#define mset(a, b) memset(a, b, sizeof(a))
#define wh(n) while(scanf("%d", &n) != EOF)
#define whz(n) while(scanf("%d", &n) != EOF && n != 0)
#define lint long long

using namespace std;

const int MaxN = 205;

bool visited[MaxN];
int s, c, p, l;

int gao()
{
    int t = s - p;
    mset(visited, false);
    int i = 0;
    while(true) {
        int tmp = (i * s + l + t) % c;
        if(visited[tmp]) return -1;
        visited[tmp] = true;
        if(tmp == 0) {
            if(p == 0) return i + 1;
            return i;
        }
        i++;
    }
}

int main()
{
    int ans = 1;
    while(scanf("%d%d%d%d", &s, &c, &p, &l) != EOF) {
        if(!(s || c || p || l)) break;
        int r = gao();
        printf("Case %d: ", ans++);
        if(r == -1) printf("Never\n");
        else {
            if(p != 0) printf("%d %d/%d\n", r, s - p, s);
            else printf("%d %d/%d\n", r, 0, s);
        }
    }
    return 0;
}

你可能感兴趣的:(uvalive 5781 Chain of Fools)