西南民族大学 春季 2023 训练赛4

发布时间 2023-04-05 04:45:24作者: Ke_scholar

小石的图形

太坑了, π的精度一定要开大,不然就wa, 建议用acos(-1)或者M_PI.

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f

using namespace std;
//typedef long long ll;

const int N = 1e5+10;
int n,m,t;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    printf("%.3lf",n * n * 0.5 / M_PI);
    return 0;
}

植树造林

刚开始想的是对的,但一直觉得没有这么简单,最后不知道怎么想就交上去了,结果真是奇数输出1偶数输出2......

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f

using namespace std;
//typedef long long ll;

const int N = 1e5+10;
int n,m,t,k;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n ;
    if(n & 1)
    cout << 1 << endl;
    else
     cout << 2 <<endl; 
    return 0;
}

Forsaken给学生分组

值得注意的是,一个人一组的话,能力值最高和最低都是他自己,并不存在只有最高值而无最低值一说...

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f

using namespace std;
//typedef long long ll;

const int N = 1e5+10;
int n,m,t,k,a[N],ans;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; i++)
     cin >> a[i];
    sort(a, a + n);
    for(int i = 0;i < k ; i ++)
     ans += a[n - i - 1] - a[i];
    cout << ans << endl;
    return 0;
}

分数的运算

纯模拟,感觉是我想得太复杂了,所以第一次写多了错了()

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <utility>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long

using namespace std;

const int N = 1e5+10;

//typedef long long ll;

int n,m,t;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int x11,x22,y11,y22;
    cin >> x11 >> y11 >> x22 >> y22;
    int d = __gcd(x11 * y22 + x22 * y11, y11 * y22);
    cout << (x11 * y22 + x22 * y11) / d << ' ' << y11 * y22 / d << endl;
    d = __gcd(x11 * y22 - x22 * y11, y11 * y22);
    if(x11 * y22 - x22 * y11 == 0)
     cout << 0 << ' ' << 0 << endl;
    else
    {
    if(x11 * y22 < x22 * y11) cout << "-";
    cout << abs(x11 * y22 - x22 * y11) / d << ' ' << y11 * y22 / d << endl;        
    }
    d = __gcd(x11 * x22, y11 * y22);
    cout << x11 * x22 / d << ' ' << y11 * y22 / d << endl;
    d = __gcd(x11 * y22 , y11 * x22);
    cout << x11 * y22 / d << ' ' << y11 * x22 / d << endl; 
    
    return 0;
}

小y的旅行

小L的数列

小L的编辑器

可以用双端队列

C++ STL deque容器(详解版) (biancheng.net)

#include <iostream>
#include <cstring>
#include <queue>
#define int long long

using namespace std;

deque<char> q;

signed main() {
    ios :: sync_with_stdio(false);
    cin.tie(0) , cout.tie(0);
    
    string s , t ;
    cin >> s >> t;
    
    q.push_back(s[s.size()-1]);
    for(int i=s.size()-1; i; i--){
        if(t[i-1] == 'L'){
            q.push_back(s[i-1]);
        }
        else q.push_front(s[i-1]);
    }
    while(q.size()){
        cout << q.front();
        q.pop_front();
    }
    return 0;
}

也可以先把'L' 和'R' 分开存,然后讲'L'的字符串反向

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <utility>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long

using namespace std;

const int N = 1e5+10;

//typedef long long ll;

int n,m,t;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s1,s2,s3,s4;
    cin >> s1 >> s2;
    for(int i = 0; i < s2.size(); i++)
    {
        if(s2[i] == 'R')
        s3 += s1[i];
        else 
         s4 += s1[i];
    }
    reverse(s4.begin(), s4.end());
    cout << s3 << s4 << endl;
    return 0;
}

1408