aba

林扬泉  •  2个月前


b

#include<bits/stdc++.h>
using namespace std;
const int N=3e4+10;
int n,m;
int s[N],g[N];
int res;
bool cmp(int x,int y){
	return x>y;
}
int main(){
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		scanf("%d",&g[i]);
	}
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&s[i]);
	}
	sort(s+1,s+n+1,cmp);
	sort(g+1,g+m+1,cmp);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(g[j]==-1){
				continue;
			}
			//printf("%d %d %d\n",res,g[j],s[i]);
			if(s[i]>=g[j]){
				g[j]=-1;
				res++;
				break;
			}
		}
	}
	printf("%d\n",res);
	return 0;
}
c
#include<bits/stdc++.h>

using namespace std; const int N=1e4+10; int n; int a[N]; int main(){

scanf("%d",&n);
for(int i=1;i<=n;i++){
	scanf("%d",&a[i]);
}
if(n<=2){
	printf("%d\n",n);
	return 0;
}
int res=1;
int u=1;
int d=2;
int s=0;
for(int i=2;i<=n;i++){
	if(i==2){
		if(a[i]>a[i-1]){
			s=d;
			res++;
		}
		else if(a[i]<a[i-1]){
			s=u;
			res++;
		}
	}
	else if(s==u){
		if(a[i]>a[i-1]){
			s=d;
			res++;
		}
	}
	else if(s==d){
		if(a[i]<a[i-1]){
			s=u;
			res++;
		}
	}
}
printf("%d\n",res);
return 0;

} d

include<bits/stdc++.h>

using namespace std; const int N=1e3+10; int p[N]; int n; int res; int main(){

scanf("%d",&n);
for(int i=1;i<=n;i++){
	scanf("%d",&p[i]);
}
for(int i=1;i<n;i++){
	if(p[i+1]-p[i]>0){
		res+=p[i+1]-p[i];
	}
}
printf("%d\n",res);
return 0;

} e

include<bits/stdc++.h>

using namespace std; const int N=1e3+10; int n,k; int a[N]; int main(){

scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
	scanf("%d",&a[i]);
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++){
	if(k<=0){
		break;
	}
	if(a[i]<0){
		a[i]=abs(a[i]);
		k--;
	}
	else{
		if(k>=2){
			k-=2;
		}
		else{
			a[i]=(-a[i]);
			k--;
		}
	}
}
int sum=0;
for(int i=1;i<=n;i++){
	sum+=a[i];
}
printf("%d\n",sum);
return 0;

} f

include<bits/stdc++.h>

using namespace std; const int N=1e4+10; int t[N]; string s; int x; int main(){

cin>>s;
int ma=0;
for(int i=0;i<s.size();i++){
	for(int j=i;j<s.size();j++){
		if(s[j]==s[i]){
			ma=max(ma,j);
		}
	}
	if(ma==i){
		t[++x]=ma;
	}
}
for(int i=1;i<=x;i++){
	if(i==1){
		printf("%d ",t[i]+1);
	}
	else{
		printf("%d ",t[i]-t[i-1]);
	}
}
printf("\n");
return 0;

}


评论: