HDU5831(水题,有一点容易忽略,导致一直WAWAWA)
2016-08-12 20:17
369 查看
http://acm.hdu.edu.cn/showproblem.php?pid=5831
从开始数,如果‘ ) ’的出现数量减去‘ ( ’大于等于3,则就不可能通过一次交换操作使得这多出来的三个‘ ) ’完全符合题目的要求字符串类别。于是我就直接写了,就WA了。不知错在何处!然后看了同学写的才考虑到了,'( )'这种情况是No,因为一次也不能交换,题目要求交换一次。
我的天吶...
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long LL;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define MAX_N 10000
//#define LOCAL
int main()
{
#ifdef LOCAL
freopen("b:\\data.in.txt", "r", stdin);
#endif
int T; scanf("%d", &T);
while(T--)
{
int n;
scanf("%d", &n);
char a;
int cnt1 = 0, cnt2 = 0;
bool ans = 0;
if(n == 2)
{
char s[3];
for(int i = 0; i<2; i++)
{
cin >>s[i];
}
if(s[0] == ')' && s[1] == '(')
{
cout << "Yes" << endl;
}
else
cout << "No" << endl;
continue;
}
for(int i = 0; i < n; i++)
{
cin >> a;
if(a == '(')
cnt1++;
if(a == ')')
cnt2++;
if(cnt2 - cnt1 >= 3)
ans = 1;
}
if(cnt1 != cnt2)
ans = 1;
if(ans)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
从开始数,如果‘ ) ’的出现数量减去‘ ( ’大于等于3,则就不可能通过一次交换操作使得这多出来的三个‘ ) ’完全符合题目的要求字符串类别。于是我就直接写了,就WA了。不知错在何处!然后看了同学写的才考虑到了,'( )'这种情况是No,因为一次也不能交换,题目要求交换一次。
我的天吶...
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long LL;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define MAX_N 10000
//#define LOCAL
int main()
{
#ifdef LOCAL
freopen("b:\\data.in.txt", "r", stdin);
#endif
int T; scanf("%d", &T);
while(T--)
{
int n;
scanf("%d", &n);
char a;
int cnt1 = 0, cnt2 = 0;
bool ans = 0;
if(n == 2)
{
char s[3];
for(int i = 0; i<2; i++)
{
cin >>s[i];
}
if(s[0] == ')' && s[1] == '(')
{
cout << "Yes" << endl;
}
else
cout << "No" << endl;
continue;
}
for(int i = 0; i < n; i++)
{
cin >> a;
if(a == '(')
cnt1++;
if(a == ')')
cnt2++;
if(cnt2 - cnt1 >= 3)
ans = 1;
}
if(cnt1 != cnt2)
ans = 1;
if(ans)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
相关文章推荐
- 导致线程死锁容易忽略的一点 SendMessage
- 摘要:我们经常会用到递归函数,但是如果递归深度太大时,往往导致栈溢出。而递归深度往往不太容易把握,所以比较安全一点的做法就是:用循环代替递归。文章最后的原文里面讲了如何用10步实现这个过程,相当精彩。本文翻译了这篇文章,并加了自己的一点注释和理解。
- 在JZ2440板上关于一直Boa服务器的一点心得总结
- DSO激活请求时因为服务器断电导致一直黄灯,作业手动取消后,黄灯一直还在
- Java基础(容易忽略的java细节)
- asp.net初学者容易忽略的问题
- Javascript兼容性问题小结(容易导致浏览器不同,又不容易察觉的)
- Jupyter Notebook远程访问配置中容易犯错的一点
- Oracle数据库模糊查询语句一个容易忽略的结果:空记录
- 好吧我承认最近一直入门python! 关于python3 和 python2 List 的一点区别 以及python 通过enumerate 内建函数遍历List
- Web测试中容易被忽略的Charset问题
- java中容易忽略的shuffle用法
- 说一说z-index容易被忽略的那些特性
- 不常用≠没用 Win7容易忽略的四个功能
- CSS布局时容易出的小错误,导致浏览器不兼容或者各种不显示
- 新手在sae部署程序容易忽略的一个细节
- 软件架构设计时容易忽略的几个重要问题
- git容易被忽略的准备工作命令
- 深入研究mysql中的varchar和limit(容易被忽略的知识)
- 针对vector,map几点容易忽略的点做一说明