Codeforces 1323 div2题解ABC
A. Even Subset Sum Problem
签到题
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 20005
#define rep(i, j, n) for (int i = j; i <= n; i++)
#define red(i, n, j) for (int i = n; i >= j; i--)
#define fil(a, n) rep(i, 0, n, ) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
vector<int> a[2];
int main()
{
int t, n, x;
read(t);
while (t--)
{
a[0].clear();
a[1].clear();
read(n);
rep(i, 1, n + 1)
{
read(x);
x %= 2;
a[x].push_back(i);
}
if (!a[0].empty()){
puts("1");
wi(a[0][0]),P;
}
else if (a[1].size() > 1)
puts("2");
wi(a[1][0]),wi(a[1][1] ),P;
else
puts("-1");
}
return 0;
}
B. Count Subrectangles
当时没做出来:
预处理:
首先统计 a序列和 b序列 的所有连续 1 区间长度, a 序列第 i 个连续 1 的区间length 为Ai ,b 序列第 i 个连续 1 的区间length 为Bi
考虑 k 的每一个约数 d。
则有, d×kd 这个矩形的个数就是 (Ai−d+1) *(Bi−kd+1) ,对k的每一个因子d计算后求和即可。
解答:
然后排序后二分输出。
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 20005
#define rep(i, j, n) for (int i = j; i <= n; i++)
#define red(i, n, j) for (int i = n; i >= j; i--)
#define fil(a, n) rep(i, 0, n, ) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
const int N = 4e4 + 100;
int a[N], b[N];
vector<pair<int, int>> node;
void init(int k)
{
for (int i = 1; i * i <= k; i++)
{
if (k % i == 0)
{
node.push_back(make_pair(i, k / i));
if (i != k / i)
node.push_back(make_pair(k / i, i));
}
}
}
unordered_map<int, int> A, B;
void solve(int a[], int n, unordered_map<int, int> &mp)
{
int pos = 1, cnt = 0;
while (pos <= n)
{
while (a[pos])
{
pos++;
cnt++;
}
if (cnt)
{
mp[cnt]++;
cnt = 0;
}
pos++;
}
}
int main()
{
int n, m, k;
read(n), read(m), read(k);
init(k);
rep(i, 1, n + 1)
read(a[i]);
rep(i, 1, m + 1)
read(b[i]);
solve(a, n, A);
solve(b, m, B);
LL ans = 0;
rep(k, 0, node.size())
{
int x = node[k].first, y = node[k].second;
LL xx = 0, yy = 0;
for (auto it : A)
if (it.first >= x)
xx += it.second * (it.first - x + 1);
for (auto it : B)
if (it.first >= y)
yy += it.second * (it.first - y + 1);
ans += xx * yy;
}
wi(ans), P;
return 0;
}
C. Unusual Competitions
我觉得这个题应该和B换一换
这个题把左括号看成-1,右括号看成1,如果前缀和小于0即存在单独的右括号,需要重排。
然后找到所有前缀和为负的连续段包括最后一个0,计算长度和就行。
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 20000005
#define rep(i, j, n) for (int i = j; i <= n; i++)
#define red(i, n, j) for (int i = n; i >= j; i--)
#define fil(a, n) rep(i, 0, n, ) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
string s;
int a[N], n, ans = 0;
int main()
{
read(n);
cin >> s;
rep(i, 0, n)
{
a[i] = a[i - 1] + (s[i] == '(' ? -1 : 1);
}
if (a[n - 1] != 0)
puts("-1");
else
{
rep(i, 0, n) ans += (a[i] < 0) + (a[i] < 0 && a[i - 1] >= 0);
wi(ans),P;
}
return 0;
}
Codeforces 1323 div2题解ABC的更多相关文章
- codeforces #275 div2题解
A题大意: 给你l,r,问你在l~r之间,是否存在 a和b互质 , b和c互质 ,但是 a,c不互质 的情况:其中l<=a<b<c<=r;如果存在,就输出a,b,c;不存在就输 ...
- Codeforces ECR50 div2题解
A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...
- Codeforces Round #707 Editorial Div2 题解
CF1501 Div2 题解 CF1501A 这道题其实是一道英语阅读题,然后样例解释又不清晰,所以我看了好久,首先它告诉了你每个站点的预期到达时间 \(a_i\) ,以及每个站点的预期出发时间 \( ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces Round #556 题解
Codeforces Round #556 题解 Div.2 A Stock Arbitraging 傻逼题 Div.2 B Tiling Challenge 傻逼题 Div.1 A Prefix S ...
随机推荐
- MTK Android Camera新增差值
一. 计算需要的插值 如果原有的插值列表没有我们需要的插值的时候,要通过计算算出符合需求的插值,比如2700W的插值. 具体计算方法如下: 假设像素的长宽分别为X,Y,则插值为XY.由于MTK规定各参 ...
- C++ memset函数用法
#include<stdio.h>#include<string.h>int main(){ char buffer[] = "I love you!"; ...
- 34.1 字符流-- FileRead FileWrite
一次读取一个字符 FileReader fr = new FileReader("aa.txt"); // System.out.println(fr.read()); // Sy ...
- 28.3 api--date 日期 (日期获取、格式化)
/* * Date: 表示特定的瞬间,精确到毫秒,他可以通过方法来设定自己所表示的时间,可以表示任意的时间 * System.currentTimeMillis():返回的是当前系统时间,1970-1 ...
- Python-selenium-自动化测试模型
1.线性测试 优势:每一个脚本都是完整独立的,每一个脚本对应一个测试用例 缺点:开发成本高,会有重复操作重复脚本:维护成本也高,修改重复操作的脚本时,要逐一进行修改. 2.模块化驱动测试 把重复的操作 ...
- K - Downgrade Gym - 101775K
题目大意:一天不玩相当于A-B中将A转换为经验值,B舍弃掉,然后A=1,在通过升级所需要的经验值来判断可以升几级 题目连接:https://codeforces.com/gym/101775/prob ...
- C#开发BIMFACE系列34 服务端API之模型对比5:获取模型构件对比差异
系列目录 [已更新最新开发文章,点击查看详细] BIMFACE平台提供了服务端“获取修改构件属性差异”API,其返回的结果也是一个列表,仅针对修改的构件(不包含新增.删除的构件),是指对于一个 ...
- SUCTF 2019 Upload labs 2 踩坑记录
SUCTF 2019 Upload labs 2 踩坑记录 题目地址 : https://github.com/team-su/SUCTF-2019/tree/master/Web/Upload La ...
- 用 Python 黄图批量鉴别审核
前言 最近写了一款微信小程序需要用到图片审核,人工审核是不可能的人工审核的太费精力了,所以我就写了一个多线程批量识别脚本来处理,主要是调用百度AI的接口,这里我是付费了也不贵审核一条1分钱不到,再说我 ...
- 国外程序员整理的 PHP 资源大全
原文:http://blog.jobbole.com/82908/ ziadoz 在 Github 发起维护的一个 PHP 资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具 ...