题意:有一个长度为\(n\)的数组,找一段最长子数组,使得其元素和为\(x\),如果存在,输出子数组的长度,否则输出\(-1\). 题解:这题我们要从元素和\(sum\)来考虑,首先,如果原数组的所有元素都被\(x\)整除,那么条件不成立. ​ 假如原数组的\(sum\)不被\(x\)整除,那么长度就为\(n\),如果被\(x\)整除,那么我们贪心来想,从前和从后来找第一个\(a[i]\)%\(x\ne0\)的位置,然后比较求个最长即可. 代码: #include <iostream> #in…
题目链接:https://codeforces.com/contest/1364/problem/A 题意 找出大小为 $n$ 的数组 $a$ 的最长连续子数组,其元素和不被 $x$ 整除. 题解 如果数组的每个元素都被 $x$ 整除,则不存在不被 $x$ 整除的子数组 如果整个数组之和不被 $x$ 整除,答案即为整个数组 如果整个数组之和被 $x$ 整除,删去最短的不被 $x$ 整除的一端子数组 代码 #include <bits/stdc++.h> using namespace std;…
Codeforces Round #649 (Div. 2) -- WKL \(\mathcal{A}\)题: \(\mathrm{XXXXX}\) Greedy implementation *1200 第一题,要求的是求一段子数组的区间和,要求该区间和不被\(x\)整除且长度尽可能长. 显然,对于这类题目可以想到以下几点: \(MOD\)的使用 贪心与构造 思路如下:定义数组为\(arr\).我们首先看\(\sum arr\)是否符合要求,假如符合显然这个是最长的.假如不符合呢?我们只需要从…
题意:有长度为\(n\)的数组\(a\),要求构造一个相同长度的数组\(b\),使得\({b_{1},b_{2},....b_{i}}\)集合中没有出现过的最小的数是\(a_{i}\). 题解:完全可以按照题意直接构造,但是比较麻烦,这里我们先标记原数组中的数,然后将原数组中没出现过的数存进\(b\)中(\(a\)中出现的数在\(b\)中不能出现在\(a\)位置之前),然后我们遍历原数组,如果\(a[i]\ne a[i-1]\),直接输出前一个数,否则输出\(b\)的队头. 构造题还是要自己多想…
A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A Description One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1…
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move…
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory limit per test 256 megabytes 问题描述 Manao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a play…
B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directio…
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/problem/A Description You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square r…
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Description Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera…