You are given nn integer numbers a1,a2,…,ana1,a2,…,an. Consider graph on nn nodes, in which nodes ii, jj (i≠ji≠j) are connected if and only if, aiaiAND aj≠0aj≠0, where AND denotes the bitwise AND operation. Find the length of the shortest cycle in th…
https://codeforces.com/contest/1061/problem/E 题意 有n个点(<=500),标记第i个点的代价a[i],然后分别在这n个点建两棵树,对于每颗树的每个点来说,都有一个p[i],代表他的子树中被标记的点的个数需要等于p[i],请你选择需要标记的点,使得可以满足上述两棵树的要求,并且使得代价最大,输出最大的代价或者-1(不存在) 思路 这道题难在建图 首先考虑子树问题,是否选择每个节点对他的子孙节点没有影响,但是对他自身及其祖先节点有影响,注意p[i]=0…
D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy…
Codeforces Round #523 (Div. 2) 题目一览表 来源 考察知识点 完成时间 A Coins cf 贪心(签到题) 2018.11.23 B Views Matter cf 思维??? 2018.11.24 C Multiplicity cf dp 2018.11.27 D TV Shows cf 贪心+multiset 2018.12.2…
Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一种题目类型一种题目类型只能出现在一天每天的题目类型不能相同,而且后一天的题目数量必须正好为前一天的两倍,第一天的题目数量是任意的求怎么安排能使题目尽量多.注意:不是天数尽量多 思路: 首先我们知道一件事,题目属于哪种类型并不重要,重要的是每种类型的个数所以我们先统计出所有类型的个数,存进一个数组,而…
https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每次询问,a,b,c三个点,会返回b是否在a,c之间的路径上 思路 粗略看了下询问次数,可以知道,你最多可以询问60对不同的点,每对点遍历n个点,可以知道n个点在不在这两个点的中间 一开始的思路是,随机找两个点,遍历所有点,然后记录在他们中间的点,在里面再找两个点,继续上述操作,知道剩下一个点,但是假设某一…
A. Coins Water. #include <bits/stdc++.h> using namespace std; int n, s; int main() { while (scanf("%d%d", &n, &s) != EOF) { ; ; --i) while (s >= i) { ++res; s -= i; } printf("%d\n", res); } ; } B. Views Matter Solved.…
题:https://codeforces.com/contest/1061/problem/C 题意:给你一个序列,我们求他们子序列的个数,这个子序列有个限制就是每一个子序列上的值都必须是能整除他的下标,问有多少个 分析:考虑dp,我们先考虑二维的dp,定义dp[i][j]表示前i个数中,能从中提取出j个”好“序列,所以dp[i][j]就可以从dp[i-1][j-1]+dp[i-1][j]得来(前提是a[i]%j==0).显然a[i]%j!=0时dp[i][j]=dp[i-1][j] 但这样写会…
题意:给出n个电视节目的起始和结束时间  并且租一台电视需要x +y*(b-a)  [a,b]为时段 问完整看完电视节目的最小花费是多少 思路:贪心的思想 情况1 如果新租一台电视的花费<=在空闲电视上面看节目 那么肯定新租电视 情况2 否则就直接在空闲电视上看 就好 模拟难(QAQ): 这里使用多重集合模拟   先把所有时间的pair(结束时间,开始时间) 放入多重集里面 然后开一个数组以l 从小到大排序 从数组小到大 枚举  在多重集里面找离终点最近的那个点 如果符合情况1 那么就删去 找到…
传送门 https://www.cnblogs.com/violet-acmer/p/10005351.html 题意: 有n个节目,每个节目都有个开始时间和结束时间. 定义x,y分别为租电视需要的花费和看电视需要的花费(应该是花的电费,哈哈). 加入某电视节目的播放区间是[a,b],那么看完这个节目需要的总花费为x+(b-a)*y. 如果有其他节目的播放区间是[b,c],那么便不能和[a,b]的节目用同一个电视看. 求看完所有电视节目所需要的最少花费. 题解: 这应该是道贪心题. 对于每个节目…
传送门 https://www.cnblogs.com/violet-acmer/p/10005351.html 这是一道贪心题么???? 题意: 某展览馆展览一个物品,此物品有n堆,第 i 堆有a[ i ]个正方块,问最多可以去除多少个正方块,使得其俯视图与右视图的保持不变. 并且去除某正方块a下方的正方块时,是不会导致a方块下降的(无重力). 题解: 相关变量解释: int n,m; ll sum;//所有的方块 int a[maxn];//a[i] : 第i堆有a[i]个正方块 int i…
传送门 https://www.cnblogs.com/violet-acmer/p/10005351.html 题意: 给定一数组a[],从a[ ]中除去任意个元素得到b[ ],求能形成多少“好序列”: 好序列的定义是:对于任意的 i 有 b[i]%i == 0(1 ≤ i ≤ size_b[ ]). 题解: 相关变量解释: int n; int a[maxn]; int dp[maxn];//dp[i] : 下标i处可以获得的最大的"好序列" int factor[maxn];//…
C. Multiplicity 题目链接:https://codeforc.es/contest/1061/problem/C 题意: 给出一串数,问它的“好序列“有多少.好序列的定义是,首先是一个子序列(顺序可以打乱),其次,序列相应位置的数可以除尽该位置编号. 题解:这题是dp,我没有想到,主要是状态的定义. 定义dp(i,j):在a1,a2...ai中长度为j的好序列的个数,这样dp转移方程就为:if ai%j==0:  dp(i,j)=dp(i-1,j-1)+dp(i-1,j)  , e…
A. Coins 题目链接:https://codeforc.es/contest/1061/problem/A 题意: 给出n和s,要在1-n中选数(可重复),问最少选多少数可以使其和为s. 题解: 贪心就行了. 代码如下: #include <cstdio> #include <algorithm> #include <iostream> using namespace std; int main(){ int a,s; cin>>a>>s;…
#include<bits/stdc++.h>using namespace std;const long long N=1e5+5;const long long MOD=1e9+7;long long n,x,y,ans=0;long long cost[N];pair<long long,long long>a[N];multiset<pair<pair<long long,long long>,long long> >s;int main…
#include<bits/stdc++.h>using namespace std;long long a[100007];long long dp[1000007];const int mod=1e9+7;int main(){    int n;    scanf("%d",&n);    dp[0]=1;    for(int i=1;i<=n;i++)        scanf("%lld",&a[i]);    for(…
https://codeforces.com/contest/1139/problem/F 题意 有m个人,n道菜,每道菜有\(p_i\),\(s_i\),\(b_i\),每个人有\(inc_j\),\(pref_j\),一个人可以买一道菜的条件是 1. \(p_i \leq inc_j \leq s_i\) 2. \(|b_i - pref_j| \leq inc_j-p_i\) ,问每个人分别能买多少道菜 题解 转化一下公式 \(p_i \leq inc_j \leq s_i\) 下面两个满…
传送门 D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Finally it is a day when Arthur has enough money for buying an apartment. He found a great option close to the cente…
链接: https://codeforces.com/contest/1230/problem/C 题意: Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1≤a≤b≤6, there is exactly one domino with a dots on one half and b dots on th…
题目链接:https://codeforces.com/contest/1417/problem/C 题意 给出一个大小为 $n$ 的数组 $a$,计算当 $k$ 从 $1$ 到 $n$ 取值时在所有 $k$ 长区间中出现的数的最小值. 题解 记录一个值两两间的最大距离,该距离的 $k$ 长区间及之后更长的区间都可能以该值为最小值. Tips 注意两端的处理. 代码一 #include <bits/stdc++.h> using namespace std; int main() { ios:…
The link to problem:Problem - D - Codeforces   D. Range and Partition  time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Given an array a of n integers, find a range of values [x,y] (x≤y…
C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is…
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the c…
#include<bits/stdc++.h>using namespace std;int a[300007],b[500007],c[500007];set<int>st[300007];vector<int>v;int main(){    int n,m;    scanf("%d%d",&n,&m);    for(int i=1;i<=n;i++){        scanf("%d",&…
#include<bits/stdc++.h>using namespace std;int a[1007][1007];pair<int,int>p1[1007],p2[1007];int rk1[1007][1007],rk2[1007][1007],no1[1007][1007],no2[1007][1007];int main(){    int n,m;    scanf("%d%d",&n,&m);    for(int i=1;i&…
#include<bits/stdc++.h>using namespace std;int a[200007];stack<int>s;int main(){    int n;    int mn=0;    scanf("%d",&n);    for(int i=1;i<=n;i++){        scanf("%d",&a[i]);        if(a[i]>mn)            mn=a…
题意 给你N个数字和一个K,问一共有几种拼接数字的方式使得到的数字是K的倍数,拼接:“234”和“123”拼接得到“234123” 分析: N <= 2e5,简单的暴力O(N^2)枚举肯定超时 数字A和B拼接,B的位数最多10位,如果我们知道位数为(1-10)的数字和A拼接满足是K的倍数这样的数字有几个,就可以在N*10的复杂度下完成所有的拼接 在读入数据的时候,我们可以统计出数字的位数和对K取余的结果,这样我们就可以在O(1)的时间内得到所有满足的情况 #include<bits/stdc+…
沿时间轴枚举,发现关键时间点在于新题目被锁定的前一时间,那是新的题目还没有被锁定并且距离旧的题目已经被锁定的最晚时间,对这些时间点进行操作 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; typedef struct node{ int flag,s; }; node c[]; bool cmp(node x,node y){ if(x.s!=y.s) return x.s<y.s; re…
#include<bits/stdc++.h>using namespace std;char s[200007],t[200007];int last[200007][27],nxt[200007][27];int l[200007],r[200007];int main(){ cin>>s+1>>t+1; int n=strlen(s+1); int m=strlen(t+1); for(int i=1;i<=n;++i){ for(int j=0;j<…