首页 > 其他分享 >牛客练习赛100

牛客练习赛100

时间:2023-03-19 12:33:07浏览次数:47  
标签:typedef 练习赛 int LL 小红 牛客 Limit 100 include

牛客练习赛100

B.小红的子序列(dp)

题目链接

子序列问题一般是dp问题,这里结尾dp状态只有四种,蓝偶,红偶,蓝奇,红奇。对于当前物品,所要做的判断就是加与不加入状态完全相反的背包中,例如,当前是蓝色偶数,现在就要判断加不加到当前以红色奇数为结尾的数组中,状态方程:

f[c[i][a[i]&1]=max(f[c[i]][a[i]&1],f[1-c[i]][1-(a[i]&1)]+(LL)a[i]);

// Problem: 小红的子序列
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/11251/B
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long LL;
const int N=2e5+10;
int a[N],n;
string col;
int c[N];
LL f[2][2];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	cin>>col;
	for(int i=0;i<n;i++){
		c[i+1]=(col[i]=='R');
	}
	for(int i=1;i<=n;i++){
		f[c[i]][a[i]&1]=max(f[c[i]][a[i]&1],f[1-c[i]][1-(a[i]&1)]+(LL)a[i]);
	}
	LL ans=0;
	 for(int i=0;i<2;i++){
		 for(int j=0;j<2;j++){
			 ans=max(f[i][j],ans);
			 // cout<<f[i][j]<<" ";
			}
	}
	printf("%lld",ans);
	
	

	return 0;
}

C.小红的删数字

题目链接
先将

  • 数学题,博弈论,小红先手且要保证删去一个位数后还是3的倍数,假设所有位数之和为s,则必须删除一个sum%3的一位,否则肯定失败。
  • 接下来就是a[sum%3]--,问题转换为小紫先手了,此时如果a[1]和a[2]相等,且没有a[0]那么小红必胜
  • 否则就是小红必败
// Problem: 小红的删数字
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/11251/C
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long LL;
const int N=2e5+10;
int a[3];
int sum=0;
string s;
int main(){
	cin>>s;
	int len=s.length();
	for(int i=0;i<len;i++){
		if(s[i]-'0'){
			a[(s[i]-'0')%3]++;
		}
		sum+=s[i]-'0';
	}
	if(!a[sum%3]) puts("yukari");
	else{
		a[sum%3]--;
		if(a[1]==a[2]&&a[0]) puts("kou");
		else puts("yukari");
	}

	return 0;
}


D. 小红的构造题

题目链接
考虑数列re……re……re……re…………
对于每个在第k个re后添加一个d,那么共添加 \(\sum_{i=1}^k\)x*i(i+1)/2 个子序列,将上列式子化简可得k个re总共可有x*k(k+1)*(k+2)个red子序列,其中x为添加几个d
这样枚举复杂度降到了n1/3 可以枚举(但是有个疑问怎么证明这样可以包含所有整数呢?)

// Problem: 小红的构造题
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/11251/D
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long LL;
const int N=2e5+10;
LL n;
LL ned[N];
int main(){
	cin>>n;
// 	if(!n) {puts("d"); return 0;}
	LL i,j;
	for(i=1;i*i*i/6<=n;i++);
	i--;
	for(j=i;j>0;j--){
		ned[j]+=n/(j*(j+1)/2);
		n%=j*(j+1)/2;//剩余还要构造的字符串数量
	}
	for(j=1;j<=i;j++){
		cout<<"re";
		while(ned[j]--){
			cout<<"d";
		}
	}

	return 0;
}


标签:typedef,练习赛,int,LL,小红,牛客,Limit,100,include
From: https://www.cnblogs.com/viewoverlooking/p/17232832.html

相关文章

  • 打印100~999之间三位数每一位的积等于每一位的和的数字以及这些数的总数
    打印100~999之间三位数每一位(个十百)的积等于每一位(个十百)的和的数字以及这些数的总数首先需要一个循环,遍历所有的三位数,即100~999for(inti=100;i<1000;i++)......
  • 100道python基础题——(8)
    问题:编写一个程序,接受逗号分隔的单词序列作为输入,按字母顺序排序后按逗号分隔的序列打印单词。假设向程序提供以下输入:without,hello,bag,world则输出为:bag,hello,witho......
  • 100道python基础题——(9)
    多组输入问题:编写一个程序,接受一行序列作为输入,并在将句子中的所有字符大写后打印行。假设向程序提供以下输入:HelloworldPracticemakesperfect则输出为:HELLOWORLDP......
  • 牛客项目——说说你是如何实现敏感词过滤的?
    面试官:说说你是如何实现敏感词过滤的?敏感词过滤我采用的是前缀树的数据结构,前缀树又叫字典树、查找树,它的根节点不存储信息,其他的每个节点只存储一个字符,有查找效率高的......
  • 100道python基础题——(7)
    问题:编写一个程序,以2位数字,X,Y作为输入,生成一个二维数组。数组的第i行和第j列中的元素值应该是i*j。注意:i=0,1..,X-1;j=0,1,­Y-1。例子假设程序有以下输入:......
  • 100道python基础题——(6)
    编写一个程序,根据给定的公式计算并打印值:。以下是C和H的固定值:C是50。H是30。D是一个变量,它的值应该以逗号分隔的序列输入到程序中。例子假设程序的输入序列是逗号分隔的......
  • 100道python基础题——(5)
    Python简明教程---20,Python类中的属性与方法-码农充电站-博客园(cnblogs.com)问题:定义一个至少有两个方法的类:    getString:从控制台输入获取字符串......
  • 图片分割100块点击消除,再次点击出现
    第一步:创建一个web项目,本地导入vue.js  第二步:实例化vue对象    第三步:利用photoshop将图片分割成10*10,导入img文件夹下,并在vue的data属性下创建一个图片路......
  • 100Wqps异地多活,得物是怎么架构的?
    文章持续更新,建议收藏起来,慢慢读!疯狂创客圈总目录博客园版为您奉上珍贵的学习资源:免费赠送:《尼恩Java面试宝典》持续更新+史上最全+面试必备2000页+面试必备+......
  • LeetCode 1005.K 次取反后最大化的数组和
    题目描述:给你一个整数数组nums和一个整数k,按以下方法修改该数组:选择某个下标i并将nums[i]替换为-nums[i]。重复这个过程恰好k次。可以多次选择同一个下......