2020-2021 ACM-ICPC, Asia Nanjing Regional Contest (XXI Open Cup, Grand Prix of Nanjing) | JorbanS

E - Evil Coordinate

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define Cases int __; cin >> __; for (int _ = 1; _ <= __; _ ++)
#define aa first
#define bb second
const string no = "Impossible";

const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {1, -1, 0, 0};
int n, mx, my;
string s;
string op = "UDLR";

void solve() {
    cin >> mx >> my >> s;
    n = s.size();
    int cnt[4] = {0};
    for (int i = 0; i < n; i ++)
        for (int j = 0; j < 4; j ++)
            if (s[i] == op[j]) cnt[j] ++;
    vector<int> v{0, 1, 2, 3};
    for (int _ = 0; _ < 24; _ ++) {
        int x = 0, y = 0;
        for (int i = 0; i < 4; i ++) {
            int xx = x + dx[v[i]] * cnt[v[i]], yy = y + dy[v[i]] * cnt[v[i]];
            int minx = min(xx, x), maxx = max(xx, x);
            int miny = min(yy, y), maxy = max(yy, y);
            if (xx == x && x == mx) {
                if (miny <= my && my <= maxy) break;
            } else if (yy == y && y == my) {
                if (minx <= mx && mx <= maxx) break;
            }
            if (i == 3) {
                for (int j = 0; j < 4; j ++)
                    while (cnt[v[j]] --) cout << op[v[j]];
                return;
            }
            x = xx, y = yy;
        }
        next_permutation(v.begin(), v.end());
    }
    cout << no;
}

int main() {
    Cases
    {
        solve();
        cout << endl;
    }
    return 0;
}

F - Fireworks

#include <iostream>
#include <cmath>
using namespace std;
#define Cases int __; cin >> __; for (int _ = 1; _ <= __; _ ++)

const double eps = 1e-6;
double n, m, p;

double cal(double k) {
    return (m + k * n) / (1 - pow(1 - p, k));
}

double solve() {
    cin >> n >> m >> p;
    p /= 1e4;
    double l = 1, r = 2e9;
    while (abs(l - r) >= eps) {
        double mid = (l + r) / 2;
        if (cal(mid - eps) < cal(mid + eps)) r = mid;
        else l = mid;
    }
    return min(cal(floor(l)), cal(ceil(l)));
}

int main() {
    Cases
    printf("%.6lf\n", solve());
    return 0;
}

K - K Co-prime Permutation

#include <iostream>

using namespace std;
#define Cases int __; cin >> __; for (int _ = 1; _ <= __; _ ++)
int n, m;

void solve() {
    cin >> n >> m;
    if (!m) {
        cout << -1 << endl;
        return;
    }
    if (n == 1) {
        cout << (m == 1 ? 1 : -1) << endl;
        return;
    }
    if (m & 1) {
        cout << 1 << ' ';
        m --;
        for (int i = 2; i <= n; i ++) {
            if (m) {
                cout << i + 1 << ' ' << i << ' ';
                m -= 2;
                i ++;
            } else cout << i << ' ';
        }
    } else {
        for (int i = 1; i <= n; i ++) {
            if (m) {
                cout << i + 1 << ' ' << i << ' ';
                m -= 2;
                i ++;
            } else cout << i << ' ';
        }
    }
}

int main() {
    solve();
    return 0;
}

L - Let’s Play Curling

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define Cases int __; cin >> __; for (int _ = 1; _ <= __; _ ++)
const string no = "Impossible";
#define aa first
#define bb second

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 2;
int n, m;

int a[N], b[N];

void solve() {
    cin >> n >> m;
    vector<pair<int, char>> v;
    map<int, bool> mp;
    for (int i = 0; i < n; i ++) {
        int x; cin >> x;
        v.emplace_back(x, 'a');
    }
    for (int i = 0; i < m; i ++) {
        int x; cin >> x;
        mp[x] = true;
        v.emplace_back(x, 'b');
    }
    sort(v.begin(), v.end());
    int res = 0, cnt = 0;
    for (auto it : v) {
        if (it.bb == 'a' && !mp[it.aa]) cnt ++;
        else {
            res = max(res, cnt);
            cnt = 0;
        }
    }
    res = max(res, cnt);
    if (res) cout << res << endl;
    else cout << no << endl;
}

int main() {
    Cases
    solve();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JorbanS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值