Codeforces Round #596 (Div. 1, based on Technocup 2020 Elimination Round 2)
(第一把div1心态崩了,给大家表演了一把上蓝)
(看来以后div1需要先读前三题,如果没把握切掉还是不要交了……)
A:
题意是求最少用几个形如$2^{t}+p$的数拼出n,给定n和p。$n\leq 10^{9},-1000\leq p\leq 1000,k\geq 0$。
我们不妨考虑如何判断一个k是否能成为答案。显然移项之后变成了用$2^{t}$拼$n-kp$。
设$n-kp$的二进制中有a个1,拼出它所用的$2^{t}$个数为num,那么$num_{min}=a$。
注意到我们可以把这a个中的某些$2^{t}$拆成两个$2^{t-1}$,最多可以拆出$n-kp$个(全用1拼)。
感性理解一下,显然num的可能取值是连续的。那么只要判断k是否在$[a,n+kp]$之间即可。
那我们应该枚举k到多少呢?注意到$a_{max}=log{n}$,那么只要k枚举到$log{n}$一定能找到解或者判断无解。
这么一个送分题我进入网页花了5分钟,想了5分钟,写了5分钟,我真是活该掉分。
#include<bits/stdc++.h>
#define maxn 100005
#define maxm 500005
#define inf 0x7fffffff
#define ll long long using namespace std; inline int read(){
int x=,f=; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-;
for(;isdigit(c);c=getchar()) x=x*+c-'';
return x*f;
} inline int calc(int x){int cnt=;while(x){cnt+=(x&);x>>=;}return cnt;} int main(){
int n=read(),p=read();
if(n==p){printf("-1\n");return ;}
for(int i=;i<=;i++){
n-=p; if(n<i){printf("%d\n",-);return ;}
if(calc(n)<=i && i<=n){printf("%d\n",i);return ;}
}
return ;
}
A
B:
题意是求有多少对$i,j$满足$a_{i}\cdot a_{j}=x^{k}$。$n\leq 10^{5},2\leq k\leq 100$。
看到这题大概是个人都有一个想法:维护一个质因数与指数集合的集合。
每次把$a_{i}$质因数分解,然后指数膜k。若膜k得0则忽略该质因数。
最后查找有多少数能和它的指数匹配(加起来膜k得0),并向集合中插入该数。
然后我不知道怎么写这个东西好写,于是去想了一些高论做法。
然而太菜什么都没想出来,只好手写这个东西,然后re on 6。
我:???
你wa on 6我也可以调,你tm的re on 6又不给result,我拿头调???
然后我陆续交了几发仍然re,于是心态崩了,去打炉石。(一套海盗战从10砍到了6,强烈推荐)
比完之后我点开第一个A的code,发现他写了一个这样的东西。
map<vector<pair<int,int> >,int> ans;
我:???
积累一个实用小知识:打cf一定要把stl的所有操作学好,不然你re都不知道是怎么re的。
#include<bits/stdc++.h>
#define maxn 100005
#define maxm 500005
#define inf 0x7fffffff
#define ll long long using namespace std;
map<vector<pair<int,int> >,int> res; inline int read(){
int x=,f=; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-;
for(;isdigit(c);c=getchar()) x=x*+c-'';
return x*f;
} int main(){
int n=read(),k=read(); ll ans=;
for(int nu=;nu<=n;nu++){
int x=read(); vector<pair<int,int> > a,b;
//a.push_back(0),b.push_back(0);
for(int j=;j<=sqrt(x);j++){
int p=; while(x%j==) x/=j,p++;
p%=k; if(p==) continue;
a.push_back(make_pair(j,p));
b.push_back(make_pair(j,k-p));
}
if(x!=){
a.push_back(make_pair(x,));
b.push_back(make_pair(x,k-));
}
ans+=(ll)res[b],res[a]++;
}
cout<<ans<<endl;
return ;
}
B
C:
由于上述原因(海盗战txdy)我并没有看这道题。今天上午胡了一下还胡错了,我真是活该掉分。
题意大概是给你一个$n\times m$的地图,每个点要么是空的要么有石头。
你只能向下或向右走,如果你撞到一个石头会把它推着一起走。
如果推到地图边界就不能再推了,也就是不能再朝该方向走。
求有多少种方法从$(1,1)$走到$(n,m)$。$n,m\leq 2000$。
这种有限制的移动题一般还是考虑用dp去表示它的状态以及走法。
我们如果考虑从$(1,1)$走到$(i,j)$比较麻烦,因为没法表示有多少石头的状态。
那如果倒着考虑,从$(i,j)$走到$(n,m)$呢?好多了,可以通过石头个数判断后面能走哪。但由于不知道走的方向比较麻烦。
考虑一条路径,我们如果只在它转弯的地方进行dp转移,就变得方便很多。
那么可以考虑设$D_{i,j},R_{i,j}$。其中$D_{i,j}$表示现在在$(i,j)$,下一步要往下,上一步不是往下的方案数。
设$(i,j)$正下方有k个石头,那么最多走$n-k-i$步就必须右转了。于是有$D_{i,j}=\sum_{s=1}^{n-k-i}{R_{i+s,j}}$。
R的转移类似。我写了个$O(nmlogn)$的,其实记一下石头个数完全可以$O(nm)$。
#include<bits/stdc++.h>
#define maxn 2005
#define maxm 500005
#define inf 0x7fffffff
#define mod 1000000007
#define ll long long using namespace std;
char mp[maxn][maxn];
ll n,m,d[maxn][maxn],r[maxn][maxn];
ll cd[maxn][maxn],cr[maxn][maxn];
ll nd[maxn][maxn],nr[maxn][maxn]; inline ll read(){
ll x=,f=; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-;
for(;isdigit(c);c=getchar()) x=x*+c-'';
return x*f;
} inline ll mo(ll &x){return x>=mod?x-mod:x;}
inline ll lowbit(ll x){return x&(-x);}
inline ll sr(ll t,ll x){ll ans=;for(ll i=x;i;i-=lowbit(i)) mo(ans+=cr[t][i]);return ans;}
inline ll sd(ll t,ll x){ll ans=;for(ll i=x;i;i-=lowbit(i)) mo(ans+=cd[t][i]);return ans;}
inline ll qr(ll t,ll x,ll y){return (sr(t,y)-sr(t,x-)+mod)%mod;}
inline ll qd(ll t,ll x,ll y){return (sd(t,y)-sd(t,x-)+mod)%mod;}
inline void ar(ll t,ll x,ll y){for(ll i=x;i<=n;i+=lowbit(i)) mo(cr[t][i]+=y);}
inline void ad(ll t,ll x,ll y){for(ll i=x;i<=m;i+=lowbit(i)) mo(cd[t][i]+=y);} int main(){
n=read(),m=read();
for(ll i=;i<=n;i++) scanf("%s",mp[i]+);
for(ll i=;i<=n;i++)
for(ll j=m;j>=;j--)
nr[i][j]=nr[i][j+]+(mp[i][j]=='R');
for(ll i=n;i>=;i--)
for(ll j=;j<=m;j++)
nd[i][j]=nd[i+][j]+(mp[i][j]=='R');
d[n][m]=r[n][m]=,ad(n,m,),ar(m,n,);
for(ll i=n;i>=;i--){
for(ll j=m;j>=;j--){
if(i==n && j==m) continue;
ll t1=nd[i+][j],t2=nr[i][j+];
if(i+<=n-t1) d[i][j]=qr(j,i+,n-t1);
if(j+<=m-t2) r[i][j]=qd(i,j+,m-t2);
ad(i,j,d[i][j]),ar(j,i,r[i][j]);
//cout<<i<<" "<<j<<":"<<d[i][j]<<" "<<r[i][j]<<endl;
}
}
if(n==m && n==) cout<<(mp[][]=='.')<<endl;
else cout<<(d[][]+r[][])%mod<<endl;
return ;
}
C
D:
咕了,补别的题(玩海盗战)。
Codeforces Round #596 (Div. 1, based on Technocup 2020 Elimination Round 2)的更多相关文章
- 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 (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 ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B. TV Subscriptions 尺取法
B2. TV Subscriptions (Hard Version) The only difference between easy and hard versions is constraint ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) A. Forgetting Things 水题
A. Forgetting Things Kolya is very absent-minded. Today his math teacher asked him to solve a simple ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products 数学 暴力
D. Power Products You are given n positive integers a1,-,an, and an integer k≥2. Count the number of ...
随机推荐
- BZOJ2151/洛谷P1792 题解
若想要深入学习反悔贪心,传送门. Description: 有 \(n\) 个位置,每个位置有一个价值.有 \(m\) 个树苗,将这些树苗种在这些位置上,相邻位置不能都种.求可以得到的最大值或无解信息 ...
- Java Array二维数组使用
二维数组:元素为一维数组的数组 package myArray.arrayarray; /* *二维数组:元素为一维数组的数组 * * 定义格式: * A:数组类型[][] 数组名: (推荐用法) * ...
- 面试官问我:平常如何对你的 Java 程序进行调优?
阅读本文大概需要 10 分钟. 作者:张俊城, 郭理勇, 刘建来源:http://t.cn/AiCTERJz Java 应用性能优化是一个老生常谈的话题,典型的性能问题如页面响应慢.接口超时,服务器负 ...
- 【转】Android 将自己的应用改为系统应用
所谓系统程序就是system/app目录中的程序,普通应用转换成系统程序后有稳定.减少内存(DATA)空间占用.恢复出厂设置后不会消失.修改系统时间.调用隐藏方法.系统关机重启.静默安装升级卸载应用等 ...
- C# 简单通信(实现文件传输)
https://blog.csdn.net/Sayesan/article/details/82185772 之前写过一个简单通信传输,不过只有聊天的功能,现在实现了文件传输的功能,借鉴于网上一篇博客 ...
- Oracle系列十三 视图
视图 :从表中抽出的逻辑上相关的数据集合. 视图是一种虚表. 视图建立在已有表的基础上, 视图赖以建立的这些表称为基表. 向视图提供数据内容的语句为 SELECT 语句, 可以将视图理解为存储起来的 ...
- Java8 lambda表达式10个示例<转>
例1.用lambda表达式实现Runnable 我开始使用Java 8时,首先做的就是使用lambda表达式替换匿名类,而实现Runnable接口是匿名类的最好示例.看一下Java 8之前的runna ...
- java concurrent并发包使用
package cn.com.zxf.atomic; import java.util.concurrent.atomic.AtomicInteger; public class AtomicExam ...
- Nginx打印json日志
1.修改配置,在http{}中添加 log_format access_json '{"@timestamp":"$time_iso8601",' '" ...
- Superset配置impala数据源
1.安装impyla pip install impyla 2.在superset页面配置如下,此时impala是有kerberos认证的 impala://xxxx:xx/default?auth_ ...