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 ...
随机推荐
- 1079 - Just another Robbery
1079 - Just another Robbery PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 3 ...
- 【剑指Offer】把二叉树打印成多行 解题报告(Python)
[剑指Offer]把二叉树打印成多行 解题报告(Python) 标签(空格分隔): 剑指Offer 题目地址:https://www.nowcoder.com/ta/coding-interviews ...
- datatables scrollX设置水平滚动无效问题
如下:设置了水平滚动之后, 页面并没有滚动效果$(document).ready(function() { $('#example').dataTable( { "scrollX" ...
- Adversarial Self-Supervised Contrastive Learning
目录 概 主要内容 Linear Part 代码 Kim M., Tack J. & Hwang S. Adversarial Self-Supervised Contrastive Lear ...
- 利用 jQuery 操作页面元素的方法,实现电商网站购物车页面商品数量的增加和减少操作,要求单项价格和总价随着数量的改变而改变
查看本章节 查看作业目录 需求说明: 利用 jQuery 操作页面元素的方法,实现电商网站购物车页面商品数量的增加和减少操作,要求单项价格和总价随着数量的改变而改变 当用户单击"+" ...
- SpringBoot 原理分析、监控、项目部署
目录 SpringBoot 监控 概述 使用 SpringBoot Admin 概述 使用 SpringBoot 项目部署 SpringBoot 监控 概述 SpringBoot 自带监控功能 Act ...
- 强化学习实战 | 自定义gym环境之显示字符串
如果想用强化学习去实现扫雷.2048这种带有数字提示信息的游戏,自然是希望自定义 gym 环境时能把字符显示出来.上网查了很久,没有找到gym自带的图形工具Viewer可以显示字符串的信息,反而是通过 ...
- Swagger的应用
一.介绍 一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 框架. 二.依赖 <dependency> <groupId>io.springf ...
- Numpy实现简单BP神经网络识别手写数字
本文将用Numpy实现简单BP神经网络完成对手写数字图片的识别,数据集为42000张带标签的28x28像素手写数字图像.在计算机完成对手写数字图片的识别过程中,代表图片的28x28=764个像素的特征 ...
- java集合分类
Java中的集合包括三大类,它们是Set.List和Map, Set(集) List(列表) Map(映射) 它们都处于java.util包中,Set.List和Map都是接口,它们有各自的实现类.( ...