全部题目跳转链接

A - The Miracle and the Sleeper

题意

给定\([l, r]\) 求出在这个区间内的两个数字ab的取模的最大值 (\(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倍关系的二进制串 0xxxxxxxxxxxx
    • 在前半段的时候, 我们可以分割成两个成2倍关系的二进制串 xxxxxx0xxxxxx
  • 0 不存在时候, 我们可以分割成两个成1倍关系的二进制串 111111111111 (全是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)的更多相关文章

  1. Codeforces Round #741 (Div. 2), problem: (D1) Two Hundred Twenty One (easy version), 1700

    Problem - D1 - Codeforces 题意: 给n个符号(+或-), +代表+1, -代表-1, 求最少删去几个点, 使得     题解(仅此个人理解): 1. 这题打眼一看, 肯定和奇 ...

  2. Codeforces Round #741 (Div. 2)部分题题解

    我果然还是太菜了,就写了两道题....真是水死了.... A The Miracle and the Sleeper 简化题意:给定\(l,r\),求\(a\)%\(b\)的最大值,其中\(r> ...

  3. 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 ...

  4. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  5. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  6. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  7. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 一站式元数据治理平台——Datahub入门宝典

    随着数字化转型的工作推进,数据治理的工作已经被越来越多的公司提上了日程.作为新一代的元数据管理平台,Datahub在近一年的时间里发展迅猛,大有取代老牌元数据管理工具Atlas之势.国内Datahub ...

  2. pandas tutorial

    目录 Series 利用dict来创建series 利用标量创建series 取 Dataframe 利用dict创建dataframe 选择 添加列 列移除 行的选择, 添加, 移除 Panel B ...

  3. uniapp跳转webview后H5不执行UniAppJSBridgeReady 回调无用

    开始时我在真机上测试使用 <web-view :src="'/hybrid/html/pages/index/index.html?userInfo='+JSON.stringify( ...

  4. [开发配置]Linux系统配置开发环境

    deeplin系统配置开发环境 开发系统:deeplin 15.11 开发工具:Clion 2019.2 ; PyCharm 2019 ; Idea 2019;  Android Studio 开源库 ...

  5. Linux_Cornd任务调度

    Crond任务调度 进行定时任务的设置 概述 任务调度:是指系统在某个时间执行特定的命令或程序 作用:避免重复工作 基本语法 crontab [选项] 选项 功能 -e 编辑crontab定时任务 - ...

  6. VUE的学习_从入门到放弃(一)

    一.vue的功能及作用 工作方式如下 1.不用操作DOM 2.单页面应用web项目 简称:SPA 3.当下各种新框架都采用的类似Vue或者类似React的语法去作为主语法,微信小程序/MpVue... ...

  7. CVE-2021-45232 Apache APISIX 从未授权访问到RCE

    00x1漏洞环境 Apache APISIX Dashboard 2.7 - 2.10 版本受到影响 通过git拉取在docker搭建环境 git clone https://github.com/a ...

  8. PHP DateTime类常用方法总结

    实例化: $date = new DateTime(); $date = new DateTime('2018-01-01'); $date = new DateTime('tomorrow'); $ ...

  9. Jedis 连接池的基本使用

    jedis直连 每次操作都会创建一个jedis对象,执行完毕后关闭连接后释放,对应的就是一次Tcp连接. jedis连接池 预先生成一批jedis连接对象放入连接池中,当需要对redis进行操作时从连 ...

  10. alias 中使用 awk

    alias hehistory10='history |awk "{print \$2}"|sort|uniq -c|sort -rn|head -10' alias lv='ls ...