发送盒子给Alice(简单版本) 题意:准备n个盒子放巧克力,从1到n编号,初始的时候,第i个盒子有ai个巧克力. Bob是一个聪明的家伙,他不会送n个空盒子给Alice,换句话说,每个盒子里面都有巧克力. Alice不喜欢互质集,如果这里存在一个整数k > 1,每个盒子里的巧克力数量都能被k整除,那么Alice会很高兴. Alice不介意这里有空盒子. 每次操作可以把一个盒子里的巧克力放置在相邻两个盒子里,即第i个盒子里的巧克力可以放在第i + 1和i - 1盒子里. 如果这里没有方法使得Al…
题解: 保存每个1的位置.然后记录1的总个数cnt,如果存在一个k使得这个k是每个集合的倍数,那么为了使操作次数最小,这个k应该是cnt的质因子.(因为都是每个集合的数目1,使每个集合的数目变为2需要的次数一定小于使每个集合数目变为4需要的次数) 枚举cnt的质因子x,即x个1构成一个新的集合.构成新集合的时候要是两边的1往中间凑(中位数).剩下的就暴力... #include<bits/stdc++.h> using namespace std; typedef long long ll;…
#include <bits/stdc++.h> using namespace std; typedef long long ll; ; int a[N]; int n; bool prime(int x) {//判断是否为质数 ; i*i <= x; i++) { ) return false; } return true; } ll solve(int x) { vector<int>b; ll ans = ; ; i <= n; i++) { &&…
Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的一块巧克力左移或右移,要求移动后的每个盒子中的巧克力数量都能被k整除(无视空盒子),求最小的操作数.(1<=N<=1e6,0<=a[i]<=1e6) 题解 k只需考虑巧克力总数的质因子 考虑每个盒子的贡献,盒子中可以保存k的整数倍(k*i)块巧克力,从左向右递推,每个盒子保留最大数目的…
题意 n个数字的序列a,将i位置向j位置转移x个(a[i]-x,a[j]+x)的花费为\(x\times |i-j|\),最终状态可行的条件为所有a[i]均被K整除(K>1),求最小花费 做法 \(sum=\sum\limits a\),则\(K|sum\) 有\(K1|sum,K2|sum\),若\(K1|K2\),则转移到被K1整除比转移到K2更优.这个是显然的,所以最终可能成为最优解的K个数为\(logsum\le 40\) 对于一个枚举到的K,将\(b[i]=a[i]\% K\) 对于b…
秒的有点难以理解:https://blog.csdn.net/weixin_42868863/article/details/103200132 #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ; ll arr[N]; ll n; ll cal(ll x){ ll sum=,s=; ;i<=n;i++){ s=(s+arr[i])%x; sum+=min(s,x-s); } return sum;…
E. Send Boxes to Alice 首先求出每一个位置的前缀和. 对答案进行复杂度为\(\sqrt{a[n]}\)的遍历,因为最后的答案不可能大于\(\sqrt{a[n]}\) for(ll j=2;j*j<=a[n];++j) if(a[n]%j==0) { Try(j); while(a[n]%j==0) a[n]/=j; } 在Try(j)函数中,求的是当因子为\(j\)时的操作数量 void Try(ll k) { ll temp=0; for(int i=1;i<n;++i…
我们考虑前缀和sum[i],如果将a[i+1]中的一个塞入a[i]中,则不影响sum[i+1],但是sum[i]++,如果将a[i]中的一个塞入a[i+1],则不影响sum[i+1],但是sum[i]--,我们可以发现操作一次相当于将一个sum[i]+1或者到sum[i]-1,那么题意就变成了操作多少次可以使得所有的sum[i]为某一个k的倍数,那么一个sum[i]变成k的倍数操作次数最小必然为min(sum[i]%k,k-sum[i]%k),那么接下如何考虑k呢,显然k是sum[n]的一个因子…
E1. String Coloring (easy version) time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This is an easy version of the problem. The actual problems are different, but the easy version is almost…
http://codeforces.com/problemset/problem/1216/E1 E1. Numerical Sequence (easy version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The only difference between the easy and the hard ver…
B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to in…
3868 - Earthstone: Easy Version Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3867 Description Earthstone is a famous online card game created by Lizard Entertainment. It is a collectible card g…
题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j]$:以i为结尾选择j个数字的最大和. $dp[i][j]=max(dp[i][j],dp[s][j-1]+a[i])$,$s为区间[i-k,i)$. 以i为结尾的最大和可以由i之前k个位置中的其中一个位置选择j-1个,再加上当前位置的ai得到. #include <cstdio> #includ…
Problem UVA12569-Planning mobile robot on Tree (EASY Version) Accept:138  Submit:686 Time Limit: 3000 mSec  Problem Description  Input The first line contains the number of test cases T (T ≤ 340). Each test case begins with four integers n, m, s, t (…
Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions is the constraints. Polycarp has to write a coursewor…
1114 ModricWang's FFT EASY VERSION 思路 利用FFT做大整数乘法,实际上是把大整数变成多项式,然后做多项式乘法. 例如,对于\(1234\),改写成\(f(x)=1*x^3+2*x^2+3*x+4\),那么\(x=10\)处的值就是原数.类似的,对于输入的两个大整数,转换为\(f(x)\) 和\(g(x)\) ,利用FFT求出\(h(x)=f(x)*g(x)\) ,此时\(h(10)\) 就是乘积. 代码 #include <cstdio> #include…
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land…
任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an undirected tree of nn vertices. Some vert…
任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions…
F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n个数,以及k,x,k即长度为k的区间至少选一个,x的意思是一共要选x个,少一个或者多一个都不行. 选一个会得到一定的奖励,问在满足条件的前提下,最多得到多少的奖励. 题解: 简单版本数据量比较小,考虑比较暴力的动态规划. dp[i,j]表示前i个数,要选第i个数,目前选了j个所得到的最大奖励,那么当…
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was capture…
06-图2 Saving James Bond - Easy Version(25 分) This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land…
D1.Remove the Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The only difference between easy and hard versions is the length of the string. You are given a string…
B1. Character Swap (Easy Version) This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems. After struggling and failing many times, Ujan decided to tr…
CF1225B1 TV Subscriptions (Easy Version) 洛谷评测传送门 题目描述 The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the kk TV shows. You know the schedule for the next nn days: a seque…
G1 - Into Blocks (easy version) 参考:Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2) G1. Into Blocks (easy version) 思路:先把数据预处理一遍,找到每一种数的最右端的位置,和每一种数的出现的次数,然后,从第一个数字开始遍历,用r保存当前这一块的最大右端,用MAX…
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The only difference between easy and hard versions is the size of the input. You are given a string s consistin…
D1. Kirk and a Binary String (easy version) 01串找最长不降子序列 给定字符串s,要求生成一个等长字符串t,使得任意l到r位置的最长不降子序列长度一致 从后往前暴力枚举,枚举每个一替换成0后是否改变了l到r位置的最长不降子序列长度 01串的最长不降子序列,可以通过线性dp求解 dp i表示以i结尾的最长不降子序列长度 dp[0]=dp[0]+s[i]=='0'; dp[1]=max(dp[0],dp[1])+s[i]=='1'; #include<bi…
题目链接: C1. Skyscrapers (easy version) 题目描述: 有一行数,使得整个序列满足 先递增在递减(或者只递增,或者只递减) ,每个位置上的数可以改变,但是最大不能超过原来的值. 最后找到满足这样的序列并且满足 这种方案 所有数加起来 和 是最大的. 考察点 : 贪心,对数据范围的掌握程度,计算每次加数时有可能会 爆 int 析题得侃: 比赛的时候看到这道题直接找了 最大值,然后以最大值为中心向两侧递减,交了一发, WA 后来想到可能会有重复的最大值,因为每个值并不是…
Codeforce 1420 C1. Pokémon Army (easy version) 解析(DP) 今天我們來看看CF1420C1 題目連結 題目 對於一個數列\(a\),選若干個數字,求alternating-series的最大值. 前言 C2真的想不到 @copyright petjelinux 版權所有 觀看更多正版原始文章請至petjelinux的blog 想法 \(dp[i][0]\)代表:考慮到第i個數字為止,最後一個數字是負的的最大值 \(dp[i][1]\)代表:考慮到第…