Codeforces Round #741 (Div. 2)部分题题解
我果然还是太菜了,就写了两道题....真是水死了....
A The Miracle and the Sleeper
简化题意:给定\(l,r\),求\(a\)%\(b\)的最大值,其中\(r>=a>=b>=l\).
这里规定了是大的数模小的数,考虑选定一个\(b\),显然\(a\)必须比他大,则b%b=0,(b+1)%b=1,(b+2)%b=2...(2b-1)%b=b-1,之后就又从0开始到b-1,显然若\(2b-1<=r\)的话我们就能取到在模b的意义下的最大值,还有的是我们想让这个b足够大,才能满足我们的期望。也就是说对于一个数x在其2x-1处恰取到最大值。那么最好的情况就是2bx-1=r,这样的话,恰好在r处取到模bx意义下的最大值。这样比bx大的,取不到bx-1,比bx小的,更取不到bx-1。但这只是奇数的情况,若r为偶数的话怎么办,有两种想法,让r-1恰取到最大值,和r+1恰取到最大值,经过计算发现这样的话得到的值都是一样的都为r/2。但让r+1取到最大值,要求的值为r/2+1比r-1取到最大值要求的值为r/2,相比下前者更容易满足l的限制。还有一个问题那如果我们要求的恰好取到最大值的x(或b)小于l怎么办呢,你想一下,你的x是从x开始到r恰好取到最大值,但x小于l,那说明从l开始到r都取不到l-1,此时一定数从l开始更优!完毕!
//不等,不问,不犹豫,不回头.
#include<bits/stdc++.h>
#define _ 0
#define ls p<<1
#define db double
#define rs p<<1|1
#define P 1000000007
#define ll long long
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define ull unsigned long long
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define rep(x,y,z) for(int x=y;x<=z;++x)
#define fep(x,y,z) for(int x=y;x>=z;--x)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
inline int read()
{
int x=0,ff=1;
char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*ff;
}
int main()
{
//freopen("1.in","r",stdin);
int get(T);
while(T--)
{
int get(l),get(r);
if(r%2==0)
{
if(r/2+1>=l) cout<<r/2-1<<endl;
else cout<<r-l<<endl;
}
else
{
int s=r+1;
if(s/2>=l) cout<<s/2-1<<endl;
else cout<<r-l<<endl;
}
}
return (0^_^0);
}
//以吾之血,铸吾最后的亡魂.
B. Scenes From a Memory
B题啊,气人我把57当成质数了....气死!57=19*3,估计我能记一辈子了...
这个题我们其实可以将所有的答案给预先找出来,这样直接查找就行了,答案最多是两位数。
//不等,不问,不犹豫,不回头.
#include<bits/stdc++.h>
#define _ 0
#define ls p<<1
#define db double
#define rs p<<1|1
#define P 1000000007
#define ll long long
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define ull unsigned long long
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define rep(x,y,z) for(int x=y;x<=z;++x)
#define fep(x,y,z) for(int x=y;x>=z;--x)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
const int N=100;
int vis[N],n;
char c[N];
inline int read()
{
int x=0,ff=1;
char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*ff;
}
int main()
{
//freopen("1.in","r",stdin);
int get(T);
while(T--)
{
get(n);scanf("%s",c+1);
int id=0;
rep(i,1,n)
{
if(c[i]=='1'||c[i]=='4'||c[i]=='6'||c[i]=='8'||c[i]=='9')
{
id=c[i]-'0';
break;
}
}
if(id) {put(1);put(id);continue;}
memset(vis,0,sizeof(vis));
rep(i,1,n)
{
if(c[i]=='2'&&i!=1)
{
id=(c[i-1]-'0')*10+2;
break;
}
else if(c[i]=='5'&&i!=1)
{
id=(c[i-1]-'0')*10+5;
break;
}
else if(c[i]=='3'&&vis[3])
{
id=33;break;
}
else if(c[i]=='7'&&vis[7])
{
id=77;break;
}
else if(c[i]=='7'&&vis[2])
{
id=27;break;
}
else if(c[i]=='7'&&vis[5])
{
id=57;break;
}
vis[c[i]-'0']=1;
}
put(2);put(id);
}
return (0^_^0);
}
//以吾之血,铸吾最后的亡魂.
C. Rings
看完题解的我眼泪流下来...
简化题意:给定一个长度为n的01串表示一个二进制数,你需要截取两个不同的且长度都必须大于等于\(\frac{n}{2}\)(向下取整)的区间,使得这两个区间转换成两个十进制数后互为倍数关系,这不妥妥的构造题吗,我怎么死在上面了....
由于2进制数肯定和2有关系,我们先尝试用2的倍数看能不能搞事情,容易发现,我们若截取了l,r,考虑l-1,r为若l-1为0,那妥妥的一倍关系就行,考虑l,r+1,若r+1为0,那不就是两倍的关系吗?找到什么规律了吗?也就是说只要这个01串中有0的话,我们就可以顺着这个0在前面(或后面)截取长度为n/2的字串就可以构造答案了,为什么有0就行,因为往前往后都可以构造,这样的话一定能构造出答案。那接下来考虑全是1的情况,那这不是更是白给吗?我们随便截取两端全是1的就是1倍的关系。完毕!
//不等,不问,不犹豫,不回头.
#include<bits/stdc++.h>
#define _ 0
#define ls p<<1
#define db double
#define rs p<<1|1
#define P 1000000007
#define ll long long
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define ull unsigned long long
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define rep(x,y,z) for(int x=y;x<=z;++x)
#define fep(x,y,z) for(int x=y;x>=z;--x)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
const int N=2e4+10;
int n,T;
char c[N];
inline int read()
{
int x=0,ff=1;
char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*ff;
}
int main()
{
//freopen("1.in","r",stdin);
get(T);
while(T--)
{
get(n);
scanf("%s",c+1);
bool flag=false;
rep(i,1,n)
{
if(c[i]=='0')
{
flag=true;
if(i-n/2>=1)
printf("%d %d %d %d\n",i-n/2,i,i-n/2,i-1);
else if(i+n/2<=n)
printf("%d %d %d %d\n",i,i+n/2,i+1,i+n/2);
break;
}
}
if(flag) continue;
printf("%d %d %d %d\n",1,n/2,2,n/2+1);
}
return (0^_^0);
}
//以吾之血,铸吾最后的亡魂.
D1. Two Hundred Twenty One (easy version)
这个题的题意是真的难理解啊....
简化题意:给你一个序列,其中序列中每个数的值要么1要么-1,且每个位置上都有一个符号满足奇数位为+,偶数位为-,给你q个询问,每个询问给你一个区间,求区间里至少去掉多少个数,才能使得这个区间和为0,注意去掉一个数后,后面所有的数都向前平移。其实这句话的意思就是所有数的符号变为前面数的符号。考虑去掉一个数,对前面数肯定没影响,对后面的数的影响就是所有数的符号取反,其实就是后面数的和取反。考虑对于一个区间而言,若区间和为奇数,那么肯定存在一个中间的数,其前面的和等于后面的和,那么我们将这个数去掉,后面的数取反,和为0为最优的情况,那和为偶数的呢?一次显然不够,那我么可以随便去掉一个数,使其和变为奇数,再按上述操作就行。完毕!
//不等,不问,不犹豫,不回头.
#include<bits/stdc++.h>
#define _ 0
#define ls p<<1
#define db double
#define rs p<<1|1
#define P 1000000007
#define ll long long
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define ull unsigned long long
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define rep(x,y,z) for(int x=y;x<=z;++x)
#define fep(x,y,z) for(int x=y;x>=z;--x)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
const int N=3e5+10;
int T,a[N],n,q;
char c[N];
inline int read()
{
int x=0,ff=1;
char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*ff;
}
int main()
{
//freopen("1.in","r",stdin);
get(T);
while(T--)
{
get(n);get(q);
scanf("%s",c+1);
rep(i,1,n) a[i]=a[i-1]+(((c[i]=='+'&&i%2==1)||(c[i]=='-'&&i%2==0))?1:-1);
rep(i,1,q)
{
int get(x),get(y);
int s=a[y]-a[x-1];
if(s==0) put(0);
else if((s%2+2)%2==1) put(1);
else put(2);
}
}
return (0^_^0);
}
//以吾之血,铸吾最后的亡魂.
D2. Two Hundred Twenty One (hard version)
这个在上个的基础上要求输出方案。
考虑奇数的话,我们想要找到那个特殊的位置,直接二分就行。
偶数的话,我们可以将区间左端点去掉,再二分。
Codeforces Round #741 (Div. 2)部分题题解的更多相关文章
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
- Codeforces Round #744 (Div. 3) G题题解
淦,最后一道题没写出来,...还是我太菜了,不过这个题确实比较有趣. G. Minimal Coverage 简化题意:就是你处在坐标轴的0点上,给你一个序列\(a_i\),每次你可以选择向左走\(a ...
- Codeforces Round #573 (Div. 2) D题题解
一.题目 Tokitsukaze, CSL and Stone Game Tokitsukaze和CSL正在玩一些石头游戏. 一开始,有n堆的石头,第i堆石头数记为 \(a_i\),两人轮 ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- Codeforces Round #552 (Div. 3) A题
题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...
- Codeforces Round #198 (Div. 2)A,B题解
Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
随机推荐
- composer 包 slim使用案例,一个简单的路由解决方案
nginx配置文件修改 location / { try_files $uri /index.php$is_args$args; } 设置好nginx伪静态,把所有的请求方式都转向到index.php ...
- SQLmap的基本命令
Sqlmap sqlmap是一个自动化的SQL注入工具,其主要功能是扫描,发现并利用给定的URL进行SQL注入.目前支持的数据库有MySql.Oracle.Access.PostageSQL.SQL ...
- Spring系列-SpringBase+IOC
Spring 一.前言 Thinking is more important than learning 本文主要讲述spring 以及它的 IOC原理 代码地址:https://gitee.com/ ...
- 洛谷P1583——魔法照片(结构体排序)
https://www.luogu.org/problem/show?pid=1583#sub 题目描述 一共有n(n≤20000)个人(以1--n编号)向佳佳要照片,而佳佳只能把照片给其中的k个人. ...
- PTA——c++函数
1.在C++中,关于下列设置缺省参数值的描述中,()是正确的. 在指定了缺省值的参数右边,不能出现没有指定缺省值的参数: 2.使用地址作为实参传给形参,下列说法正确的是() 实参与形参操作的是同一对象 ...
- Django边学边记—新手Django建项目各流程细节
一.准备虚拟环境 1)安装 virtualenv pip install virtualenv 2)virtualenvwrapper pip install virtualenvwrapper-wi ...
- javascript 一些函数的实现 Function.prototype.bind, Array.prototype.map
* Function.prototype.bind Function.prototype.bind = function() { var self = this, context = [].shift ...
- AOJ/搜索与递归及分治法习题集
ALDS1_4_A-LinearSearch. Description: You are given a sequence of n integers S and a sequence of diff ...
- 一个故事,一段代码告诉你如何使用不同语言(Golang&C#)提供相同的能力基于Consul做服务注册与发现
目录 引言 什么是微服务 传统服务 微服务 什么是服务注册与服务发现 为什么要使用不同的语言提供相同的服务能力 服务协调器 服务注册 Golang C#(.NetCore3.1) 服务发现 通过Htt ...
- MacOS上通过虚拟机搭建基础CentOS7系统环境
MacOS上通过虚拟机搭建基础CentOS7系统环境 尽管从Mac的Terminal可以看出,macOS与UNIX.Linux或多或少都有血缘关系(shell.bash等),但是在mac进行Linux ...