小明种苹果(续)

试题编号: 201909-2
试题名称: 小明种苹果(续)
时间限制: 1.0s
内存限制: 512.0MB
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
题目解析:
明确一点,他可能在中间查看,不止查看一次,所以使用整型t的话,值不一定是1 。

代码:

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;  

int main(){
	int n , m , total , method;
	vector<int> vc;
	while(cin >> n){
		int sum = 0;
		for(int i = 0 ; i < n ; i++){
			int t = 0;        
			cin >> m >> total;         //本行数目 ,开始的总数     
			int rest = total;  
			int temp = 0;
			for(int j = 0 ; j < m - 1 ; j++){
				cin >> method;
				if(method <= 0){
					rest += method;
				}else{
					if(rest > method){
						rest = method;    //重新查看的总数 
						t++;             //是否掉落,掉落肯定 t>0 
					}
				}
			}
			vc.push_back(t);      //为了进行比较,找到e,e是连续三棵掉落 
			sum += rest;       //总数 
		}
		int e = 0;
		int t = 0;     //与上面的t不同,这个是掉落棵树,上面是一棵树,在查看中掉落几次 
		for(int i = 0; i < vc.size(); i++){
			if(vc[i] != 0){
				t++;
			}
			int two = (i + 1) % n;
			int three = (i + 2) % n;
			if(vc[i] != 0 && vc[two] != 0 && vc[three] != 0){
				e++;
			}
		}
		cout << sum << " " << t << " " << e << endl; 
		vc.clear();
	}
    return 0;
}

/*
5
4 10 0 9 0
4 10 -2 7 0
2 10 0
4 10 -3 5 0
4 10 -1 8 0

4
4 74 -7 -12 -5
5 73 -8 -6 59 -4
5 76 -5 -10 60 -2
5 80 -6 -15 59 0
*/

/* 第二次 

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<fstream>
//#include<regex>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;  

int main()
{
	int n , m , total , number;
	vector<int> vc;
	while(cin >> n){
		int rst = 0;
		while(n--){
			cin >> m >> total;
			bool flag = false;
			for(int i = 1 ; i < m ; i++){
				cin >> number;
				if(number <= 0){
					total += number;
				}else{
					if(total > number){
						flag = true;
					}
					total = number;
				}
			}
			rst += total;
			if(flag){
				vc.push_back(1);
			}else{
				vc.push_back(0);
			}
		}
		
		int d = 0 , e = 0 , count = vc.size();
		for(int i = 0 ; i < vc.size() ; i++){
			if(vc[i] == 1){
				d++;
			}
			if(vc[i % count] == 1 && vc[(i+1) % count] == 1 && vc[(i+2) % count] == 1){
				e++;
			}
		}
		cout << rst << " " << d << " " << e << endl;
		vc.clear();
	}
    return 0;
}

*/ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值