Codeforces Round #780 (Div. 3) B题吃不同种类糖果

关于难得一遇div3的B都没做出来的反思

看清题!看清题!看清题!

我的思路是所有输入的数依次大减小,所得   剩余 > 1  即为肯定要连续吃同一种才能吃完

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{   int n;
    cin >> n;
    
    while(n --)
    {   LL k , xmax ,xmin;
        int flag = 0;
        cin >> k;
        cin >> xmax;
        if(k == 1&&xmax == 1) flag = 1;
		for(int i = 0;i < k - 1;i ++) 
		{
			cin >> xmin;
			if(xmin > xmax) swap(xmin , xmax);
			xmax -= xmin; 
		}
        if(xmax <= 1) flag = 1;
		if(flag) cout << "Yes" <<endl;
		else cout << "No" <<endl;
	}
	return 0;
 } 

但是!题上是{2 , 2} - >  {1 , 2}   ->   {1 , 1 } -> {0 , 1}  -> {0 , 0} 的次序

当出现 4

            4   2   1  1  的时候

我的思路判断是       

             4    2   1   1

           ------------------

             1    2

             3    4

             5         6

             7              8     是跟题目判定方式和结果不一样的

所以只判断最大和次大的才是  √  

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{   int n;
    cin >> n;
    
    while(n --)
    {    int mx = 0, nmx = 0;
        int k;
        cin >> k; 
        for (int i = 0; i < k; i++) {
    	int x;
    	cin >> x;
    	if (x > mx) {
    		nmx = mx;
    		mx = x;
    	} else if (x > nmx) {
    		nmx = x;
    	}
    }
 
    if (mx - nmx > 1) {
    	cout << "No\n";
    } else {
    	cout << "Yes\n";
    }
	}
	return 0;
 } 

就这一道简单思维题给我大半夜wa破防了,果然菜是原罪QAQ

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值