Codeforces Global Round 17
Codeforces Global Round 17
A. Anti Light's Cell Guessing
坑点:\(n=1,m=1\) 时答案为 \(0\) 。
其他情况:当 \(n=1\) 或 \(m=1\) 时,只需要取端点即可。其他情况只需要两个点,也是取两个端点,把离一个点曼哈顿距离为固定值的点连成一条线段,可以发现这两个端点形成的线段只可能有一个交点,即隐藏点。
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
using ll = long long;
constexpr int N = 2e5+5, P = 1e9+7;
int main() {
cin.tie(nullptr)->ios::sync_with_stdio(false);
int _; cin>>_;
while (_--) {
ll n,m; cin>>n>>m;
if(n==1&&m==1)cout<<0<<endl;
else if(n==1||m==1)cout<<1<<endl;
else {
cout<<2<<endl;
}
}
return 0;
}
B. Kalindrome Array
和之前cf出过的一题一模一样,那题是删字母,这题是删数字,不过都一样,因为可能删的值只可能有两个,枚举这两个可能值即可。
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
using ll = long long;
constexpr int N = 2e5+5, P = 1e9+7;
int a[N];
int main() {
cin.tie(nullptr)->ios::sync_with_stdio(false);
int _; cin>>_;
while (_--) {
int n; cin>>n;
rep(i,0,n)cin>>a[i];
int lx=-1,ly=-1;
int l=0,r=n-1;
while(l<r){
if(a[l]!=a[r]){
if(lx==-1){
lx=a[l]; ly=a[r];
break;
}
}else{
l++,r--;
}
}
l=0,r=n-1;
int flag=1;
while(l<r){
if(a[l]!=a[r]){
if(a[l]==lx){
while(l<r&&a[l]==lx)l++;
}else if(a[r]==lx){
while(l<r&&a[r]==lx)r--;
}else{
flag=0;
break;
}
if(a[l]!=a[r]){
flag=0;
break;
}
}else{
l++,r--;
}
}
if(flag){
cout<<"yes\n";
continue;
}
l=0,r=n-1;flag=1;
while(l<r){
if(a[l]!=a[r]){
if(a[l]==ly){
while(l<r&&a[l]==ly)l++;
}else if(a[r]==ly){
while(l<r&&a[r]==ly)r--;
}else{
flag=0;
break;
}
if(a[l]!=a[r]){
flag=0;
break;
}
}else{
l++,r--;
}
}
if(!flag){
cout<<"no\n";
}else{
cout<<"yes\n";
}
}
return 0;
}
C. Keshi Is Throwing a Party
由于答案具有单调性,考虑二分答案。于是问题就转化成了从 \(n\) 个人里选 \(k\) 个人,使他们都开心。
假设选了 \(k\) 个人的下标分别为 \(p_1,p_2,\cdots,p_k\) 。对于 \(i\in[1,k]\) ,都有
a_{p_i}\ge k-i
\]
根据这个性质,我们就可以贪心地取了。
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
using ll = long long;
constexpr int N = 2e5+5, P = 1e9+7;
int r[N], p[N], n;
int check(int x) {
int ans=0,cc=0;
rep(i,0,n){
if(cc+1>=x-r[i]&&cc+1<=p[i]+1)cc++;
}
return cc>=x;
}
int main() {
cin.tie(nullptr)->ios::sync_with_stdio(false);
int _; cin>>_;
while (_--) {
cin>>n;
rep(i,0,n)cin>>r[i]>>p[i];
int l=1,r=n;
while(l<r){
int mid=l+r+1>>1;
if(check(mid))l=mid;
else r=mid-1;
}
cout<<l<<endl;
}
return 0;
}
D. Not Quite Lee
一个数 \(x\) 形成的连续数字的和可以表示为
\]
于是一个数列 \((x_1,x_2,\cdots,x_k)\) 的合法性可以表示为
\]
移项得
\]
为表示简略,以下的幂次都是指 \(2\) 的幂次。
当数列中有一个为奇数时,右边的最低幂次为 \(0\) ,最低幂次为 \(0\) 的数可以表示任何数,也就是说,当数列中有一个为奇数,该数列即合法。于是考虑数列中全为偶数的情况,等式右边的最低幂次一定比左边的最低幂次大 \(1\) 。因为 \(x\) 是偶数,\(x+1\) 是奇数,乘起来再除个 \(2\) 必定会丢失一个因子 \(2\) 。低幂次的可以表示高幂次的,高幂次的不能表示低幂次,而左边的最低幂次要比右边小,所以要保证数列中幂次为最低幂次的数有偶数个,才能使他们的最低幂次 \(+1\) ,从而被右边的表示出来。于是思路就显而易见了,枚举最低幂次,若这个幂次不为 \(0\) ,那只能挑偶数个,否则都可以选。
从 \(n\) 个数中挑偶数个数(不能不挑)的方案数为
\]
其实根据二项式定理,二项式系数中的偶数项和奇数项的和其实是一样的,也就是说,上述的式子其实就是
\]
然后就可以写了。一个小技巧,求一个数的幂次可以用内建函数 __builtin_ctz(x)
求得。
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
using ll = long long;
constexpr int N = 2e5+5, P = 1e9+7;
ll qpow(ll a, ll b) {
ll res=1;
for(;b;b>>=1,a=(a*a)%P)if(b&1)res=res*a%P;
return res;
}
int cc[35];
int main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
#endif // !ONLINE_JUDGE
cin.tie(nullptr)->ios::sync_with_stdio(false);
int n; cin>>n;
rep(i,0,n){
int x; cin>>x;
cc[__builtin_ctz(x)] ++;
}
ll ans=0, tot=0;
for(int i=31;i>=0;i--){
if(cc[i]){
if(i) ans=(ans+qpow(2,tot)*(qpow(2,cc[i]-1)-1)%P)%P;
else ans=(ans+qpow(2,tot)*(qpow(2,cc[i])-1)%P)%P;
tot += cc[i];
}
}
cout<<ans;
return 0;
}
Codeforces Global Round 17的更多相关文章
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Beta Round #17 D. Notepad (数论 + 广义欧拉定理降幂)
Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2 ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
- Codeforces Global Round 11 个人题解(B题)
Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...
- Codeforces Beta Round #17 C. Balance DP
C. Balance 题目链接 http://codeforces.com/contest/17/problem/C 题面 Nick likes strings very much, he likes ...
随机推荐
- vue学习笔记(一)---- vue指令( v-on 事件绑定 )
Vue 中提供了 v-on: 事件绑定机制 绑定的事件处理函数必须定义到vm实例的事件处理函数 methods 中去 <div id="app"> <!-- &l ...
- 前端(vue)导出pdf
纯前端导出 pdf 实现方法如下: 1. 安装 html2pdf.jspdf npm install html2canvas jspdf --save 2. 项目 utils 文件夹中新建一个 htm ...
- 非代码的贡献也能成为Committer,我与DolphinScheduler社区的故事
点亮 ️ Star · 照亮开源之路 https://github.com/apache/dolphinscheduler // 每个人对于"开源社区"的定义都不一样, ...
- C-08\变量类别和名称粉碎机制
全局变量 定义:在所有函数外部定义的变量称为全局变量,一般以g_开头,如 char g_szBuf[100]; // 全局变量g_szBuf int main() { printf("%s\ ...
- k8s中使用prometheus operator监控外部服务器部署的windows exporter
k8s中使用prometheus operator监控外部服务器部署的windows exporter 0.文档说明 (1)Prometheus Operator是一个流行的k8s集群监控套件,项目地 ...
- [POI2014]HOT-Hotels 加强版
长链剖分优化 \(dp\) 模板 不过这 \(dp\) 真毒 \(\text{Code}\) #include <cstdio> #define RE register #define I ...
- 使用flex布局(多行,一行三个),换行后最后一行左右对齐问题
<html> <head> <style> html, body, ul { margin: 0; padding: 0; } ul { width: 100%; ...
- CF873F - Forbidden Indices
题意:对于一个字符串 \(S\),有一些位置是被 \(\text{Ban}\) 掉的. 对于这个字符串的所有子串,它的分数是(长度 \(\times\) 在没有被 \(\text{Ban}\) 掉的位 ...
- MyBatis 查询的条目与预期的不一致
预期查询的数据条目是 4 条: 但是 MyBatis 查询出来的结果只有 2 条数据: resultMap 开启了 autoMapping 功能,就不需要多余地添加 result.下面是错误的映射操作 ...
- ABP微服务系列学习-搭建自己的微服务结构(四)
上篇我们实现了认证服务和网关服务,基本我们的基础服务已经完成了,接下来我们才需要做服务的数据迁移.这里我们需要使用EF的CodeFirst模式.通过DotnetCli的命令去操作: dotnet ef ...