E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who wil…
题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard output 问题描述 The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tour…
题目传送门 https://codeforces.com/contest/1103/problem/D 题解 失去信仰的低水平选手的看题解的心路历程. 一开始看题目以为是选出一些数,每个数可以除掉一个不超过 \(k\) 的因数,使得被选出这些数的 \(\gcd\) 为 \(1\). 错的有点离谱.然后想了半天,想了一个奇怪的思路结果没有任何优化空间(因为选择的数不固定无法直接确定所有的质因子). 然后就开始看题解(事实上就算我没看错题目肯定也不会做). 以下为搬运题解内容. 我们可以先求出初始的…
题意: 有\(n(n \leq 18)\)个人打擂台赛,编号从\(1\)到\(n\),主角是\(1\)号. 一开始主角先选一个擂主,和一个打擂的人. 两个人之中胜的人留下来当擂主等主角决定下一个人打擂,败的人退出比赛,直到比赛只剩一个人. 已知任意两人之间决胜的胜率\(P_{ij}\),求主角最终能够获胜的概率. 分析: 设\(d(S, i)\)表示存活的人的集合为\(S\),当前擂主为\(i \in S\),主角获胜的概率. 为了方便我们把编号设为\(0 \sim n-1\),递推边界\(d(…
题意:给你一个长度为n的序列 问你需要多少次两两交换 可以让相同的数字在一个区间段 思路:我们可以预处理一个数组cnt[i][j]表示把i放到j前面需要交换多少次 然后二进制枚举后 每次选择一个为1的位置 考虑这个位置最后加进来的花费取最小 #include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int N = 4e5+7; typedef…
题目链接: http://codeforces.com/problemset/problem/8/C C. Looking for Order time limit per test:4 secondsmemory limit per test:512 megabytes 问题描述 Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready f…
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Robots are becoming more and more popular. They are used nowadays not only in manufacturing plants, but also at home. One programmer wit…
[多校联考2019(Round 5)] [ATCoder3912]Xor Tree(状压dp) 题面 给出一棵n个点的树,每条边有边权v,每次操作选中两个点,将这两个点之间的路径上的边权全部异或某个值,求使得最终所有边权为0的最小操作次数. \(v \leq 15,n \leq 10^5\) 分析 首先把边权转化为点权.记一个点的点权为与它相连的所有边的边权和.当我们给一条路径上的边异或上某个值时,路径端点的点权被异或了1次,而路径上不是端点的点有两条边被异或了,相当于异或了2次,权值不变.因此…
Codeforces 题目传送门 & 洛谷题目传送门 还是做题做太少了啊--碰到这种题一点感觉都没有-- 首先我们来证明一件事情,那就是存在一种合并方式 \(\Leftrightarrow\) \(\exist b_i\in\mathbb{Z}^+,\sum\limits_{i=1}^na_ik^{-b_i}=1\) 考虑充分性,倘若我们已经知道了 \(b_1,b_2,\dots,b_n\) 的值怎样构造合并的序列,考虑 \(B=\max\limits_{i=1}^nb_i\),这里有一个结论,…
http://codeforces.com/contest/678 A:水题 #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define C 0.5772156649 #define ls l,m,rt<…
http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, nand x find the value of g(n)(x) mod…
题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h> using namespace std; typedef __int64 LL; struct data { LL mat[][]; }; LL mod = 1e9 + ; data operator *(data a , data b) { data res; ; i <= ; ++i) { ;…
D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find t…
C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern. An unpainted tile should be painted R…
B. The Same Calendar 题目连接: http://www.codeforces.com/contest/678/problem/B Description The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday,…
A. Johny Likes Numbers 题目连接: http://www.codeforces.com/contest/678/problem/A Description Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. Input The only line con…
A. Johny Likes Numbers time limit per test 0.5 seconds memory limit per test 256 megabytes input standard input output standard output Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divi…
Description Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. Input The only line contains two integers n and k (1 ≤ n, k ≤ 109). Output Print the smallest intege…
Description Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted B…
Description The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know wh…
  D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For…
D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x))for n > 0. For the…
题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间看作整体,按照R从小到大排序.然后从最小的R开始枚举每个区间,要是枚举到这个区间L的时候,计算之前枚举的区间有多少个Li在L之后,那么这些Li大于L的区间的数量就是答案.那我每次枚举的时候用树状数组add(L , 1) 说明在L这个位置上出现了区间,之后枚举的时候计算L之前的和,然后i - 1 -…
https://codeforces.com/contest/1101/problem/D 题意 一颗n个点的树,找出一条gcd>1的最长链,输出长度 题解 容易想到从自底向长转移 因为只需要gcd>1即可,所以定义\(dp[u][i]\)为u的子树中和u相连的gcd含有i的最长链长度,i为素因子 这样对于每个点u,维护\(dp[u][i]\),用两条最长子链和u构成的链更新答案即可 代码 #include<bits/stdc++.h> #define MAXN 200005 us…
https://codeforces.com/contest/1107/problem/E 题意 给出01字符串s(n<=100),相邻且相同的字符可以同时消去,一次性消去i个字符的分数是\(a[i]\),问消去s最多能得到多少分数 题解 实质是安排消去次序使得分数最大,第一步采取的行动是递归边界 因为只有01串,所以s被分成了一段一段,考虑段处理 预处理出一次性消去i个字符的最大分数\(f[i]\) 定义\(dp[l][r][cnt]\)为消去第l到第r段加上cnt个字符和第l段相同得到的最大…
#include<bits/stdc++.h>using namespace std;const long long mod=998244353;long long f[200007][2],g[200007][2];long long a[200007],b[200007],c[200007];int n,k,cnt1,cnt2;long long qpow(long long a,long long p){    long long ans=1;    while(p){        i…
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],t[]; int n,m; ][];//nex[i][j]表示i位置以字母j+'a'最先出现的位置 ][];//把t分割为t1和t2,dp[i][j]表示t1长度为i,t2长度为j时,在字符串s中的最小位置 int check(int x){ int y=m-x; dp[][]=; ;i<=x;++i) ;j<=y;++j){ &a…
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ; ][],temp[][]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m; cin>>n>>m; ;i<=n;++i){ pre[][i]=; temp[][i]=; } ;i<=m;++i)//…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long a[300007],b[300007];long long dp[300007][5];long long ans;int main(){ ios::sync_with_stdio(false);//多组数据输入cin,cout容易超时 cin.tie(NULL); cout.tie(NULL); int q; cin>>…
#include<bits/stdc++.h>using namespace std;int a[300007];long long sum[300007],tmp[300007],mx[300007];int main(){ int n,m,k; cin>>n>>m>>k; for(int i=1;i<=n;++i){ cin>>a[i]; sum[i]=sum[i-1]+a[i];//前缀和 } long long ans=0; for…