Codeforces Round #697 (Div. 3) ABCDE 题解
久违的cf服务器爆炸场
A. Odd Divisor
思路:任何一个数都可以写成\(n = k2^m,其中k是一个奇数\),若k=1,那么n就一定是一个2的幂。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
int flag = 1;
for(ll i=1; (1LL<<i)<=n; i++ )
{
if((1LL<<i)==n) flag = 0;
}
puts(flag?"YES":"NO");
}
return 0;
}
B. New Year's Number
思路:你知道答案肯定是\(n = 2020i + 2021j\)的形式,那么你只需要枚举i,看j是否存在即可。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
int flag = 0;
for(ll i=0; i*2020<=n; i++)
{
ll cur = n - i*2020;
double num = cur/2021.0;
if(num==(ll)num)
{
flag = 1;
break;
}
}
puts(flag?"YES":"NO");
}
return 0;
}
C. Ball in Berland
思路:因为只选出两组,我们只需要枚举其中一组的选法,另外一组就自然确定了。枚举a中每个人的舞伴时,当前贡献就是k - 和当前这个a有的舞伴个数 - 要和a跳舞的那个人的舞伴个数 + 本次的1, 画个图自己理解一下就很容易懂了。 最后答案要除2因为会有重复计算的对。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 2e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
vector<vector<ll> > a(maxn);
vector<vector<ll> > b(maxn);
ll ina[maxn];
ll inb[maxn];
int main()
{
int kase;
cin>>kase;
int num = 1;
while(kase--)
{
ll na = read(), nb = read(), k = read();
for(int i=0; i<=na+2; i++)
a[i].clear();
for(int i=0; i<=nb+2; i++)
b[i].clear();
rep(i,1,k) ina[i] = read();
rep(i,1,k) inb[i] = read();
rep(i,1,k)
{
a[ina[i]].pb(inb[i]);
b[inb[i]].pb(ina[i]);
}
ll ans = 0;
rep(i,1,na)
{
for(int j=0; j<a[i].size(); j++)
{
ll cur = a[i][j];
ans += k-a[i].size()-b[cur].size()+1;
}
}
cout<<ans/2<<endl;
num++;
}
return 0;
}
D. Cleaning the Phone
思路:破题口在于b只有两种情况,\(bi=1或bi=2\),那么我们可以采取前面B题的思路,答案肯定是选了x个bi=1的 + y个bi=2的, 由于贪心策略,我在这两种b的选择中,如果选k个,那肯定选a最大的那k个。 所以就只需要从大到小排序好,记录各自前缀和后,枚举一遍x,用二分看还需要多少个y,然后每次比较取最小即可。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 2e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll a[maxn];
ll b[maxn];
ll suma[maxn];
ll sumb[maxn];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read(), m = read();
rep(i,1,n) a[i] = read();
rep(i,1,n) b[i] = read();
vector<ll> one;
vector<ll> two;
rep(i,1,n)
{
if(b[i]==1) one.pb(a[i]);
else two.pb(a[i]);
}
sort(one.begin(),one.end(), greater<ll>());
sort(two.begin(),two.end(),greater<ll>());
int lena = one.size();
int lenb = two.size();
rep(i,1,lena) suma[i] = suma[i-1] + one[i-1];
rep(i,1,lenb) sumb[i] = sumb[i-1] + two[i-1];
ll ans = 1e18;
rep(i,0,lena)
{
ll One = suma[i];
ll need = m - suma[i];
if(need<=0)
{
ans = min(ans,i);
}
else
{
int id = lower_bound(sumb+1,sumb+1+lenb, need) - sumb;
if(id>lenb) continue;
ans = min(ans,id*2+i);
}
}
if(ans==1e18) cout<<-1<<endl;
else cout<<ans<<endl;
}
return 0;
}
E. Advertising Agency
水题,预处理一下组合数就行了。我肯定挑的是最大的那k个,每次的贡献就是ans = ans*C(a[i]的个数,要挑出的个数)。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll dp[1005][1005];
ll a[maxn];
void init()
{
rep(i,0,1003) dp[i][0] = 1;
rep(i,1,1003) rep(j,1,1003) dp[i][j] = (dp[i-1][j-1] + dp[i-1][j])%mod;
}
int main()
{
init();
int kase;
cin>>kase;
while(kase--)
{
map<ll,ll> Map;
ll n = read(), k = read();
rep(i,1,n) a[i] = read(), Map[a[i]]++;
sort(a+1,a+1+n);
ll pre = -1;
ll ans = 1;
per(i,n,1)
{
if(a[i]==pre) continue;
ll d = min(k,Map[a[i]]);
ans = ((ans%mod)*(dp[Map[a[i]]][d]%mod))%mod;
k -= d;
pre = a[i];
}
cout<<ans<<endl;
}
return 0;
}
Codeforces Round #697 (Div. 3) ABCDE 题解的更多相关文章
- Codeforces Round #460 (Div. 2) ABCDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...
- Codeforces Round #546 (Div. 2) ABCDE 题解
1136A: 题意:一本书有n个章节,每个章节的分别在li到ri页,小明读完书后将书折在第k页,问还有多少章节没有读 题解:控制k在li~ri的范围内后输出n-i即可 #include <set ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- Codeforces Round #261 (Div. 2)[ABCDE]
Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
随机推荐
- 【FAQ】HarmonyOS SDK 闭源开放能力 — IAP Kit(6)
1.问题描述: 支付场景,表现是在沙盒情况下所有商品都可以正常跑通,但是在非沙盒情况下,线上购买年包1800大额支付华为的 iap.createPurchas 在输完密码就会报 1001860001 ...
- 重生之我是操作系统(十)----I/O管理
简介 操作系统的I/O管理(input/output mannagment)是协调,控制计算机与外部设备(如磁盘,键盘,网络接口)等之间数据交换的核心功能.实现可靠高效且统一(隐藏设备差异,如磁盘.串 ...
- apisix~ApisixPluginConfig的使用
1. ApisixPluginConfig 的作用 插件配置复用:将插件配置定义为独立的资源,供多个路由或服务引用. 解耦插件与路由:修改插件配置时,只需更新 ApisixPluginConfig,无 ...
- Vue ElementUI 树表格
树表格做懒加载-点击小箭头走接口 children为[]则使用hasChildren的true/false来判断是否有子节点,另,如果要做点击小箭头走接口必须加lazy及load <el-tab ...
- ArcGIS Desktop 10.7 完美汉化安装教程
1,下载文件并解压缩,双击[Esri ArcGIS Desktop v10.7.0.exe] 2.在安装向导中选择[Next] 3.选中[I accept the master agreement]我 ...
- vue3 基础-slot 插槽
前几篇的内容都是父子组件通过属性传值或者事件传值这样的. 本篇来学习父组件在调用子组件时, 如果想要给子组件传递特定的内容 (dom) , 则可通过 slot 这个设计来轻易实现哦. 例如现在有这样一 ...
- WPF 粉笔绘制
在做白板书写的时候,会有各种笔的绘制,比如 书写笔.马克笔.演示笔等等.粉笔的功能需求也是很有必要的. 上网搜了一圈,几乎没有绘制粉笔的. 有的是毛笔.楷体等绘制的如下博客: wpf inkcanva ...
- .NET8带来的一些新特性
最近收到任务,项目从.NET 5升级为.NET 8. 特意去了解了一下.NET8的新特性,经过验证后,分享一些这些新特性. 管他用得到用不到,先了解了再说. 一.性能提升 1.原生AOT深度优化 通 ...
- 纯前端实现图片伪3D视差效果
作者:vivo 互联网前端团队- Su Ning 本文通过depth-anything获取图片的深度图,同时基于pixi.js,通过着色器编程,实现了通过深度图驱动的伪3D效果.该方案支持鼠标/手势与 ...
- gRPC-go的一些tips
1.请注意,在 gRPC-Go 中,RPC 以阻塞/同步模式运行,这意味着 RPC 调用等待服务器响应,并且将返回响应或错误. Note that in gRPC-Go, RPCs operate i ...