ACM省赛试水5.4

整体的比赛流程队友也已经写了,我就补一下题目

CF118A String Task - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/CF118ACF500A New Year Transportation - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/CF500ACF69A Young Physicist - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/CF69ACF177C1 Party - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/CF177C1CF1249B1 Books Exchange (easy version) - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/CF1249B1CF339B Xenia and Ringroad - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/CF339BCF902B Coloring a Tree - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/CF902BCF1623B Game on Ranges - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/CF1623BCF1312B Bogosort - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/CF1312BA:

//#include<bits/std c++.h>
#include <iostream>
#include<ctime>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#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:

//#include<bits/std c++.h>
#include <iostream>
using namespace std;
signed main()
{
        int a[40000];
        int n,m;
        cin >> n>>m;
        for (int i = 1; i < n; i++) {
            cin >> a[i];
        }
        int i = 0;
        for (i = 1; i < m; i += a[i]) {}
        if (i == m) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }

 C:

//#include<bits/std c++.h>
#include <iostream>
#include<ctime>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#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;
    vector<int>arr[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;
}

D:

#include<iostream>
#include <cmath>
using namespace std;
int father[3000];
int cha[3000];
bool vis[3000];
int n, m, ans;
int find(int x)
{
	if (father[x] == x) { 
		return x;
	}
	return father[x] = find(father[x]);
}
void init() {
	for (int i = 1; i <= n; ++i) {
		father[i] = i;
	}
}
int main()
{
	int x, y;
	int t;
	cin >> n >> m;
	init();
	for (int i = 1; i <= m; i++) 
	{
		cin >> x >> y;
		father[find(x)] = find(y);//并查集合并
	}
	cin >> t;
	for (int i = 1; i <= t;i++)
	{
		cin >> x >> y;
		if (find(x) != find(y)) {
			continue;//祖先不相同,说明不在同一个集合当中
		}
		vis[find(x)] = 1;//标记这个有讨厌边权的祖先
	}
	for (int i = 1; i <= n; ++i) {
		cha[find(i)]++;//一共有多少个集合,并且这些集合里面的元素有多少个都给统计出来了
	}

	for (int i = 1; i <= n; ++i)
	{
		if (father[i] != i || vis[i]) {
			continue;
		}
		ans = max(ans, cha[i]);//取得这些条件的最大值
	}
	cout << ans << endl;}

 E:

//#include<bits/std c++.h>
#include <iostream>
#include<ctime>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#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:

#include <iostream>
using namespace std;
int a[1000100];
int main() {
	int n,m;cin>>n>>m;
	for(int i = 0;i < m;i++) cin>>a[i];	
	int inf = 1;		
	long long ans = 0;
	for(int i = 0;i < m;i++) {
		if(inf < a[i]) {
			ans += (a[i]-inf);
		} else if(inf > a[i]) {
			ans += n - (inf-a[i]); 
		}
		inf = a[i];
	}
	cout<<ans<<endl;
}

 G:

#include <iostream>
#include <vector>
using namespace std;
int n;
int dis[11000];
long long ans;
int t;
vector<int>v[11000];
void dfs(int x, int color) {//x为结点
	if (dis[x] != color) {//如果颜色相同不染色,如果不同染色++
		ans++;
	}
	int size = v[x].size();
	for (int i = 0; i < size; i++) {
		int y = v[x][i];
		dfs(y, dis[x]);
	}
}
int main() {
	cin >> n;
	for (int i = 2; i <= n; i++) {
		cin >> t;
		v[t].push_back(i);//建树
	}
	for (int i = 1; i <= n; i++) {
		cin >> dis[i];//输入每个结点的染色情况
	}		
	dfs(1, -2);
	cout << ans << endl;
}

I:(这题我没看)

//#include<bits/std c++.h>
#include <iostream>
#include<ctime>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#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;
        vector<int>arr;
        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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

钟一淼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值