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的更多相关文章

  1. codeforces #275 div2题解

    A题大意: 给你l,r,问你在l~r之间,是否存在 a和b互质 , b和c互质 ,但是 a,c不互质 的情况:其中l<=a<b<c<=r;如果存在,就输出a,b,c;不存在就输 ...

  2. Codeforces ECR50 div2题解

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  3. Codeforces Round #707 Editorial Div2 题解

    CF1501 Div2 题解 CF1501A 这道题其实是一道英语阅读题,然后样例解释又不清晰,所以我看了好久,首先它告诉了你每个站点的预期到达时间 \(a_i\) ,以及每个站点的预期出发时间 \( ...

  4. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  5. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  6. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  7. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  8. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  9. Codeforces Round #556 题解

    Codeforces Round #556 题解 Div.2 A Stock Arbitraging 傻逼题 Div.2 B Tiling Challenge 傻逼题 Div.1 A Prefix S ...

随机推荐

  1. ssh秘钥免交互批量分发脚本

    将以下内容保存为.sh文件后运行即可,需根据各自情况修改ip_up和ip_arr #!/bin/bash #脚本功能:ssh秘钥免交互批量分发 #制 作 人:罗钢 联系方式:278554547@qqc ...

  2. MTK Android 权限大全

    Android权限大全 1.android.permission.WRITE_USER_DICTIONARY允许应用程序向用户词典中写入新词 2.android.permission.WRITE_SY ...

  3. DataAnalysis-SOP

    一.关于数据分析 a. 互联网最热职位:研发工程师.产品经理.人力资源.市场营销.运营.数据分析(供不应求) b. 数据分析的步骤:明确目的/思路.数据收集.数据处理.数据分析.数据展现 c. 数据分 ...

  4. OS-DOS/CMD/Windows/各类软件快捷键等使用总结

    一.快捷键 很多软件的快捷键使用相通,在不确定的情况下,先试试其他软件的快捷键的使用方法 Windows电脑快捷键 HP惠普笔记本 win+E 打开文件管器 win+D 显示桌面 win+L 锁计算机 ...

  5. "文字链接"组件:<h-link> —— 快应用组件库H-UI

     <import name="h-link" src="../Common/ui/h-ui/basic/c_link"></import&g ...

  6. 宏定义#define和内联函数inline的区别

    1 宏定义在预编译的时候进行字符串替换.内联函数在编译的时候进行函数展开. 2 宏定义没有类型检查.内联函数会进行参数列表.返回值等类型检查.

  7. git如何清除远程 __pycahce__ 文件

    第一步,清除已经存在的缓存文件 >> git rm -r -f --cached */__pycache__ rm 'common/__pycache__/__init__.cpython ...

  8. docker 概览 (1)

    Docker Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows 机器上,也可以实现虚拟化.容器是完全使 ...

  9. Treasure Island DFS +存图

    All of us love treasures, right? That's why young Vasya is heading for a Treasure Island. Treasure I ...

  10. D - Romantic

    The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Trees Trees ar ...