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 ...
随机推荐
- ERC20代币(ETH)空投工具-创建代币
代币空投工具地址:http://tool.ethhelp.cn 适用币种: ETH和ERC20代币 使用建议: ERC代币空投,直投,ETH批量转小号 优势介绍: 1.可节省30%手续费 2.转几千地 ...
- 家庭版记账本app开发进度相关界面的规划
总的app界面包括四个页面,页面可以来回滑动.设计的时候就和微信的四个页面类似. 由于没有找到合适的图标进行替换,在此仍应用微信对应的四个图标. 总的四个页面是: 1.增加收入或者支出的小账单.当点击 ...
- NullPointerException的处理新方式,Java14真的太香了
在Java语言中,处理空指针往往是一件很头疼的事情,一不小心,说不定就搞出个线上Bug,让你的绩效考核拿到3.25.最近新出的Java14,相信大家都有所耳闻,那么今天就来看看,面对NullPoint ...
- .net跨域接口服务器端配置
在项目Config文件中添加一下节点配置 <system.webServer> <httpProtocol> <customHeaders> <add nam ...
- SpringMVC中利用HandlerExceptionResolver完成异常处理
在解决Controller层中的异常问题时,如果针对每个异常处理相对较为繁琐.在SpringMVC中提供了HandlerExceptionResolver用于处理捕获到的异常,从而重新定义返回给前端的 ...
- Salesforce学习 | 系统管理员Admin如何添加用户
作为世界排名第一的CRM云计算软件,不管的是500强还是中小企业,越来越多的公司都选择使用Salesforce来分享客户信息,管理和开发具有更高收益的客户关系.Salesforce Administr ...
- 用一个完整的案例讲解Python数据分析的整个流程和基础知识
先来想一下数据分析的流程,第一步获取数据,因此本节内容就是获取数据以及对数据的基本操作. 1.数据导入 1.1 导入.xlsx文件 要导入一个.xlsx后缀的Excel文件,可以使用pd.read_e ...
- 熬夜整理出来的干货:Python+Pycharm+PyQT5可视化程序设计入门
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:朱淑强 PS:如有需要Python学习资料的小伙伴可以加点击下方链接自 ...
- Python 分析后告诉你闲鱼上哪些商品抢手?
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:[Airpython] PS:如有需要Python学习资料的小伙伴可以 ...
- F - Make It Equal CodeForces - 1065C
题目大意:有n座塔,塔高h[i],每次给定高度H对他们进行削切,要求每次削掉的所有格子数不能超过k个,输出最少削几次才能使所有塔的高度相同. 思路一:差分+贪心 对于每一个高度h,用一个数组让1~h的 ...