当前位置:网站首页>A. Difference Operations(思维)
A. Difference Operations(思维)
2022-07-19 14:15:00 【罗gkv】
题意
给定n个数,给定操作
选择2<=i<=n,令a[i]=a[i]-a[i-1]
问通过上述操作,能否使a[i]=0,2<=i<=n。
思路
观察发现,a[1]是其他元素的因子,才能满足题意。易证。
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 200010;
const int mod = 1e9 + 7;
int n;
int a[maxn];
void solve() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
bool flag = true;
for (int i = 1; i < n; ++i) {
if (a[i] % a[0]) {
flag = false;
break;
}
}
printf("%s\n", flag ? "YES" : "NO");
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
solve();
}
}
边栏推荐
- 网易云信音视频能力中台,全速助力银行业数字化转型升级
- LeetCode 数据库十道题解答
- 一道随机数题目的求解
- Feature Engineering -- numerical feature normalization
- 解决错误:npm install emojis-list失败
- 小程序毕设作品之微信预约订座小程序毕业设计(8)毕业设计论文模板
- Digital triangle (Luogu p1216) basic DP
- 建立动态规划状态转移方程的练习
- Taishan Office Technology Lecture: what are the concepts of height
- Introduction to several scenarios involving programming operation of Excel in SAP implementation project
猜你喜欢
随机推荐
建立动态规划状态转移方程的练习
XML 和 JSON
Camera摄像头特定应用杂谈
[opencv] record CV2 A hole in videocapture
算法---翻转数位(Kotlin)
Emeditor based corpus statistics and analysis
正则表达式
硅谷课堂第十二课-公众号点播课程和直播管理模块
Feature Engineering -- numerical feature normalization
[performance optimization] MySQL performance optimization storage engine tuning
基于Emeditor的语料库统计与分析
硅谷课堂第十四课-直播对接和微信分享
[FAQ] access the HMS core push service, and the server sends messages. Cause analysis and solutions of common error codes
泰山OFFICE技术讲座:以A4为例,页面结构是怎样的
泰山OFFICE技术讲座:有哪些关于高度的概念
服务器运维需要24小时在线吗?需要周末加班吗?
Taishan Office Technology Lecture: what are the concepts of height
数字三角形(洛谷P1216)基础dp
A page widgetization practice
小程序毕设作品之微信预约订座小程序毕业设计(6)开题答辩PPT