codeforces 596
C
题意
定义p-binary为2^x+p
现在给你一个数x,和一个p。
问你最少用多少个p-binary能构造出x,如果没有输出-1
题解
转化为:
x = 2^x1 + 2^x2 + ... + 2^xn + n*p
首先我们知道任何数都能用二进制表示,如果p=0的话,肯定是有解的。那么答案最少都是x的2进制1的个数。
另外什么情况无解呢,即x-n*p<0的时候肯定无解,可以更加有优化为x-n*p<n的时候无解。
答案实际上就是n,我们从小到大枚举n,然后check现在的2进制中1的个数是否小于等于n。
#include<bits/stdc++.h>
using namespace std; int Count(int x){
int number=0;
for(;x;x-=x&-x){
number++;
}
return number;
}
int main(){
int n,p,ans=0;
scanf("%d%d",&n,&p);
while(1){
n-=p;
ans++;
int cnt=Count(n);
if(ans>n){
cout<<"-1"<<endl;
return 0;
}
if(cnt<=ans){
cout<<ans<<endl;
return 0;
}
}
}
D
You are given n positive integers a1,…,an, and an integer k≥2. Count the number of pairs i,j such that 1≤i<j≤n, and there exists an integer x such that ai⋅aj=xk.
In the sample case, the suitable pairs are:
a1⋅a4=8=2^3;
a1⋅a6=1=1^3;
a2⋅a3=27=3^3;
a3⋅a5=216=6^3;
a4⋅a6=8=2^3.
题意
题目这么短,我就偷懒不翻译了吧。。
题解
首先我们质因数分解后,如果两个数的质因数分解后的每个数的因子个数都是k的倍数,那么就说明有解。
于是我们先对每个数质因数分解一下,然后再用一个vector去找一下配对的那一个是哪个。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,k;
int a[maxn];
map<vector<pair<int,int> >,int>H;
int main(){
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
long long ans = 0;
for(int i=0;i<n;i++){
string tmp="";
vector<pair<int,int> >fac;
for(int now=2;now*now<=a[i];now++){
int number=0;
while(a[i]%now==0){
a[i]/=now;
number+=1;
}
if(number%k)
fac.push_back(make_pair(now,number%k));
}
if(a[i]>1)fac.push_back(make_pair(a[i],1%k));
vector<pair<int,int> >fac2;
for(int j=0;j<fac.size();j++){
fac2.push_back(make_pair(fac[j].first,k-fac[j].second));
}
ans+=H[fac2];
H[fac]++;///类似前缀的方式可以避免重复选到以下情况【ai,aj】【aj,ai】;
}
cout<<ans<<endl;
}
codeforces 596的更多相关文章
- codeforces 596 C. p-binary
题意:给你一个n和一个p,让你用 (2k+p)进制来表示n,找出用最少的(2k+p)来表示n. 分析:首先我们看到2k,首先下想到二进制,我们可以我们列出式子,也就是 (2x1 + p)+(2x2 + ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)
A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products
链接: https://codeforces.com/contest/1247/problem/D 题意: You are given n positive integers a1,-,an, and ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C. p-binary
链接: https://codeforces.com/contest/1247/problem/C 题意: Vasya will fancy any number as long as it is a ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B2. TV Subscriptions (Hard Version)
链接: https://codeforces.com/contest/1247/problem/B2 题意: The only difference between easy and hard ver ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) A. Forgetting Things
链接: https://codeforces.com/contest/1247/problem/A 题意: Kolya is very absent-minded. Today his math te ...
- Codeforces Round 596 题解
万幸的是终于碰上了一场上分好场. 不幸的是一开始差点不会 A. 万幸的是想了个不那么稳的结论过了 pretest. 不幸的是罚时很高,而且慌得一比. 万幸的是然后半个小时内把 B 和 C 码了. 不幸 ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) F. Tree Factory 构造题
F. Tree Factory Bytelandian Tree Factory produces trees for all kinds of industrial applications. Yo ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) E. Rock Is Push dp
E. Rock Is Push You are at the top left cell (1,1) of an n×m labyrinth. Your goal is to get to the b ...
随机推荐
- CCCC L2-004. 这是二叉搜索树吗?
题意: 一棵二叉搜索树可被递归地定义为具有下列性质的二叉树:对于任一结点, 其左子树中所有结点的键值小于该结点的键值: 其右子树中所有结点的键值大于等于该结点的键值: 其左右子树都是二叉搜索树. 所谓 ...
- UVA - 1610 Party Games(聚会游戏)(构造)
题意:输入一个n(2<=n<=1000,n是偶数)个字符串的集合D,找一个长度最短的字符串S(不一定在D中出现),使得D中恰好一半串小于等于S,另一半串大于S.如果有多解,输出字典序最小的 ...
- Spring(5) -(14) pointcut 语法
AOP的规范本应该由SUM公司提出,但是被AOP联盟捷足先登.AOP联盟指定AOP规范,首先就要解决一个问题,怎么表示切入点,也就是在哪些方法上增强(where) AspectJ 是一个面向切面的框架 ...
- maven学习(三)-使用maven来创建项目
转自https://www.cnblogs.com/xdp-gacl/p/4240930.html maven作为一个高度自动化构建工具,本身提供了构建项目的功能,下面就来体验一下使用maven构建项 ...
- VLOOKUP返回#N/A结果
VLOOKUP返回#N/A结果 1.无目标值 使用control+f查找是否存在所要搜索的值. 2.位置错误 所要搜索区域,被搜索值必须在首列. 3.格式错误 搜索值和被搜索区域格式需一致. 4.特殊 ...
- docker入门资料及常用命令
Docker17中文开发手册 :https://www.php.cn/manual/view/36147.html Linux部署Docker及常用命令: https://www.cnblog ...
- python类(2)
#从python开始学习编程 学习笔记 以后看书时注意一下书上表述:好像是类属性attribute,对象特性property,对象方法 1.对于一个类下的全部个体来说,某些属性可能存在个体差异.不是所 ...
- dxSkinController1 皮肤使用
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...
- VUE获取焦点
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- linux messages日志出现kernel: nf_conntrack: table full, dropping packet
上述结果会让业务访问很慢!各种网络服务耗时大幅上升,各种time out,各种丢包,完全无法正常提供服务,大并发业务场景下,开防火墙很容易出现这种问题. 解决方法1:关闭分防火墙服务 解决方法2:修改 ...