zoukankan      html  css  js  c++  java
  • “科大讯飞杯”第18届上海大学程序设计联赛春季赛暨高校网络友谊赛

    比赛链接:https://ac.nowcoder.com/acm/contest/5278

    A - 组队比赛

    题意

    将四个数分为两个和,使二者相差尽量小。

    思路

    最小数加最大数减去次小数和次大数。

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int a[4]; for (int &i : a) cin >> i;
        sort(a, a + 4);
        cout << abs(a[0] + a[3] - a[1] - a[2]);
    }

    B - 每日一报

    题意

    将给定数据按照题目要求排序输出。

    思路

    结构体排序。

    代码

    #include <bits/stdc++.h>
    using namespace std;
    
    struct P{
        string date, num;
        double tem;
    };
    
    int main() {
        int n; cin >> n;
        P a[n]; for (auto &i : a) cin >> i.date >> i.num >> i.tem;
        sort(a, a + n, [] (P a, P b) {
            if (a.date != b.date) return a.date > b.date;
            else if (a.tem != b.tem) return a.tem > b.tem;
            else return a.num < b.num;
        });
        int cnt = 0;
        for (auto i : a) if (i.tem >= 38.0) ++cnt;
        cout << cnt << "
    ";
        for (auto i : a) {
            if (i.tem < 38.0) continue;
            cout << i.date << ' ' << i.num << ' ';
            printf("%.1f
    ", i.tem);
        }
    }

    C - 最长非公共子序列

    题意

    求两个字符串的最长非公共子序列大小。

    思路

    若两个字符串相等则不存在,否则输出较长的的字符串大小即可。

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        string s1, s2; cin >> s1 >> s2;
        if (s1 == s2) cout << "-1";
        else cout << max(s1.size(), s2.size());
    }

    D - 最大字符集

    题意

    构造一个字符串最长为 n 的 01 字符串集,每个长度的字符串最多有一个,所有字符串两两不包含。

    思路

    00

    010

    0110

    01110

    011110

    …………

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int n; cin >> n;
        if (n == 1) cout << "1
    1
    ";
        else if (n == 2) cout << "2
    1
    00
    ";
        else {
            cout << n - 1 << "
    ";
            for (int i = 2; i <= n; i++) {
                cout << "0" + string(i - 2, '1') + "0" << "
    ";
            }
        }
    }

    E - 美味的序列

    题意

    每次从数列的首或尾部取一个数,余下的数都减一,求取完数列所能得到的数之和的最大值。

    思路

    第 1 次取之后余下的 n-1 个数 -1,

    第 2 次取之后余下的 n-2 个数 -1,

    ……

    第 n - 1 次取之后余下 1 个数 -1 。

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int n; cin >> n;
        long long sum = 0;
        int a[n]; for (int &i : a) cin >> i, sum += i;
        cout << sum - 1LL * n * (n - 1) / 2;
    }

    F - 日期小助手

    题意

    输出 2000.1.1~2100.12.31 间一个日期后最近的母亲节或父亲节的日期。

    思路

    平年 365 天,365 % 7 = 1,所以每个平年母亲节和父亲节的日期会较上一年向前偏移一天 (闰年偏移两天),从 2000 年向后递推至 2101 年即可。

    代码

    #include <bits/stdc++.h>
    using namespace std;
    
    int m_day[2200], f_day[2200];
    
    void Print(char c, int d, int y) {
        cout << (c == 'M' ? "Mother's Day: May " : "Father's Day: June ")
             << d
             << (d == 21 ? "st" : "th")
             << ", "
             << y << "
    ";
    }
    
    void solve() {
        int y, m, d; cin >> y >> m >> d;
        if (m < 5 or (m == 5 and d < m_day[y]))
            Print('M', m_day[y], y);
        else if (m < 6 or (m == 6 and d < f_day[y]))
            Print('F', f_day[y], y);
        else
            Print('M', m_day[y + 1], y + 1);
    }
    
    bool is_leap_year(int y) {
        return (y % 4 == 0 and y % 100 != 0) or y % 400 == 0;
    }
    
    void init(int a[], int st, int mi) {
        a[2000] = st;
        for (int i = 2001; i <= 2101; i++) {
            if (is_leap_year(i)) a[i] = a[i - 1] - 2;
            else a[i] = a[i - 1] - 1;
            if (a[i] <= mi) a[i] += 7;
        }
    }
    
    int main() {
        init(m_day, 14, 7);
        init(f_day, 18, 14);
        int t; cin >> t;
        while (t--) solve();
    }
  • 相关阅读:
    波形捕捉:(9)写入到WAV文件
    C#基础回顾:GridView全选演示
    VS.net和Reflector 图标解释
    Dot Net屏幕传输 v1.0
    C#基础回顾:用GDI+绘制验证码
    波形捕捉:(8)使用“捕捉缓冲区”
    DirectX编程:C#中利用Socket实现网络语音通信[初级版本]
    DirectX编程:[初级]C#中利用DirectSound播放WAV格式声音[最少只要4句话]
    GroupingView控件 使用经验
    Dot Net下实现屏幕图像差异获取v2.0
  • 原文地址:https://www.cnblogs.com/Kanoon/p/12726464.html
Copyright © 2011-2022 走看看