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 ...
随机推荐
- codeforces B. Island Puzzle
B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Java用sort实现对数组的降序排序
在调用Arrays.sort()对数组进行排序时,默认是升序排序的,如果想让数组降序排序,有下面两种方法: 利用Collections的reverseOrder import java.util.*; ...
- Proximal Algorithms 6 Evaluating Proximal Operators
目录 一般方法 二次函数 平滑函数 标量函数 一般的标量函数 多边形 对偶 仿射集合 半平面 Box Simplex Cones 二阶锥 半正定锥 指数锥 Pointwise maximum and ...
- CLION 使用自己的makefile来运行
之前参考过这里和这里,都是说要使用add_custom_target,无奈看不懂 但是前一篇里说它参考的是stackoverflow上的回答,去原帖里发现后来更新的第二高票答案!!!非常好用!!! 在 ...
- 带SD读卡的USB HUB方案芯片MA8621|用于带读卡的USB HUB拓展坞方案芯片MA8621
MA8621是一款带SD读卡器控制器的USB 2.0高速3端口集线器方案芯片,主要用在USB TYPEC拓展坞或者USB typec扩展底座上面. 1. MA8621功能概述 MA8621是USB 2 ...
- Sentry 企业级数据安全解决方案 - Relay 入门
内容整理自官方开发文档 Sentry Relay 通过提供作为应用程序和 sentry.io 之间中间层的独立服务来提供企业级数据安全性. Relay 专门设计用于: 在将个人身份信息 (PII) 发 ...
- SpringBoot集成MyBatis-Plus代码生成器
1.说明 本文详细介绍Spring Boot集成MyBatis-Plus代码生成器的方法. 基于一个创建好的Spring Boot工程, 执行MyBatis-Plus提供的AutoGenerator代 ...
- [学习笔记] IT项目管理 - 挣值管理(EVM)
挣值管理(EVM) 挣值管理(Earned Value Management, EVM)是成本管理里面较为重点的知识点,但是也可以用来综合考察项目范围.进度和成本绩效,经常需要做相关计算. 基本概念P ...
- shell 之 循环执行某操作
需求: 按月执行201904到202010的py脚本. 代码如下: #!/bin/bash i=201904 # 定义开始月份 while [ $i -le 202010 ] # 当i小于等于2020 ...
- django rest framework 自定义验证器
一.基于钩子函数: 官网上的例子: 官方提示:如果字段声明在序列化类上时,就具有参数required=Fasle的作用,当函数名中没有包括字段名时,那么这个验证函数就不起作用 二.基于类的验证器: 使 ...