5月4日 vp训练赛

5月4日 vp训练赛,第1张

这场感觉还行,9题出了7题,大概花了2个多小时,剩下的时间都卡在了并查集的那题,还有一个二叉树的好像也不太会,数据结构虽然学完了但是因为一直没用到不会敲了。不过总体写的很舒服,队友也很给力,提供了很多思路和题目的理解。目前我们队的节奏就是先一起开一道题,如果思路确定了,就我去写代码,另外两个人去开另一道,然后我提交完再跟上他们,他们跟我讲题目理解和思路。我觉得目前的节奏就挺合适的,但是我也得继续提高思维和代码实现的能力不能让队友失望。

目录

Ahttps://vjudge.net/problem/CodeForces-118A/origin

B https://vjudge.net/problem/CodeForces-500A/origin

Chttps://vjudge.net/problem/CodeForces-69A/origin

Dhttps://vjudge.net/problem/CodeForces-177C1/origin (待补)

Ehttps://vjudge.net/problem/CodeForces-1249B1/origin

   F--https://vjudge.net/problem/CodeForces-339B/origin

G https://vjudge.net/problem/CodeForces-902B/origin(待补)

H--省赛尝试四 - Virtual Judge

Ihttps://vjudge.net/problem/CodeForces-1312B/origin


Ahttps://vjudge.net/problem/CodeForces-118A/origin

http://codeforces.com/problemset/problem/118/A

思路:大写转换为小写然后判断原是否为元音字母即可

//#include
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define int ll
#pragma warning (disable:4996);
using namespace std;
const int N = 10;
signed main()
{
    ios::sync_with_stdio(false); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif // !ONLINE_JUDGE
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); j++) {
        char t = s[j];

        if (t >= 'A' && t <= 'Z')
            t += 32;
        if (t == 'a' || t == 'e' || t == 'i' || t == 'o'||t=='u'||t=='y') {
            continue;
        }
        else cout << "." << t;
    }
    return 0;
}
B https://vjudge.net/problem/CodeForces-500A/origin

思路: 链式数组不断加上当前的元素进行访问,如果当当前下标超过的目标值,又无法返回,结束数组的跳跃,反之到达了目标值输出YES结束数组跳跃

//#include
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define int ll
#pragma warning (disable:4996);
using namespace std;
const int N = 10;
int T;

int cmp(int a, int b) {
    return a > b;
}
int arr[300001] = { 0 };
signed main()
{
    ios::sync_with_stdio(false); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
   // freopen("out.txt", "w", stdout);
#endif // !ONLINE_JUDGE
    int n, t;
    cin >> n >> t;
    for (int j = 1; j <= n - 1; j++) {
        int k;
        cin >> k;
        arr[j] = k;
    }
   
    int x = 1;
    int ok = 0;
    while (x
Chttps://vjudge.net/problem/CodeForces-69A/origin

 思路:多个三个元素的向量相加为0向量,每个位置对应的和都要为0

//#include
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define int ll
#pragma warning (disable:4996);
using namespace std;
const int N = 10;
int T;
int cmp(int a, int b) {
    return a > b;
}
int arr[1001]={0};
signed main()
{
    ios::sync_with_stdio(false); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
   // freopen("out.txt", "w", stdout);
#endif // !ONLINE_JUDGE
    int n;
    cin >> n;
    int sum = 0;
    int a, b, c;
    vectorarr[1011];
    for (int j = 1;j<=n; j++) {
        cin >> a >> b >> c;
        arr[j] = { a,b,c };
    }
    int s1=0, s2=0, s3 = 0;
    for (int j = 1; j <= n; j++) {
        s1 += arr[j][0];
        s2 += arr[j][1];
        s3 += arr[j][2];
    }
    if (s1 == 0 && s2 == 0 && s3 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}
Dhttps://vjudge.net/problem/CodeForces-177C1/origin (待补)

Ehttps://vjudge.net/problem/CodeForces-1249B1/origin

 思路:链式记录每本书的去向,但第i本书(原数组对应的值)到了第i个人的手里输出次数的递书的次数

//#include
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define int ll
#pragma warning (disable:4996);
using namespace std;
const int N = 10;
int T;

int cmp(int a, int b) {
    return a > b;
}
int arr[3000001] = { 0 };

signed main()
{
    ios::sync_with_stdio(false); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif // !ONLINE_JUDGE
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        int vis[3001] = { 0 };
        for (int j = 1; j <= n; j++) {
            int t;
            cin >> t;
            arr[j] = t;
        }
       
        for (int j = 1; j <= n; j++) {
            int cnt = 0;
            int x = j;
            while (arr[x] != j&&arr[j]!=0) {//模拟每本书的去向
                x = arr[x];
                cnt++;
            }
            cout << cnt + 1 << " ";
        }
        cout << endl;
    }
    return 0;
}
   F--https://vjudge.net/problem/CodeForces-339B/origin

 思路:特判第一位为1.讨论后一个元素如果大于后一个元素和后一个小于前一个元素的情况,如果为前者,说明是正序向前走,加上对应步数。如果是后者,说明已经绕了一圈再到对应位置,长度为圈长-a+b

//#include
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define int ll
#pragma warning (disable:4996);
using namespace std;
const int N = 10;
int T;

int cmp(int a, int b) {
    return a > b;
}
int arr[3000001] = { 0 };

signed main()
{
    ios::sync_with_stdio(false); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
   // freopen("out.txt", "w", stdout);
#endif // !ONLINE_JUDGE
    int t, n;
    cin >> t >> n;
    for (int j = 1; j <= n; j++) {
        cin >> arr[j];
    }
    if (n == 1) {
        cout << arr[1] - 1 << endl;
        return 0;
    }
    int s = arr[1]-1;
    int idx = arr[1];
    for (int j = 2; j <= n; j++) {
        if (arr[j] < arr[j - 1]) {
            s += ((t - idx) + arr[j]);
                idx = arr[j];
        }
        else if (arr[j] > arr[j - 1]) {
            s += (arr[j] - idx);
            idx = arr[j];
        }
        else {
            continue;
        }
    }
    cout << s << endl;
    return 0;
}
G https://vjudge.net/problem/CodeForces-902B/origin

 思路:关键点是子树的颜色都与该子树的根节点相同,所以搜索的时候不必去填补颜色,只需要判断该根节点的颜色即可 。然后记录根节点颜色继续向下遍历子树。

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define int ll
#pragma warning (disable:4996);
using namespace std;
const int N = 1e4+10;
int T;

int cmp(int a, int b) {
    return a > b;
}

vectortree[N];
int mp[N];
int n;
int ans = 0;
void dfs(int dep,int f,int c) {//dep当前节点编号,f表示根节点,c为根节点的颜色
    if (mp[dep] != c)//如果根节点与该节点对应的颜色不同则染色且ans++
        ans++;
    for (auto x : tree[dep]) {//遍历该根节点的子树
        if (x != f) {//不能回走,向下遍历子树
            dfs(x, dep, mp[dep]);
        }
    }
}
signed main()
{
    ios::sync_with_stdio(false); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
 //   freopen("out.txt", "w", stdout);   
#endif // !ONLINE_JUDGE
    cin >> n;
    for (int j = 2; j <= n; j++) {
        int t;
        cin >> t;
        tree[t].push_back(j);//无向边,邻接矩阵存储
        tree[j].push_back(t);
    }
    for (int j = 1; j <= n; j++) {
        cin >> mp[j];//记录每个节点对应的颜色
    }
    dfs(1, -1, -1);//-1与正常值区分
        cout << ans << endl;
    return 0;
}

H--省赛尝试四 - Virtual Judge

 思路:枚举并查找对应区间(用map,pair-int键值对)是否存在,直到左边界等于右边界


#include 
#include 
#include 
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        map, bool> mp;
        vector l(n);
        vectorr(n);
        for (int i = 0; i < n; i++)
        {
            cin >> l[i] >> r[i];
            mp[{l[i], r[i]}] = 1;
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = l[i]; j <= r[i]; j++)
            {

                if ((j == l[i] || mp[{l[i], j - 1}]) && (j == r[i] || mp[{j + 1, r[i]}]))
                {//区间判断输出所取的数
                    cout << l[i] << " " << r[i] << " " << j << endl;
                    break;
                }
            }
        }
    }
}


Ihttps://vjudge.net/problem/CodeForces-1312B/origin

 思路:观察到条件和单调性有些关系。

倒序将大的元素放在前边,如果这都不能满足条件,也就不可能有解了

//#include
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define int ll
#pragma warning (disable:4996);
using namespace std;
const int N = 10;
int T;

int cmp(int a, int b) {
    return a > b;
}
signed main()
{
    ios::sync_with_stdio(false); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
   // freopen("out.txt", "w", stdout);
#endif // !ONLINE_JUDGE
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vectorarr;
        for (int j = 0; j< n; j++) {
            int t;
            cin >> t;
            arr.push_back(t);

        }
        sort(arr.begin(), arr.end(), cmp);
        for (auto x : arr) {
            cout << x << " ";
        }
        cout << endl;
    }
    return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/867914.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)