Codeforces Round #741 (Div. 2)
A - The Miracle and the Sleeper
题意
给定\([l, r]\) 求出在这个区间内的两个数字a和b的取模的最大值 (\(a \ge b\))
分析
上届确定 因此我们最大的取模的值就是 \(\frac {r}{2} + 1\)
但是这个值能取到的条件是\(\frac {r}{2} + 1 \ge l\)
如果上述条件不满足 很显然答案的区间是\([0, r-l]\)
AC_CODE
#include <bits/stdc++.h>
using namespace std;
inline void solve() {
int l, r;
cin >> l >> r;
int p = max(l, r / 2 + 1);
cout << r % p << endl;
}
signed main()
{
int T = 1; scanf("%d",&T);
while(T -- ) solve();
return 0;
}
B - Scenes From a Memory header
题意
给一个长度 \(\le 50\) 的数字, 问最多可以删除多少为使得它变成一个非质数 数据保证一定有解
分析
首先我们可以知道 长度最短的非质数 是 1,4,6,8,9 因此我们首先特判这五个数字
其次呢, 剩下没有被使用过的数字就只有2,3,5,7 首先我们的出两个数字的所有组合(三位数以及更高位一定包含两位数,我们需要最短的
22,23,25,27,32,33,35,37,52,53,55,57,72,73,75,77 里面的质数只有23,37,53,73
因为保证一定有解, 因此我们可以排除两位数字中23,37,53,73 出现的可能, 而三位及以上的数字一定包含其他的数字
就在两位数字中的非质数 中包含了
因此所有存在的结果就只有1,4,6,8,9,22,25,27,32,33,35,52,55,57,72,75,77
一位数判断是否出现过 两位数for循环扫一遍即可
AC_CODE
#include <bits/stdc++.h>
using namespace std;
int vis[1000];
int cnt[10];
inline void solve() {
for(int i = 1; i < 10; i ++ ) cnt[i] = 0;
int n;
string a;
cin >> n >> a;
for(auto c : a) cnt[c - '0'] ++;
for(int i = 1; i < 10; i ++ ) {
if(cnt[i] && vis[i]) {
cout << 1 << endl;
cout << i << endl;
return;
}
}
for(int i = 0; i < n; i ++ )
for(int j = i + 1; j < n; j ++ ) {
int p = a[i] - '0', q = a[j] - '0';
int res = p * 10 + q;
if(vis[res]) {
cout << 2 << endl;
cout << res << endl;
return;
}
}
}
signed main()
{
vis[1] = true;
vis[4] = true;
vis[6] = true;
vis[8] = true;
vis[9] = true;
vis[22] = true;
vis[25] = true;
vis[27] = true;
vis[32] = true;
vis[33] = true;
vis[35] = true;
vis[52] = true;
vis[55] = true;
vis[57] = true;
vis[72] = true;
vis[75] = true;
vis[77] = true;
int T = 1; scanf("%d",&T);
while(T -- ) {
solve();
}
return 0;
}
C - Rings
题意
给定一个01 串,长度为len 从中找出两个长度 \(\ge len / 2\) 的 子串
使得二者转为十进制以后具有整数倍关系
思路
思维题(想到就很简单
我们可以把原来的字符串分为两种 有0的和没有0的
- 当0 存在的时候, 我们判断0是在前半段还是在后半段(假设第idx 位是0
- 在前半段的时候, 我们可以分割成两个成1倍关系的二进制串 0xxxxxx 和 xxxxxx
- 在前半段的时候, 我们可以分割成两个成2倍关系的二进制串 xxxxxx0 和 xxxxxx
- 当0 不存在时候, 我们可以分割成两个成1倍关系的二进制串 111111 和 111111 (全是1
代码实现起来就很简单了
AC_CODE
#include <bits/stdc++.h>
#define rep(i, b, s) for(register int i = (b); i <= (s); ++i)
using namespace std;
inline void solve() {
int n; string x;
cin >> n >> x;
int px = n / 2;
rep(i, 0, n - 1) {
if(x[i] == '0') {
if(i >= px) {
printf("1 %d 1 %d \n", i + 1, i);
return;
}
else {
printf("%d %d %d %d\n", i + 1, n, i + 2, n);
return;
}
}
}
printf("%d %d %d %d\n", 1, px, 2, px + 1);
}
signed main()
{
int T = 1; scanf("%d",&T);
while(T -- ) {
solve();
}
return 0;
}
D1 - Two Hundred Twenty One
题意
给定一个由+- 构成的字符串 +代表 1 - 代表 -1 (即代表\(a_i\)的值
规定一个子区间的值为 \(\sum_{i = l}^{r}(-1)^{i-1}a_i\)
规定一个操作为: 删去字符串中某个字符,其他的字符顺次往前移动
给定一个子区间\([l,r]\) 求出最少要进行几次操作,才能使这个区间的值为0
分析
- 如果已经是0的话我们就不用删除任何数字
- 当目前子区间的值为奇数的时候
我们一定可以找到某个下标 使得改下标左右两边的值是相等的 (因为每个位置所造成的影响的绝对值是1
此时删去这个值会使得后面的所有值全部取反 就会导致区间的值为0 - 偶数的时候
我们删去头或者尾 即可把这个区间的值变为奇数 同上
AC_CODE
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define fix(a) fixed << setprecision(a)
#define debug(x) cout<<#x" ----> "<<x<<endl
#define rep(i, b, s) for(register int i = (b); i <= (s); ++i)
#define pre(i, b, s) for(register int i = (b); i >= (s); --i)
//#define int long long
#define endl '\n'
#define ios ios::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII ;
typedef pair<int, PII> PIII ;// {value, {value, value}}
typedef pair<double, double> PDD ;
typedef long long LL;
const int INF = INT_MAX;
const LL INFF = INT64_MAX;
const int mod = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1.0);
inline int lowbit(int x){return x&-x;}
inline int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}
inline LL ksm(LL a, LL b) {if (b == 0) return 1; LL ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;}
inline LL lcm(LL a, LL b) {return a / gcd(a, b) * b;}
inline void out(bool flag);
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
inline void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n + 1), s(n + 1);
for(int i = 1; i <= n; i ++ ) {
char cc; cin >> cc;
if(cc == '+') a[i] = 1;
else a[i] = -1;
}
rep(i, 1, n) {
if(i % 2 == 1) s[i] = s[i - 1] + a[i];
else s[i] = s[i - 1] - a[i];
}
rep(i, 1, m) {
int l, r; cin >> l >> r;
int t = abs(s[r] - s[l - 1]);
if(!t) cout << 0;
else if(t & 1) cout << 1;
else cout << 2;
cout << endl;
}
}
signed main()
{
ios;
int T = 1; cin >> T;
while(T -- ) {
solve();
}
return 0;
}
inline void out(bool flag) {
if(flag) puts("YES");
else puts("NO");
}
Codeforces Round #741 (Div. 2)的更多相关文章
- Codeforces Round #741 (Div. 2), problem: (D1) Two Hundred Twenty One (easy version), 1700
Problem - D1 - Codeforces 题意: 给n个符号(+或-), +代表+1, -代表-1, 求最少删去几个点, 使得 题解(仅此个人理解): 1. 这题打眼一看, 肯定和奇 ...
- Codeforces Round #741 (Div. 2)部分题题解
我果然还是太菜了,就写了两道题....真是水死了.... A The Miracle and the Sleeper 简化题意:给定\(l,r\),求\(a\)%\(b\)的最大值,其中\(r> ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
随机推荐
- 【LeetCode】416. Partition Equal Subset Sum 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 动态规划 日期 题目地址:https://l ...
- 【Java例题】3.4求a+aa+aaa+aaaa+... ...+aa...a(n个
4. package chapter3; import java.util.*; public class demo4 { public static void main(String[] args) ...
- MySQL高级查询与编程笔记 • 【第2章 数据定义和操作】
全部章节 >>>> 本章目录 2.1 数据定义语言和数据操作语言 2.1.1 设计"优乐网"数据库 2.1.2 数据定义语言 2.1.3 数据操作语言 ...
- Java 16 中新增的 Stream 接口的一些思考
这里先提一个题外话,如果想看 JDK 不同版本之间有何差异,增加或者删除了哪些 API,可以通过下面这个链接查看: https://javaalmanac.io/jdk/17/apidiff/11/ ...
- Ranger-Sqoop2插件实现详解
1.组件和插件介绍 1.1.Ranger介绍 Apache Ranger能够监控和管理整个Hadoop平台的综合数据安全, 目前作为Apache Top Level Project(TLP顶级项目), ...
- Swoole 协程简介
什么是协程 协程可以简单理解为线程,只不过这个线程是用户态的,不需要操作系统参与,创建.销毁和切换的成本都非常低. 协程不能利用多核 cpu,想利用多核 cpu 需要依赖 Swoole 的多进程模型. ...
- 算法竞赛——BFS广度优先搜索
BFS 广度优先搜索:一层一层的搜索(类似于树的层次遍历) BFS基本框架 基本步骤: 初始状态(起点)加到队列里 while(队列不为空) 队头弹出 扩展队头元素(邻接节点入队) 最后队为空,结束 ...
- PyCharm撤消/恢复
PyCharm在撤消/重做的每个步骤之前移动插入符号,然后执行撤消/重做操作. 要撤消操作,请执行以下操作之一: 在主菜单上,选择Edit | Undo. 按Ctrl+Z. 要恢复操作,请执行以下操作 ...
- vue js 格式化时间
常用于iview日期组件时间处理 /** * @param {Number} num 数值 * @returns {String} 处理后的字符串 * @description 如果传入的数值小于10 ...
- SYCOJ246螺旋矩阵
题目-螺旋矩阵 (shiyancang.cn) noip201403螺旋矩阵[普及组]数学算法 - 大本营 - 博客园 (cnblogs.com) 以下为搬运代码.一个为算圈数,另外一个是数学方法 思 ...