题目传送门

A 小W的病毒歼灭战

B 小田的三倍数

C 小田的省钱计划

D 计算表达式的值

E 永夜的报应

F 数学题2

T1 小W的病毒歼灭战

错的点

1.队列没写好,要加强代码熟练度

思路

用一个队列来统计弹夹,遇到没有的入队,容量满了就让第一个出队,注意换弹夹是要统计

代码

#include<bits/stdc++.h>
using namespace std;
int n,m,st[1111],q[111111],h=0,t=-1,j=0,x;
int main(){
	freopen("fyj.in","r",stdin);
	freopen("fyj.out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>x;
		if(st[x]==0){
			if(t-h+1==n){
				st[q[h]]--;
				h++;
			}
			j++;
			q[++t]=x;
			st[x]++;
		}
	}
	cout<<j;
	return 0;	
}

T2小田的三倍数

思路

众所周知,一个数要整除三,那么那个数各位之和,也要能整除三,所以这道题只用统计所有数各位之和在判断就行了

代码

#include<bits/stdc++.h>
using namespace std;
int main(){
	freopen("three.in","r",stdin);
	freopen("three.out","w",stdout);
	long long t;
	cin>>t;
	while(t--){
		long long n,j=0;
		cin>>n;
		for(long long i=1;i<=n;i++){
			string s;
			cin>>s;
			long long k=0;
			for(int j=0;j<s.size();j++){
				k+=(s[j]-'0')%3;
				k%=3;
			}
			j+=k;
			j%=3;
		}
		if(j==0)cout<<"Yes\n";
		else cout<<"No\n";
	}
}

T3小田的省钱计划

错的点

本来本题要用递推去写的,但用了双指针,要加强算法正确性

思路

主题思路就是递推,用双指针也可以,但麻烦,递归求最大价值不复杂,而且好想一些

代码

#include<bits/stdc++.h>
using namespace std;
long long a[100010],f[100010];
int main(){
	freopen("money.in","r",stdin);
	freopen("money.out","w",stdout);
	long long n,x,m=0;
	cin>>n>>x;
	for(long long i=1;i<=n;i++){
		cin>>a[i];
		a[i]-=x;
		if(f[i-1]<0)f[i]=a[i];
		else f[i]=f[i-1]+a[i];
		m=max(f[i],m);
	}
	cout<<m;
}

T4计算表达式的值

思路

套模板就行了!!!!!!!!!!(只用改权值和次方操作就可以了)

代码

#include<bits/stdc++.h>
using namespace std;
unordered_map<char,int>r{{'+',1},{'-',1},{'*',2},{'/',2},{'^',3}};
stack<char>fh;
stack<int>sz;
void e() {
	int b=sz.top();
	int x;
	sz.pop();
	int a=sz.top();
	sz.pop();
	char c=fh.top();
	fh.pop();
	if(c=='+')x=a+b;
	else if(c=='-')x=a-b;
	else if(c=='*')x=a*b;
	else if (c=='/')x=a/b;
	else{
		x=1;
		for(int i=1;i<=b;i++)x*=a;
	}
	sz.push(x);
}
int main() {
	freopen("bds.in","r",stdin);
	freopen("bds.out","w",stdout);
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		auto c=s[i];
		if(isdigit(c)) {
			int x=0,j=i;
			while(j<s.size()&&isdigit(s[j])){
				x=x*10+s[j]-'0';
				j++;
			}
			i=j-1,sz.push(x);
		}
		else if(c=='(')fh.push(c);
		else if(c==')'){
			while(fh.top()!='(')e();
			fh.pop();
		}
		else{
			while(fh.size()&&fh.top()!='('&&r[c]<=r[fh.top()])e();
			fh.push(c);
		}
	}
	while(fh.size())e();
	cout<<sz.top();
}

T5永夜的报应

错的点

没写

思路

a^b<=a+b 那么直接全异或

代码

#include<bits/stdc++.h>
using namespace std;
int n,s;
int main(){
	freopen("huiye.in","r",stdin);
	freopen("huiye.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		s^=x;
	}
	cout<<s;
}

T6数学题2

错的点

没写

思路

我们可以标记n的约数,然后再枚举1~n可行就输出

代码

#include<bits/stdc++.h>
using namespace std;
int n,a[100100],s[1000010],ma=-100000;
int main(){
	freopen("math2.in","r",stdin);
	freopen("math2.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){cin>>a[i];ma=max(ma,a[i]);}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=a[i]/j;j++){
			if(a[i]%j==0){
				if(j!=a[i]/j)s[a[i]/j]++,s[j]++;
				else s[j]++;
			}
		}
	}
	int j=ma;
	for(int i=1;i<=n;){
		if(s[j]>=i){cout<<j<<"\n";i++;}
		else j--;
	}
}