CSP

csp小明种苹果(续)问题

60分,我实在看不出原因,有没有大佬求教

#include<iostream>
using namespace std;
int main(){
int N,T=0,D=0,E;
cin>>N;
int Dtree[1001];//记录掉落树编号 
//初始化
int tree0,trees,tempT=0,flag=0;
for(int j=0;j<N;j++){
  cin>>tree0;
   flag=0;
  for(int i=1;i<=tree0;i++){
        cin>>trees;  
		if(i==1)
		 {
		 	tempT=trees;
		 	continue;
		 }
	    if(trees>0&&tempT>trees){			
			 tempT=trees;
			 if(flag==0)
			 {
			    Dtree[D++]=j;//(发生了重复记录的情况,只考虑到一次掉落)
			    flag=1;
			 }	
		}
		else if(trees<0)
		  tempT+=trees;
 }
 T+=tempT;
} 
//统计连续三颗掉落的组数
int temp,times=0,j;
 if(D <3)
  E=0;
else if(D==3){//当D为3时 ,注意值的集合是不可以重复的 
     if(N==3)
	    E=1;
	 else{
	 	temp=Dtree[0];
       	int i=1;
          for(;i<D;i++){
 	    	if(temp+1!=Dtree[i])
  		    break;
 		    temp=Dtree[i];
	  }
	    if(i==2)
	        E=1;
	    else E=0;
	 } 

  }
 else{
 	for(int i=0;i<D;i++) {
 	cout<<Dtree[i]<<" ";
	 }
	 cout<<endl;
	for(int i=0;i<D;i++) {
		temp=Dtree[i];		 
		j=(i+1)%(D);	//注意不要改变i的值 
		while((temp+1)%(N)==Dtree[j]){//D和N之间 
			times++;
            temp=Dtree[j];
			if(times==2)
			{
				times=0;
				E++;
				break;
			}
			j++;
			if(D <=j)
		       j=j%(D);
			
		}
	}
}
cout<<T<<" "<<D <<" "<<E<<endl;
 return 0;
} 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值