Ccodeforces2

兄弟们,这个codeforces(Div-2)是真的难啊!!!!!

我服了!!!!!

兄弟们,展示一下答案错误百分之20和百分之30的代码吧

第一题:

 

 

 

代码是这样的:

答案错误30%

#include<iostream>
using namespace std;
const int N=1e5+10;
int T,n,a[N];
int main(){
	cin>>T;
	for(int t=1;t<=T;t++){
		bool flag=true;
		int cnt=0;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			if(a[i]==i){
				flag=false;
			}
		}
		if(flag){
			cout<<0<<"\n";
			continue;
		}
		else{
			int i=1,j=n;
			while(i<=j){
				if(i==j){
					if(a[i]==i){
						swap(a[i],a[1]);
						cnt++;
					}
				}
				if(a[i]==i&&a[j]==j){
					swap(a[i],a[j]);
					cnt++;
					i++,j--;
				} else if(a[i]==i&&a[j]!=j){
					j--;
				} else if(a[i]!=i&&a[j]==j){
					i++;
				} else if(a[i]!=i&&a[j]!=j){
					i++,j--;
				} 
			}
		}
		cout<<cnt<<"\n";
	}
	return 0;
} 

 第四题(剩下的题都没看懂):

 

 

代码是这样的:

答案错误20%

#include<iostream>
using namespace std;
const int N=1e5+10;
int n,a[N];
bool vis[N];
int main(){
	int sum=0,cnt=0;
	cin>>n;
	vis[1]=1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=2;i<=n;i++){
		vis[i]=0;
	}
	while(!vis[n]){
		for(int i=1;i<=n;i++){
			if(!vis[i]){
				cnt++;
			}
		}
		for(int i=1;i<=n;i++){
			if(!vis[i]){
				if(cnt<a[i]){
					sum+=a[i];
					for(int j=1;j<=n;j++){
						vis[j]=1;
					}
				} else{
					sum+=a[i];
				}
			}
		}
	}
	cout<<sum<<"\n";
	return 0;
}

 行了,那个codeforces的朋友关注我一下,我也会回关,关注ta,OK了,感兴趣的可以参加比赛

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值