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 ...
随机推荐
- 12月12日内容总结——Django之数据增删改查、Django请求生命周期流程图、Django路由层(路由匹配、转换器、正则匹配)、反向解析
目录 一.可视化界面之数据增删改查 二.django请求生命周期流程图 三.django路由层 1.路由匹配 2.转换器 3.正则匹配 不同版本的区别 正则匹配斜杠导致的区别 4.正则匹配的无名有名分 ...
- Vue3源码阅读梳理
简单代码例子 const { createApp, defineComponent, computed, watch, ref, reactive, effect } = Vue const app ...
- Pytest插件pytest-order指定用例顺序
Pytest插件pytest-order指定用例顺序 安装 pip install pytest-order 注意不是pytest-ordering 说起来这里有个故事 关于pytest-order ...
- undefined会变为null吗?
echarts 会将 series data中的数据并不是你想的那样简单 我们很多小伙伴都使用过echarts. 然后 series:[{ data:[] }] 中的数据可能并没有我们想的那样简单 为 ...
- Grafana 系列文章(十四):Helm 安装Loki
前言 写或者翻译这么多篇 Loki 相关的文章了, 发现还没写怎么安装 现在开始介绍如何使用 Helm 安装 Loki. 前提 有 Helm, 并且添加 Grafana 的官方源: helm repo ...
- 「SHOI2015」脑洞治疗仪
\(\text{Naive Solition}\) 当然是 \(ODT\) 暴力啦 \(Luogu\) 煞费苦心加强了数据,于是就过不了了... 不过 \(LibreOJ\) 上可以过 #includ ...
- JZOJ 4250.路径
\(\text{Solution}\) \(30\) 分暴搜合法路径 另 \(30\) 分状压 设 \(f_{i,j,k}\) 表示当前到第 \(i\) 个点,走过的点状态为 \(j\),走过的路径长 ...
- JavaSE 对象与类(一)
对象与类 1.面向对象程序概述 Java是完全面向对象的,必须熟悉OOP才能够编写Java程序. 概念:类class.实例(对象)instance 由类构造(construct)对象的过程称为创建类的 ...
- docker-compose部署rocketmq
docker-compose安装: 1.从github上下载docker-compose二进制文件安装 Ubuntu下载docker-compose文件 sudo curl -L https://gi ...
- PostgreSQL性能优化综合案例 - 2
[调优阶段8] 1. 压力测试 pgbench -M prepared -r -c 1 -f /home/postgres/test/login0.sql -j 1 -n -T 180 -h 172. ...