当前位置:网站首页>Codeforces Round #649 (Div. 2)——A. XXXXX
Codeforces Round #649 (Div. 2)——A. XXXXX
2022-07-08 00:02:00 【非长】
题目链接:https://codeforces.com/problemset/problem/1364/A
题目描述: 在只能删除数据串首尾的情况下,求最长的,不能被x整除的子串的长度。
解题思路: 贪心(在输入过程中,当总和不能被x整除时,取子串长度进行比较更新( l = max( l,max( i,n - i )))i为左边首长度(类似删除了右边数字),n-i为右边尾长度(类似删除了左边数字)。
代码:
#include<iostream>
#include<algorithm>
using namespace std;
int num[100005];
int main()
{
int t;
cin >> t;
while (t--)
{
int n, x;
cin >> n >> x;
int l = -1, sum = 0;
for (int i = 1; i <= n; i++)
{
cin >> num[i];
sum += num[i];
if (sum % x)
l = max(l, max(i, n - i));
}
cout << l << endl;
}
return 0;
}
边栏推荐
- 2021 tea master (primary) examination materials and tea master (primary) simulation test questions
- 5. Discrete control and continuous control
- The beauty of Mathematics -- the principle of fine Fourier transform
- About how USRP sets the sampling frequency below the minimum sampling frequency reached by the hardware
- 用户之声 | 冬去春来,静待花开 ——浅谈GBase 8a学习感悟
- Tapdata 的 2.0 版 ,開源的 Live Data Platform 現已發布
- 子矩阵的和
- Kaptcha generates verification code on Web page
- 2021-03-14 - play with generics
- COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况----几何模型的建立
猜你喜欢
3. Multi agent reinforcement learning
LeetCode 练习——剑指 Offer 36. 二叉搜索树与双向链表
子矩阵的和
2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
Running OFDM in gnuradio_ RX error: gr:: Log: info: packet_ headerparser_ b0 - Detected an invalid packet at item ××
Probability distribution
从cmath文件看名字是怎样被添加到命名空间std中的
Leetcode exercise - Sword finger offer 36 Binary search tree and bidirectional linked list
Gnuradio 3.9 using OOT custom module problem record
Qt - - Packaging Programs - - Don't install Qt - can run directly
随机推荐
Euler Lagrange equation
Android 创建的sqlite3数据存放位置
About how USRP sets the sampling frequency below the minimum sampling frequency reached by the hardware
Understanding of sidelobe cancellation
nacos-微服务网关Gateway组件 +Swagger2接口生成
common commands
COMSOL----微阻梁模型的搭建---最终的温度分布和变形情况----几何模型的建立
Redux使用
小金额炒股,在手机上开户安全吗?
Understanding of maximum likelihood estimation
2022 safety officer-b certificate examination question bank and safety officer-b certificate simulation test questions
2022 operation certificate examination for main principals of hazardous chemical business units and main principals of hazardous chemical business units
5、離散控制與連續控制
Transportation, new infrastructure and smart highway
About snake equation (2)
Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method
Running OFDM in gnuradio_ RX error: gr:: Log: info: packet_ headerparser_ b0 - Detected an invalid packet at item ××
Mat file usage
2021-03-14 - play with generics
Getting started STM32 -- how to learn stm32