沈阳化工大学21级一月月赛(正式赛)题解

· · 个人记录

A 初中数学知识

#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    double x1, y1, x2, y2;
    int n;
    cin >> x1 >> y1 >> x2 >> y2 >> n;

    double mix = 0, miy = 0;
    mix = (x1 + x2) / 2;
    miy = (y1 + y2) / 2;

    double k1 = (y1 - y2) * 1.0 / (x1 - x2);

    while (n--)
    {
        double x, y;
        cin >> x >> y;
        double len1 = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
        double len2 = sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));

        double k2 = (y - miy) * 1.0 / (x - mix);

        if (k1 * k2 == -1 && len1 == len2)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

B 高中数学知识

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PII;

const int N = 3010;

int a[N];

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;

    for (int i = 1; i <= n; i ++)  // 预处理
    {
        int x = i;
        int cnt = 0;
        while (1)
        {
            int num = 0;
            if (x == 0)
                break;
            if(x < 10)
            {
                x = 0;
                cnt ++;
            }
            else
            {
                int y = x;
                while (y)
                {
                    num += y % 10;
                    y /= 10;
                }
                cnt ++;
            }
            x = num;
        }
        a[i] = cnt;
    }
    int res = 0;
    for (int z = 1; z <= n; z ++) // 暴力查找
        for (int y = z + 1; y <= n; y ++)
            for (int x = y + 1; x <= n; x ++)
                if (a[x] < a[y] && a[y] < a[z])
                    res ++;

    cout << res << endl;

    return 0;
}

C 完美横幅

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s;
    string str;
    while (cin >> str) // 字符串读入,因为中间含有空格,所以利用多组输入和getline都可
        s += str;      // 不要使用gets(忘掉gets),因为gets在C++11种已经被删除,以后比赛使用了也可能会过不去

    int f = s.length();

    for (int i = 0; i < f; i ++)  // 因为无视大小写,所以索性将他们都转换为小写
        if (s[i] >='A' && s[i] <= 'Z')
            s[i] += 32;

    string s1 = "syuct", s2 = "sylu";

    int res = 0, ress = 0;
    int j = 0;
    for (int i = 0; i < f; i ++)
    {
        if (s[i] == s1[j])
            j ++;
        if (j == 5)
            j = 0,res ++;
    }
    j = 0; // 重置 j
    for (int i = 0; i < f; i ++)
    {
        if (s[i] == s2[j])
            j ++;
        if (j == 4)
            j = 0,ress ++;
    }

    if (res == ress && res != 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

D 经典博弈

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, m;// 如果n % (m + 1) != 0的话,那么先手第一次取走余数,然后,无论后手怎么拿,先手都拿到(m + 1)就好了,所以先手必赢。

    cin >> n >> m;

    if (n % (m + 1) == 0) 
    {
        cout << "second" << endl;
    }
    else
    {
        cout << "first" << endl;
    }

    return 0;
}

E 偏爱正方形

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

LL n, m;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> m;

    if (n > m)
        swap(n, m);

    LL res = 0;

    for (int i = 1; i <= n; i ++)
    {
        res += ((n - i + 1) * (m - i + 1));
    }

    cout << res << endl;

    return 0;
}

F 过年啦~~~

#include <bits/stdc++.h> 

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << "\"you/dao/le/guo/nian/de/shi/hou/le\"" << endl;//注意转义字符

    return 0;
}

G "经典"题

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    scanf("%d", &t);
    while (t --)
    {
        LL x;
        scanf("%lld", &x);
        x *= 2;
        LL n = sqrt(x); 
        if (n * (n + 1) == x)
            puts("YES");
        else
            puts("NO");
    }

    return 0;
}

H 时间显示

出题人acwing题解链接:https://www.acwing.com/solution/content/72383/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ms;
ll hour, minute, s;
int main()
{
    cin >> ms;
    hour = ms / 1000 / 60 / 60;
    hour = hour % 24;
    minute = ms / 1000 / 60;
    minute = minute % 60;
    s = ms / 1000;
    s = s % 60;
    printf("%02lld:%02lld:%02lld", hour, minute, s);
    return 0;
}

I "坏掉"的计算器

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;

    int res = 0;

    while (n != 1)
    {
        if (n & 1)
            n --;
        else
            n /= 2;
        res ++;
    }

    cout << res << endl;

    return 0;
}

J 拖拉机与干草堆

重载运算符版本

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 200010;

struct node
{
    double s;
    int num;
    bool operator < (const node &w) const
    {
        return s < w.s;
    }
}a[N];
int n;
double xx, yy;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> xx >> yy;

    for (int i = 1; i <= n; i ++)
    {
        double x, y;
        cin >> x >> y;
        double s = sqrt((x - xx) * (x - xx) + (y - yy) * (y - yy));
        a[i].s = s;
        a[i].num = i;
    }

    sort(a + 1, a + n + 1);

    for (int i = 1; i <= n; i ++)
    {
        if (i != 1)
            cout << ' ';
        cout << a[i].num;
    }
    cout << endl;

    return 0;
}

函数版本

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 200010;

struct node
{
    double dist;
    int num;
}s[N];

bool cmp(node x, node y)
{
    return x.dist < y.dist;
}

int n;
double a, b;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> a >> b;

    for (int i = 1; i <= n; i ++)
    {
        double x, y;
        cin >> x >> y;
        s[i].dist = sqrt((x - a) * (x - a) + (y - b) * (y - b));
        s[i].num = i;
    }

    sort(s + 1, s + n + 1, cmp);

    for (int i = 1; i <= n; i ++)
        cout << s[i].num << ' ';
    cout << endl;

    return 0;
}

K 王木辛r穿越时光机(穿越篇)

#include <iostream>
using namespace std;
long long c(int a, int b)
{
    long long ans = 1;
    for (int j = 1; j <= a; j++)
    {
        ans = ans * b / j;
        b--;
    }
    return ans;
}
int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n, m, k, t;
        cin >> n >> m >> k >> t;
        long long sum = 0;
        for (int i = 4; i <= n; i++)
        {
            if (t - i > m || t - i < 2)
                continue;
            sum += k * c(i, n) * c(t - i, m);
        }
        cout << sum << endl;
    }
}

L AhxcwPw3n

#include <bits、stdc++.h>
using namespace std;
const int N=1e6;
string a = "AhxcwPw3n";
string b = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int get(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
  else  if (c >= 'A' && c <= 'Z')
        return c - 'A' + 10;
  else
        return c - 'a' + 36;
}
char res[N];
long long sum;
int k=0;
int main()
{  
    for (int i = a.size() - 1; i >= 0; i--)
    { 
        sum=sum+get(a[i])*pow(62,k);   
        k++;
    }//转化成十进制
    k=0;
   while(sum)
   {
        res[k++]=b[sum%47];
        sum/=47;
   }
   for(int i=k-1;i>=0;i--)
   {
          cout<<res[i];
   }
   cout<<endl;

    return 0;
}

M 小A吃水果

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 1010;

int a[N];
int n, C;
int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> C;

    for (int i = 1; i <= n; i ++) cin >> a[i];

    int res = 0;

    for (int i = 1; i <= n; i ++)
    {
        int num = 0;
        int x = C;
        for (int j = i; j <= n; j ++)//从选择吃的位置开始
        {
            if (a[j] <= x)
            {
                num ++;
                x -= a[j];
            }
        }
        res = max(res, num);//维护最大值
    }

    cout << res << endl;

    return 0;
}