Codeforces Round #776 (Div. 3)

A. Deletions of Two Adjacent Letters

题意

  • 链接A. Deletions of Two Adjacent Letters
  • 给出一个长度为奇数的字符串s( 1 ≤ t ≤ 49 1 \le t\le49 1t49)和一个字符c,每一次操作可以把字符串中任意两个相邻的字符删除,如果可以通过任意次操作得到字符c则输出YES否则输出NO。
  • t组数据 ( 1 ≤ t ≤ 1 0 3 1 \le t\le10^3 1t103)

解题思路

  • 思维
  • 如果c在s中左右各有偶数长度即可。

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		string s,c;
		cin>>s>>c;
		int len=s.length(),f=0;
		for(int i=0;i<len;i++)
		{
			if((i%2==0)&&(s[i]==c[0]))
			{
				f=1;break;
			}
		}
		if(f==1)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
} 

B. DIV + MOD

题意

  • 链接B. DIV + MOD
  • f a ( x ) = ⌊ x a ⌋ + x   m o d   a f_a(x)=⌊\frac{x}{a}⌋+x \, mod\, a fa(x)=ax+xmoda,给出a和x的取值范围 l ≤ x ≤ r l \le x\le r lxr,求出 f a ( x ) f_a(x) fa(x)的最大值

解题思路

  • 数学
  • x在l到r内取值,x/a是递增,那么从r开始往左看就是递减,再看xmod a他是伪周期性递增,那么最大值只可能在r这个点或者在倒数第二个周期的顶点

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int l,r,a;
		cin>>l>>r>>a;
		int ans=r/a+r%a,x=r-(r%a+1);
		if(x>=l)ans=max(ans,x/a+x%a);
		printf("%d\n",ans);
	}
	return 0;
}

C. Weight of the System of Nested Segments

题意

解题思路

  • 贪心
  • 取权重最小的2n个点,如果将2n个点按坐标排序,一左一右取组合。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
struct node{
	int x,w,id;
}a[maxn],b[maxn];
bool cmp1(node X,node Y)
{
	return X.w<Y.w; 
}
bool cmp2(node X,node Y)
{
	return X.x<Y.x; 
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=m;i++)
		{
			cin>>a[i].x>>a[i].w;
			a[i].id=i;
		}
		sort(a+1,a+1+m,cmp1);
		int len=2*n,ans=0;
		for(int i=1;i<=len;i++)
		{
			b[i].id=a[i].id;
			b[i].x=a[i].x;
			b[i].w=a[i].w;
			ans+=a[i].w;
		}
		sort(b+1,b+1+len,cmp2);
		printf("%d\n",ans);
		for(int i=1;i<=n;i++)
		{
			printf("%d %d\n",b[i].id,b[len-i+1].id);
		}
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值