CF-937

在补题……

D

分析

我们发现这些因子都是二进制形式的十进制数,n的范围是$1e5$,16的二进制是$10000$,于是可以枚举1~16,把这些因子预处理出来,对于每个n就枚举因子再作除,看剩下的数每位是不是只有0与1

代码

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define db(x) cout<<x<<" "<<endl;
#define _db(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;
#define mem(a) memset(a,0, sizeof(a))
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
int s[16],b[33];
void solve(){
int n;cin>>n;
int tp=n,f=0;
while(tp){
if(tp%10>1) f=1;
tp/=10;
}
if(f){
rep(i,2,16){
while(n%b[i]==0){
n/=b[i];
}
}
int tp=n,ff=1;
while(tp){
if(tp%10>1) ff=0;
tp/=10;
}
if(ff) cout<<"YES";
else cout<<"NO";
}
else cout<<"YES";
cout<<endl;
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int e=0;
rep(i,1,32){//预处理因子
if(i&1){
int x=i,res=0,k=0;
while(x){
s[k++]=x%2;
x/=2;
}
per(j,k,0){
res=res*10+s[j];
}
b[++e]=res;
}
}
int t;cin>>t;while(t--)
solve();
return 0;
}

E

分析

因为所求长度一定是n的因子,我们可以暴力枚举长度$len$,再对遍历每个区间判断就行

操作

蒟蒻之前只会嵌套for循环把每个枚举到的对应区间取出来再遍历判断

难点在于如何简单的实现这个“周期性区间映射”

如$s=hshahaha$,$len$为2,且我们要映射到第一个长为$len$的区间,即要得到这样的映射关系:$s[0]-s[2],s[1]-s[3],s[0]-s[4],s[1]-s[5],s[0]-s[6],s[1]-s[7]$

我们可以简化为一个序列,已知序列$a[]$,设周期T,所选的一个周期长度的区间起点为st,用i枚举序列每一个数

则所求映射为 : $a[i]-a[i%T+s]$

rep(i,0,7) a[i]=i;
int T,st;cin>>T>>st;//周期长度与映射区间的起点
for(int i=0;i<=7;i++){
cout<<a[i]<<"-"<<a[i%T+st]<<endl;
}
/*
2 2
0--2
1--3
2--2
3--3
4--2
5--3
6--2
7--3
*/

代码

void solve(){
int n;cin>>n;
string s;cin>>s;
for(int len=1;len<=n;len++){
if(n%len!=0) continue;
for(int st=0;st<=len&&st<n;st+=len){//枚举起点,即第一个区间与第二个区间的起点
int sum=0;
rep(j,0,n-1){
sum+=(s[j]!=s[j%len+st]);
}
if(sum<=1){
cout<<len<<endl;
return;
}
}
}
}

F

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define db(x) cout<<x<<" "<<endl;
#define _db(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;
#define mem(a) memset(a,0, sizeof(a))
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--) void solve(){
int a,b,c;cin>>a>>b>>c;
if(c-a!=1){
cout<<"-1"<<endl;
return;
}
int x=0;
queue<int>q;
q.push(0);
while(q.size()){
x=q.front();
q.pop();
if(a){
a--;
q.push(x+1);
q.push(x+1);
}
else if(b){
b--;
q.push(x+1);
}
}
cout<<x<<endl;
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;cin>>t;while(t--)
solve();
return 0;
}

CF-937(D,E)的更多相关文章

  1. Karen and Coffee CF 816B(前缀和)

    Description To stay woke and attentive(专注的) during classes, Karen needs some coffee! Karen, a coffee ...

  2. CF#538(div 2) C. Trailing Loves (or L'oeufs?) 【经典数论 n!的素因子分解】

    任意门:http://codeforces.com/contest/1114/problem/C C. Trailing Loves (or L'oeufs?) time limit per test ...

  3. CF 439C(251C题)Devu and Partitioning of the Array

    Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes ...

  4. CF 518D(概率dp)

    传送门:Ilya and Escalator 题意:有n个人排队进车厢,每秒只能进一个人,而且第1个人进了后面的人才能进,第一个人每秒进入车厢的概率为p,不进的概率为1-p,求t秒后进入车厢总人数的数 ...

  5. CF 439D(251D题)Devu and his Brother

    Devu and his Brother time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. CF History(区间合并)

    这其实是一个简单的区间合并问题,但是我们第一交是过了,后来学长rejudge,我们又TLE了,这一下不仅耽误了我们的时间,也波动到了我们的心情,原先时间是2s,(原oj就是2s),后来改成了1s,我用 ...

  7. CF 86D 莫队(卡常数)

    CF 86D 莫队(卡常数) D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes i ...

  8. 清橙A1206.小Z的袜子 && CF 86D(莫队两题)

    清橙A1206.小Z的袜子 && CF 86D(莫队两题) 在网上看了一些别人写的关于莫队算法的介绍,我认为,莫队与其说是一种算法,不如说是一种思想,他通过先分块再排序来优化离线查询问 ...

  9. CF Round #600 (Div 2) 解题报告(A~E)

    CF Round #600 (Div 2) 解题报告(A~E) A:Single Push 采用差分的思想,让\(b-a=c\),然后观察\(c\)序列是不是一个满足要求的序列 #include< ...

  10. CF #552(div3)G 最小lcm

    题目链接:http://codeforces.com/contest/1154/problem/G 题意:lcm是最小公倍数,本题就是给你一个数组(可能会重复),要求你判断出那两个数的最小公倍数最小, ...

随机推荐

  1. cookie和服务器Session的区别

    cookie和服务器Session的区别 cookie和服务器Session都可用来存储用户信息,cookie存放于客户端,Session存放于web服务器端. 因为cookie存放于客户端有可能被窃 ...

  2. Java面向对象之接口和抽象类的区别一目了然

    介绍 相信对于Java面向对象部分,很多人很长一段时间对于接口和抽象类的区别,使用场景都不是很熟悉,同是作为抽象层重要的对象,工作中到底什么情况下使用抽象类,不是很清楚.本文就一次性把这些概念一次性说 ...

  3. github.com/json-iterator/go 详细教程

    最近接触到了 github.com/json-iterator/go , 是由滴滴开源的第三方json编码库,它同时提供Go和Java两个版本. 文中大量内容来自 github 上的 wiki 文档, ...

  4. K6 在 Nebula Graph 上的压测实践

    背景 对于数据库来说,性能测试是一个非常频繁的事情.优化查询引擎的规则,调整存储引擎的参数等,都需要通过性能测试,查看系统在不同场景下的影响. 即便是同样的代码,同样的参数配置,在不同的机器资源配置, ...

  5. C++ String //string字符串查找和替换 比较 存取 修改单个字符 插入和删除 string字串

    1 //string字符串查找和替换 比较 存取 修改单个字符 插入和删除 string字串 2 #include <iostream> 3 #include<string> ...

  6. 4、dubbo的高可用

    1.zookeeper宕机与dubbo直连 现象:zookeeper注册中心宕机,还可以消费dubbo暴露的服务. 原因: 健壮性 l 监控中心宕掉不影响使用,只是丢失部分采样数据 l 数据库宕掉后, ...

  7. PWR & 低功耗三种模式

    睡眠模式: int main(void) { OLED_Init(); OLED_ShowString(1, 1, "RxData:"); Serial_Init(); while ...

  8. openlayers.org 百度地图 静态化 同类产品

    openlayers 官网 https://openlayers.org/ 发现不好打开,修改dns 114.114.114.114 202.99.104.68 打开快了许多 https://blog ...

  9. 数据湖&湖仓一体简介

    1 简介 术语 数据库 数据库是"按照数据结构来组织.存储和管理数据的仓库". 广义上的数据库,在20世纪60年代已经在计算机中应用了.但这个阶段的数据库结构主要是层次或网状的,且 ...

  10. K8s中Labels(标签)和Annotations(注解)对比

    在Kubernetes中,Labels(标签)和Annotations(注解)都是用于为资源对象添加元数据的机制,但它们在用途.选择能力以及数据形式上存在一些关键的区别. 首先,Labels主要用于标 ...