模拟赛

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
#define N 100000 + 10
#define LL long long
const int mod = 365 * 24 * 3600;

struct que
{
    LL a, b;
};

bool cmp(que t1, que t2)
{
    if(t1.a == 0) return true;
    if(t1.b == 0) return false;
    return t1.a * t2.b < t2.a * t1.b;
}

int n;
que t[N];

int main()
{
    while(~scanf("%d", &n) && n)
    {
        for(int i = 0; i < n; i++)
            scanf("%I64d%I64d", &t[i].a, &t[i].b);
        sort(t, t + n, cmp);
        LL ans = 0;
        for(int i = 0; i < n; i++)
            ans = (ans + t[i].a + ans * t[i].b) % mod;
        printf("%I64d\n", ans);
    }
    return 0;
}



#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
#define N 25

int n, s1, s2, t1, t2, k;
char dir1, dir2;

void doit(char& ch, int& x, int& y, int s)
{
    char tmp = ch;
    if(ch == 'W')
    {
        if(y - s >= 1)
            y -= s;
        else
        {
            y = s - y + 2;
            ch = 'E';
        }
    }

    else if(ch == 'E')
    {
        if(y + s <= n)
            y += s;
        else
        {
            y = 2 * n - s - y;
            ch = 'W';
        }
    }

    else if(ch == 'N')
    {
        if(x - s >= 1)
            x -= s;
        else
        {
            x = s - x + 2;
            ch = 'S';
        }
    }

    else
    {
        if(x + s <= n)
            x += s;
        else
        {
            x = 2 * n - s - x;
            ch = 'N';
        }
    }
}

map<char, char> mm;
void solve()
{
    mm['N'] = 'W', mm['E'] = 'N', mm['S'] = 'E', mm['W'] = 'S';
    int time = 0, x1 = 1, y1 = 1, x2 = n, y2 = n;
    while(time < k)
    {
        doit(dir1, x1, y1, s1);
        doit(dir2, x2, y2, s2);
        time++;
        if(x1 == x2 && y1 == y2) swap(dir1, dir2);
        else
        {
            if(time % t1 == 0)
                dir1 = mm[dir1];
            if(time % t2 == 0)
                dir2 = mm[dir2];
        }
    }
    printf("%d %d\n%d %d\n", x1, y1, x2, y2);
}

int main()
{
    while(~scanf("%d", &n) && n)
    {
        scanf(" %c%d%d", &dir1, &s1, &t1);
        scanf(" %c%d%d", &dir2, &s2, &t2);
        scanf("%d", &k);
        solve();
    }
    return 0;
}

你可能感兴趣的:(ACM)