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 题意: 输入 ...
随机推荐
- zk源码—5.请求的处理过程
大纲 1.服务器的请求处理链 (1)Leader服务器的请求处理链 一.PrepRequestProcessor请求预处理器 二.ProposalRequestProcessor事务投票处理器 三.S ...
- blk_mq多队列块设备浅析
1. 为什么要使用多队列 在主机中,多cpu运行多个线程,每个线程都能和文件系统交互,文件系统层也是用多线程和bio层交互,但是,块设备层只有一个队列: 在块设备层,来自多个cpu的bio请求被放在同 ...
- 一个日h站的Nday
0x00 前言 今天先来无事的我翻起了qq收藏夹.忽然发现了一个去年EDUSRC群里一个老表发的洞.今天就给大家发出来耍耍. 抵制黄色网站人人有责,打造绿色上网环境. 面对正规网站时候,请不要做非法测 ...
- 25年初的cnvd小试
算是一个里程碑吧,第一次尝试获得cnvd证书
- 【工具】SageMath|Ubuntu 22 下 SageMath 安装和一般数域筛法代码示例(2024年)
就一个终端就能运行的东西, 网上写教程写那么长, 稍微短点的要么是没链接只有截图.要么是链接给的不到位, 就这,不是耽误生命吗. 废话就到这里. 文章目录 链接 步骤 链接 参考: Install S ...
- 保护网站免受黑客攻击:Web安全的重要性和保护方法
@charset "UTF-8"; .markdown-body { line-height: 1.75; font-weight: 400; font-size: 15px; o ...
- NewtonJsonConvert的比较好搭配使用
(1)与关键字冲突,解决办法加@ var a = new { @class=1, }; var d = JsonConvert.SerializeObject(a); Console.WriteLin ...
- codeup之进制转换(大数的进制转换
题目描述 将一个长度最多为30位数字的十进制非负整数转换为二进制数输出. 输入 多组数据,每行为一个长度不超过30位的十进制非负整数. (注意是10进制数字的个数可能有30个,而非30bits的整数) ...
- POWERBI_创建工作区应用_协同办公能力 up up up
在powerbi中,我们往往会创建很多不同模型的报表,他们分别独立,但是在业务决策过程中,我们需要跨报表查看数据,反复切换报表,低效且忙乱 这个时候,合并展示报表是至关重要的 今天就一起学习一下,如何 ...
- Nuxt的SEO实践
第9章:Nuxt的SEO实践 1. 引言 Nuxt框架在SEO方面的优势主要体现在以下几个方面: 服务器端渲染(SSR): Nuxt默认支持SSR,这意味着搜索引擎爬虫可以直接看到完整的页面内容,而不 ...