华东交通大学2019年ACM 双基 程序设计竞赛 个人题解(A - K)

目前先放几道题面,等晚上做完实验补

Update:A ~ D,更新剩余的题面(题面复制会有链接水印,懒得一一去除、直接截图)

A、签到

真·签到题

输出祝贺祖国成立70周年!即可

B、欧涛的烦恼

思路:

简单累加,然后注意取整即可

// Author : RioTian
// Time : 20/11/02
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll _, n;
void solve() {
    cin >> n;
    int a;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a;
        sum += a;
    }
    cout << (sum + n - 1) / n << endl;
}
int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> _;
    while (_--) solve();
}

C、欧涛最短路

思路:

跑一遍迪杰斯特拉最短路就可以的样子,不知道为什么没什么人过

// Author : RioTian
// Time : 20/11/02
#include <bits/stdc++.h>
#define ll long long
#define N 608
using namespace std;
const double INF = 0x4242424242424242;
int vis[N];
int path[N];
double dis[N];
double mp[N][N];
double cord[N][3];
double ans;
void dijkstra(int n) {
    for (int i = 0; i < n; ++i) dis[i] = mp[0][i];
    dis[0] = 0;
    vis[0] = 1;
    double mmin = dis[606];
    int pos = -1;
    for (int i = 0; i < n; ++i) {
        mmin = dis[606];
        pos = -1;
        for (int j = 0; j < n; ++j) {
            if (!vis[j] && dis[j] < mmin) {
                pos = j;
                mmin = dis[j];
            }
        }
        if (pos == -1) break;
        vis[pos] = 1;
        for (int j = 0; j < n; ++j) {
            if (!vis[j] && dis[j] > dis[pos] + mp[pos][j]) {
                dis[j] = dis[pos] + mp[pos][j];
                path[j] = pos;
            }
        }
    }
    ans = dis[n - 1];
}
int main() {
    int n;
    double m;
    while (cin >> n >> m) {
        memset(mp, 0x42, sizeof mp);
        memset(dis, 0x42, sizeof dis);
        memset(path, -1, sizeof path);
        memset(vis, 0, sizeof vis);
        cin >> cord[0][0] >> cord[0][1] >> cord[0][2];
        cin >> cord[n + 1][0] >> cord[n + 1][1] >> cord[n + 1][2];
        for (int i = 1; i <= n; ++i)
            scanf("%lf %lf %lf", &cord[i][0], &cord[i][1], &cord[i][2]);
        for (int i = 0; i <= n + 1; ++i) {
            for (int j = i + 1; j <= n + 1; ++j) {
                double x =
                    (1.0 * cord[i][0] - cord[j][0]) * (cord[i][0] - cord[j][0]);
                double y =
                    (1.0 * cord[i][1] - cord[j][1]) * (cord[i][1] - cord[j][1]);
                double z =
                    (1.0 * cord[i][2] - cord[j][2]) * (cord[i][2] - cord[j][2]);
                double len = sqrt(x + y + z);
                if (len <= m) mp[i][j] = mp[j][i] = len;
            }
        }
        dijkstra(n + 2);
        if (ans < dis[606]) {
            printf("%.3f\n", ans);
            stack<int> st;
            while (!st.empty()) st.pop();
            for (int i = path[n + 1]; i != -1; i = path[i]) st.push(i);
            cout << "Start ";
            while (!st.empty()) {
                cout << st.top() << " ";
                st.pop();
            }
            cout << "End\n";
        } else
            cout << -1 << endl;
    }
}

D、 甜甜圈

// Author : RioTian
// Time : 20/11/02
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    // freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s;
    int n;
    cin >> n;
    while (n--) {
        cin >> s;
        int res = 0;
        for (int i = 0; i < s.length(); ++i) {
            if (s[i] == '0' || s[i] == '4' || s[i] == '6' || s[i] == '9') res++;
            else if (s[i] == '8') res += 2;
        }
        cout << res << endl;
    }
}

E、欧涛爬树

F、欧涛B

G、数据结构

H、谁在说谎

// Author : RioTian
// Time : 20/11/08
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, dp[N], v[N];
struct node {
    int l, r;
} nd[N], lst_nd[N];
bool cmp(node a, node b) {
    if (a.r != b.r) return a.r < b.r;
    return a.l < b.l;
}
int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int l, r, tol = 0, tot = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> l >> r;
        if (l + r >= n) continue;
        nd[++tol].l = l + 1;
        nd[tol].r = n - r;
    }
    sort(nd + 1, nd + 1 + tol, cmp);
    for (int i = 1; i <= tol; ++i) {
        if (nd[i].l != nd[i - 1].l || nd[i].r != nd[i - 1].r)
            lst_nd[++tot].l = nd[i].l, lst_nd[tot].r = nd[i].r;
        v[tot] = min(v[tot] + 1, nd[i].r - nd[i].l + 1);
    }
    for (int i = 1, j = 1; i <= n; i++) {
        dp[i] = dp[i - 1];
        while (j <= tot && lst_nd[j].r == i) {
            dp[i] = max(dp[i], dp[lst_nd[j].l - 1] + v[j]);
            j++;
        }
    }
    cout << n - dp[n] << endl;
}

I、不要666

J、组合技

K、这个勇者明明超强却过分慎重

玩梗好评

基本递推,打表找规律

const int mod = 666666;
ll n, m;
int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int a = 4, b = 233, ans[100000] = {0}, c = 0;
    for (int i = 1; i <= 2523; ++i) {
        c = ((a * 3 % mod) + (b * 4 % mod)) % mod;
        a = b, b = c;
        ans[i] = c;
    }
    while (cin >> n >> m) {
        if (n == 1)
            cout << m - 4 << endl;
        else if (n == 2)
            cout << m - 233 << endl;
        else
            cout << m - ans[(n - 2) % 2520] << endl;
    }
}
posted @ 2020-11-02 18:14  RioTian  阅读(169)  评论(0编辑  收藏  举报