Hello 2019题解

题解 CF1097A 【Gennady and a Card Game】

map大法好qwq

枚举每一个的第\(1,2\)位判是否与给定的重复即可

# include <bits/stdc++.h>
std::map<char, int> m1, m2;
int main()
{
std::string s[6], str;
std::cin >> str;
for(int i = 1; i <= 5; i++)
std::cin >> s[i], m1[s[i][0]] = 1, m2[s[i][1]] = 1;
if(m1[str[0]] || m2[str[1]])
return printf("YES\n") * 0;
printf("NO\n");
return 0;
}

题解 CF1097B 【Petr and a Combination Lock】

\(dfs\)入门题,下一个

枚举每一个是正还是负,最后判能不能被\(360\)整除即可

时间复杂度\(O(2^n)\)


# include <bits/stdc++.h> int n, flag, a[20], used[20]; inline void check()
{
int sum = 0;
for(int i = 1; i <= n; i++)
sum += a[i] * (used[i] ? (-1) : 1);
if(sum % 360 == 0)
flag = 1;
} void dfs(int x)
{
if(x == n + 1)
return (void) (check());
dfs(x + 1);
used[x] = 1;
dfs(x + 1);
used[x] = 0;
} int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
dfs(1);
printf(flag ? "YES" : "NO");
return 0;
}

题解 CF1097C 【Yuhao and a Parenthesis】

说起Yuhao,我就不得不提@BlueCat,想起了他旋转**的情景,明年,中美,两开花,关注

对于每个括号序列,我们都用栈预处理出它不能配对的部分

等等?什么叫不能配对的部分?

比如说序列\()())\),\())\)就是它不能配对的部分

然后把这个部分取反

就得到了如果要把这个序列弄成正确的需要的最简序列\(x_i\)

显然这个部分要放在当前串的前面或后面

但是我们有些时候发现这东西是假的

比如这个序列\())))((((\),它的匹配序列是\((((())))\),很明显放前或后都不行,那么这个串就废了

如果这个串没废,就把\(x_i\)的计数累加\(1\)

然后我们枚举每一个\(x_i\),将\(ans\)累加上\(\min{x_i,x_i取反}\)(取反只把一个括号序列中'('变成')',反之亦然)

注意这里有一个特判,如果有一个串本来就是好的,那么统计答案时,由于空串的反串还是空串,所以答案会算两次

所以要特判出好串的个数\(cnt\)

最后输出\(ans/2+cnt/2\)即可(下取整)

#include <bits/stdc++.h>

const int MaxN = 100010, MaxM = 500010;

std::string s[MaxN], str[MaxN];
std::map<std::string, int> m; inline std::string change(std::string s)
{
int len = s.length();
std::string tmp = "";
for (int i = 0; i < len; i++)
tmp += ((s[i] == '(') ? ')' : '(');
return tmp;
} inline int check1(std::string s)
{
std::stack<char> st;
int len = s.length();
for (int i = 0; i < len; i++)
{
if (s[i] == '(')
st.push('(');
else if (s[i] == ')' && st.empty())
return 0;
else
st.pop();
}
return 1;
} inline void check(int x, std::string s)
{
std::vector<char> st;
int len = s.length();
for (int i = 0; i < len; i++)
{
if (st.empty())
{
st.push_back(s[i]);
continue;
}
if (s[i] == '(')
st.push_back('(');
else if (s[i] == ')' && st.back() == '(')
st.pop_back();
else if (s[i] == ')' && st.back() == ')')
st.push_back(')');
}
std::string tmp = "";
for (int i = 0; i < st.size(); i++)
tmp += ((st[i] == '(') ? ')' : '(');
if (check1(tmp + s) || check1(s + tmp))
++m[tmp];
// std::cout << " " << s << " " << tmp << "\n";
} int main()
{
int n, ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
std::cin >> s[i], check(i, s[i]);
for (std::map<std::string, int>::iterator it = m.begin(); it != m.end(); ++it)
{
if (it->first == "")
continue;
ans += std::min(it->second, m[change(it->first)]);
}
printf("%d\n", (ans / 2) + (m[""] / 2));
return 0;
}

Hello 2019题解的更多相关文章

  1. ICPC World Finals 2019 题解

    [A]Azulejos 题意简述: 有两排瓷砖,每排都有 \(n\) 个,每个瓷砖有高度 \(h_i\) 和价格 \(p_i\) 两种属性. 你需要分别重新排列这两排瓷砖,使得同一排的瓷砖满足价格不降 ...

  2. Code Chef February Challenge 2019题解

    传送门 \(HMAPPY2\) 咕 话说这题居然卡\(scanf\)的么??? int T;cin>>T; while(T--){ cin>>n>>a>> ...

  3. CodeChef March Challenge 2019题解

    传送门 \(CHNUM\) 显然正数一组,负数一组 for(int T=read();T;--T){ n=read(),c=d=0; fp(i,1,n)x=read(),x>0?++c:++d; ...

  4. Code Chef April Cook-Off 2019题解

    传送门 \(PEWDSVTS\) 我哪根筋不对了要把所有可行的拿出来\(sort\)一下--还有忘开\(long\ long\)真的好难受-- int main(){ // freopen(" ...

  5. Atcoder Tenka1 Programmer Contest 2019 题解

    link 题面真简洁 qaq C Stones 最终一定是连续一段 . 加上连续一段 # .直接枚举断点记录前缀和统计即可. #include<bits/stdc++.h> #define ...

  6. Atcoder Tenka1 Programmer Contest 2019题解

    传送门 \(C\ Stones\) 最后肯定形如左边一段白+右边一段黑,枚举一下中间的断点,预处理一下前缀和就可以了 int main(){ // freopen("testdata.in& ...

  7. Code Chef January Challenge 2019题解

    传送门 \(div2\)那几道题不来做了太水了-- \(DPAIRS\) 一个显然合法的方案:\(A\)最小的和\(B\)所有连,\(A\)剩下的和\(B\)最大的连 算了咕上瘾了,咕咕咕 const ...

  8. CodeChef April Challenge 2019题解

    传送门 \(Maximum\ Remaining\) 对于两个数\(a,b\),如果\(a=b\)没贡献,所以不妨假设\(a<b\),有\(a\%b=a\),而\(b\%a<a\).综上, ...

  9. AtcoderExaWizards 2019题解

    传送门 \(A\ Regular\ Triangle\) 咕咕 \(B\ Red\ or\ Blue\) 咕咕咕 \(C\ Snuke\ the\ Wizard\) 我可能脑子真的坏掉了-- 容易发现 ...

随机推荐

  1. 编译 Linux 内核 时出现 Restart config 问题

    scripts/kconfig/conf --silentoldconfig Kconfig * * Restart config... * * * Enable the block layer * ...

  2. Bipartite Checking CodeForces - 813F (线段树按时间分治)

    大意: 动态添边, 询问是否是二分图. 算是个线段树按时间分治入门题, 并查集维护每个点到根的奇偶性即可. #include <iostream> #include <sstream ...

  3. 交流绕组 & 感应电机

    交流绕组 1. 为什么整距线圈产生的电动势最大? 整距时, 一个线圈的两根有效导体边之间相差180电角度, 线圈的节距因数为1, 线圈产生的电动势为单根导体边产生电动势的2倍, 为最大 2. 三相交流 ...

  4. Consul微服务的配置中心体验篇

    Spring Cloud Consul 项目是针对Consul的服务治理实现.Consul是一个分布式高可用的系统,具有分布式.高可用.高扩展性 Consul Consul 是 HashiCorp 公 ...

  5. IDEA 导入 NodeJS 项目部署启动

    1.导入项目 2.添加模块 3.配置启动项 4.启动 5.备注 如果不明白,新建一个项目查看配置详情 原文地址:https://blog.csdn.net/tiankongzhichenglyf/ar ...

  6. [v]Linux下安装Git

    Ubuntu12.04中默认没有安装Git.需要自行安装. 1. 安装Git 1.1 Ubuntu12.04下 可以使用apt-get方式安装,也可以下载源代码安装[1],我们这里使用apt-git安 ...

  7. Android NDK 学习之Application.mk

    Application.mk file syntax specification Introduction: This document describes the syntax of Applica ...

  8. 【JUC】1.线程

    先复习一下线程的东西: Java线程的内存模型 主内存与工作内存 Java内存模型主要定义了程序中各个变量的访问规则 所有的变量都在主内存,Java堆(线程共享) 每条线程都有自己的工作内存,虚拟机栈 ...

  9. 解析CentOS 7中系统文件与目录管理

    Linux目录结构 Linux目录结构是树形的目录结构 根目录 所有分区.目录.文件等的位置起点 整个树形目录结构中,使用独立的一个"/"表示 常见的子目录 目录 目录名称 目录 ...

  10. 定制centos6.5自动安装ISO光盘

    一 ISO定制项清单 安装系统为centos6.5 (base server),安装方式为全新安装 使用ext4分区格式 安装前可以交互输入root密码,主机名,swap分区大小,之后安装过程自动化 ...