当前位置:网站首页>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;
}
边栏推荐
- Is it safe to open an account on your mobile phone for small amount of stock speculation?
- qt--將程序打包--不要安裝qt-可以直接運行
- 跨模态语义关联对齐检索-图像文本匹配(Image-Text Matching)
- How to get the first and last days of a given month
- About snake equation (1)
- Different methods for setting headers of different pages in word (the same for footer and page number)
- Frequency probability and Bayesian probability
- ArrayList源码深度剖析,从最基本的扩容原理,到魔幻的迭代器和fast-fail机制,你想要的这都有!!!
- Getting started STM32 -- how to learn stm32
- AttributeError: ‘str‘ object has no attribute ‘strftime‘
猜你喜欢
QT build with built-in application framework -- Hello World -- use min GW 32bit
QT -- package the program -- don't install qt- you can run it directly
Js中forEach map无法跳出循环问题以及forEach会不会修改原数组
Guojingxin center "APEC investment +": some things about the Internet sector today | observation on stabilizing strategic industrial funds
Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
3. Multi agent reinforcement learning
Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method
Scalar / vector / matrix derivation method
qt-使用自带的应用框架建立--hello world--使用min GW 32bit
The combination of relay and led small night light realizes the control of small night light cycle on and off
随机推荐
GBASE观察 | 数据泄露频发 信息系统安全应如何守护
Kaptcha generates verification code on Web page
滑环在直驱电机转子的应用领域
4、策略学习
Redis集群
Frrouting BGP protocol learning
Matlab method is good~
The persistence mode of redis - RDB and AOF persistence mechanisms
写一个纯手写的qt的hello world
2021 welder (primary) examination skills and welder (primary) operation examination question bank
不算不知道,花呗分期的真实利率居然这么高
快速熟知XML解析
Coordinate conversion of one-dimensional array and two-dimensional matrix (storage of matrix)
Talk about smart Park
生态 | 湖仓一体的优选:GBase 8a MPP + XEOS
Leetcode exercise - Sword finger offer 36 Binary search tree and bidirectional linked list
NPM internal split module
Introduction to grpc for cloud native application development
Introduction to natural language processing (NLP) based on transformers
2022 examination for safety production management personnel of hazardous chemical production units and new version of examination questions for safety production management personnel of hazardous chem