magical bamboo

本文探讨了一个有趣的数学问题:在魔法森林中,通过调整竹子高度来使所有竹子达到相同高度的可能性。提供了判断标准及简洁的代码实现。

In a magical forest, there exists N bamboos that don't quite get cut down the way you would expect.

Originally, the height of the ith bamboo is equal to hi. In one move, you can push down a bamboo and decrease its height by one, but this move magically causes all the other bamboos to increase in height by one.

If you can do as many moves as you like, is it possible to make all the bamboos have the same height?

Input

The first line of input is T – the number of test cases.

The first line of each test case contains an integer N (1 ≤ N ≤ 105) - the number of bamboos.

The second line contains N space-separated integers hi (1 ≤ hi ≤ 105) - the original heights of the bamboos.

Output

For each test case, output on a single line "yes” (without quotes), if you can make all the bamboos have the same height, and "no" otherwise.

Example
Input
2
3
2 4 2
2
1 2
Output
yes

no

想了好久好久的规律啊
终于出来了

就是只要任意两个竹子的高度相差为偶数或0即可 代码自然就简单喽

#include <cstdio>
#include <iostream>
#include <cstring>
#include  <queue>
#include <algorithm>
#include <map>
using namespace std;
///只要任意两数相差偶数就可以
int a[100005];
int main()
{
    int t;
    scanf("%d", &t);
    while( t-- )
    {
        memset( a,0, sizeof( a ));
        int n , i;
        scanf("%d", &n);
        for( i = 0; i<n; i++)
        {
            scanf("%d", &a[i]);
        }
        sort( a, a+n);
        int f = 1;
        for( i = 1; i<n; i++)
        {
            if( (a[i] - a[i-1])%2 != 0)
            {
                f = 0;
                printf("no\n");
                break;
            }
        }
        if( f== 1)
        {
            printf("yes\n");
        }
    }
}


### 关于编程和技术背景下的“Magical Formula” 在技术领域,“magical formula”通常指代一种能够显著提升效率、简化复杂流程或者解决特定问题的方法或工具。尽管这一术语并非严格定义的技术名词,但在某些上下文中可以被理解为某种算法、框架或设计理念。 #### 在.NET中的Code Generator或Template Engine视角下 当提到“.NET”的代码生成器或模板引擎时,“magical formula”可能指的是通过元编程(Metaprogramming)实现动态代码生成功能的核心逻辑[^1]。这种机制允许开发者基于预设规则自动生成大量重复性的代码片段,从而减少手动编码的工作量并提高开发速度。例如,在构建复杂的业务逻辑层时,可以通过配置文件自动创建数据访问对象(DAOs),这便是所谓的“魔法配方”。 #### 在机器学习项目管理方面 从另一个角度来看,在指导如何建立成功的机器学习项目的课程描述中并未直接提及“magical formula”,但如果将其隐喻化,则可认为是指定一套科学合理的规划方法论来引领团队完成高质量的人工智能解决方案开发过程[^2]。具体而言,它涵盖了需求分析、模型选择、训练评估以及部署优化等多个环节的最佳实践集合体。 以下是Python语言展示的一个简单例子用于说明自动化脚本编写过程中所运用到的一些基本原理: ```python def generate_code(template_string, variables_dict): """Generate code by replacing placeholders with actual values.""" result = template_string.format(**variables_dict) return result template = """ class {ClassName}: def __init__(self, value): self.value = value def get_value(self): return self.value * 2 """ data = {"ClassName": "Multiplier"} generated_class = generate_code(template, data) print(generated_class) ``` 上述代码展示了利用字符串替换功能来自动生成类定义的过程,这就是一种小型的“magic formula”。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值