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. crontab采坑总结

    目录 crontab环境变量 脚本缺少执行权限 crontab是Linux平台实现定时任务的服务工具,通常情况下该服务会预装在发行版中,直接使用即可. 关于crontab的详细用法参考:https:/ ...

  2. SpringBoot 服务接口限流,搞定!

    来源:blog.csdn.net/qq_34217386/article/details/122100904   在开发高并发系统时有三把利器用来保护系统:缓存.降级和限流.限流可以认为服务降级的一种 ...

  3. 标准运算符替代函数之operator模块

    # 官网参考示例地址 https://docs.python.org/zh-cn/3/library/operator.html # operator模块提供了一套与python的内置的运算符对应的高 ...

  4. Flex 弹性盒子布局

    可以少去理解一些不必要的概念,而多去思考为什么会有这样的东西,它解决了什么问题,或者它的运行机制是什么? 1. 弹性盒子布局概念 Flex 是 Flexible Box 的缩写,意为"弹性布 ...

  5. ASP.NET Core 微信支付(四)【支付结果通知回调(未按照官方步骤) APIV3】

    官方文档 支付通知API 证书和回调报文解密 参考资料 netcore 中没有Request.InputStream 理论实战 对于我来说,这个微信支付结果通知回调有两个难点. 难点一 一开始在想是怎 ...

  6. Java纯手打web服务器(二)

    概要:这里对上一篇中的访问资源进行改进,将访问servlet和静态资源进行区分. 主要不同的地方是加入了两种分析器 servlet分析器 if (request.getUri().startsWith ...

  7. 【Azure 云服务】查看Azure云服务在中国区域的VM型号大小列表(型号编码,定价层,以及CPU, Memory等)

    问题描述 如何查看创建 Azure Cloud Service 服务时,可以选择的VM型号吗? 问题解答 根据官网参考,可以通过PowerShell脚本 Get-AzComputeResourceSk ...

  8. Python(上机题) 通俗易懂的基础题目解析

    python 题目 文章目录 python 题目 题目一:幸运数对 题目二:lambda 函数找最大值 题目三:n个数前后互换 (切片) 题目四:字符串相减(删除指定字符) 方法一:可以用空字符来替换 ...

  9. SHA算法:数据完整性的守护者

    一.SHA算法的起源与演进 SHA(Secure Hash Algorithm)算法是一种哈希算法,最初由美国国家安全局(NSA)设计并由国家标准技术研究所(NIST)发布.SHA算法的目的是生成数据 ...

  10. vscode 尾逗号不自动删除 'comma-dangle': 'off' eslint vue

    vscode 尾逗号不自动删除 'comma-dangle': 'off' eslint 外层环境说明 vscode eslint - .elintrs.js vue - vue开发 vetur - ...