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 ...
随机推荐
- 六十七、SAP中内表插入的三种方法之一,APPEND的使用
一.如果内表是一个普通的内表,只用于存储数据不用来排序,那么优先选择APPEND插入 二.我们运行程序,并把工作区和内表加入到断点变量,如图所示,1X22的意思如图 三.我们点击ITAB1,来看内表数 ...
- 四十八、在SAP中函数参数的使用
一.不带参数的函数定义如下 二.我们把函数内部会变化的变量以参数的形式定义,其中USING和CHANGING分别表示变量和返回值,因为so_car表示的是工作区,所以后面加上[]符号. 三.我们把2个 ...
- 用cmd运行java可以javac不行(win10)
今天发现个有趣的问题,用cmd运行java可以javac不行.(win10) java-home和classpath配置没有问题,最后发现问提出先在path,在这里看并没有异常. 在上面图片中点击编辑 ...
- js(JavaScript)使用${pageContext.request.contextPath}报错
前几天写程序在js文件中用到了${pageContext.request.contextPath}然后一直报错,没有办法post到服务器,原来js把这个当成字符串了,一直以为他是jquery的函数! ...
- 逆向-PE重定位表
重定位表 当链接器生成一个PE文件时,会假设这个文件在执行时被装载到默认的基地址处(基地址+RVA就是VA).并把code和data的相关地址写入PE文件.如果像EXE一样首先加载就是它image ...
- NumPy 基于数值区间创建数组
来源:Python Numpy 教程 章节 Numpy 介绍 Numpy 安装 NumPy ndarray NumPy 数据类型 NumPy 数组创建 NumPy 基于已有数据创建数组 NumPy 基 ...
- linux常用命令-关机、重启
常用命令-关机.重启 命令 含义 reboot 重新启动操作系 shutdown –r now 重新启动操作系统,shutdown会给别的用户提示 shutdown -h now 立刻关机,其中now ...
- 每天一点点之vue框架开发 - History 模式下线上路由报404错误
vue-router 默认 hash 模式 —— 使用 URL 的 hash 来模拟一个完整的 URL,于是当 URL 改变时,页面不会重新加载. 如果不想要很丑的 hash,我们可以用路由的 his ...
- Fragment 知识巩固
重新学习 Fragment 1.Fragment 的生命周期 想要熟练使用 Fragment,那么必须要弄懂它的生命周期. 我们可以先看一下 Fragment 生命周期和 Activity 生命周期的 ...
- java web实现在线编辑word,并将word导出(二)
前一篇文章介绍了后台将前台html转为word文档的一种方式,但却有一个问题是没法讲图片放置在生成的word报告中.我在网上找了很多方法,甚至将图片转换成base64编码的方式也不成功.效果如下: 由 ...