CodeForces 1650

A - Deletions of Two Adjacent Letters

思路:给定一个字符串,进行任意次以下操作:选择字符串中的任意两个相邻字母 s并将它们从字符串中删除,使过程以长度为 1、由字母 c 组成的字符串结束。只需要判断字符串中是否存在这个字符,并且该字符的下表是偶数即可

ac代码

#include<iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int flag = 0;
		string s;
		cin >> s;
		char c;
		cin >> c;
		for (int i = 0; i < s.size(); i++)
		{
			if (s[i] == c&&i%2==0)
			{
				flag = 1;
				break;
			}
		}
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

B - DIV + MOD
思路:给定一个区间,输出区段上函数的最大值。比较r- r % a - 1和r带入函数的结果,输出较大值即可,注意r- r % a - 1的值不能小于l。

ac代码

#include<iostream>
using namespace std;

int fun(int x, int p)
{
	return x / p + x % p;
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int l, r, a;
		cin >> l >> r >> a;

		int e1 = fun(r, a);
		int f = r- r % a - 1;
		int e2 = 0;
		if(f>=l)
			e2 = fun(f, a);

		cout << max(e1, e2) << endl;
	}
	return 0;
}

C - Weight of the System of Nested Segments
思路:使用结构体存放一个点的信息,包括下标,索引,权值;对权值升序排序,找到权值最小的几个。使用pair数组存放最小的几个的下标和索引,对下标再进行排序,输出对应索引即可

ac代码

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 2e5 + 10;

struct trip{
    int _a,_b,_idx;//表示下标,权值,索引
    //对权值排序
    bool operator<(const trip&w)const{
        return _b<w._b;
    }
}trip[N];

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		cin >> n >> m;
		for(int i=0;i<m;i++)
		{
			int a, b;
			cin >> a >> b;
			trip[i]={a,b,i+1};
		}
		sort(trip, trip + m);
		long long ans = 0;
		for (int i = 0; i < 2*n; i++)
		{
			ans += trip[i]._b;
		}
		
		cout<<ans<<endl;
		vector<pair<int,int>>ma;
		for (int i = 0; i < 2 * n; i++)
		{
			ma.push_back({trip[i]._a,trip[i]._idx});
		}
		sort(ma.begin(),ma.end());
		for(int i=0;i<n;i++)
		    cout<<ma[i].second<<" "<<ma[2*n-i-1].second<<endl;
		   
	}
	return 0;
}

D - Twist the Permutation

思路:将数字向左移动,回到1,2,3,4……的状态就可,可以看出,将第i个数向左移动时,前i个数都要跟着移动,i之后的数就不会移动。所以我们从大到小枚举,模拟即可

ac代码

#include<iostream>
using namespace std;
const int N = 2e3 + 10;
int a[N];
int f[N];

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		for (int i = 1; i <= n; i++)
		{
			int x; cin >> x;
			a[x] = i;
		}
		for (int i = n; i >= 1; i--)
		{
			int tt = a[i];
			int yy = a[i] % i;
			f[i] = yy;
			for (int j = 1; j <= i; j++)
			{
				if (a[j] - yy >= 0)
					a[j] = a[j] - yy;
				else
					a[j] = ( a[j] - yy + i) % n;
			}
		}
		for (int i = 1; i <= n; i++)
			cout << f[i] << " ";
		cout << endl;
	}

	return 0;
}
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

~nilv

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

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

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

打赏作者

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

抵扣说明:

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

余额充值