bnuoj 29368 Check the Identity(栈)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=29368
【题解】:模拟,然后对x,进行枚举,看是否所有都满足条件
【code】:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <list>
#include <string>
#include <string.h> using namespace std; double stack[];
int s_cnt; double fabs(double a)
{
return a>?a:-a;
} char op[];
int len; int checkRight(double x)
{
int i;
s_cnt = -;
for(i=;i<len;i++)
{
char ch = op[i];
if(ch=='x')
{
s_cnt++;
stack[s_cnt] = x;
}
else if(ch=='s')
{
stack[s_cnt] = sin(stack[s_cnt]);
}
else if(ch=='c')
{
stack[s_cnt] = cos(stack[s_cnt]);
}
else if(ch=='t')
{
stack[s_cnt] = tan(stack[s_cnt]);
}
else if(ch=='-')
{
stack[s_cnt-] = stack[s_cnt-] - stack[s_cnt];
s_cnt--;
}
else if(ch=='+')
{
stack[s_cnt-] = stack[s_cnt]+stack[s_cnt-];
s_cnt--;
}
else if(ch=='*')
{
stack[s_cnt-] = stack[s_cnt]*stack[s_cnt-];
s_cnt--;
}
}
if(fabs(stack[])>1e-) return ;
return ;
} int main()
{
int t,cas=;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int i;
char str[];
s_cnt = -;
len = ;
for(i=;i<n;i++)
{
scanf("%s",str);
op[len] = str[];
len++;
}
double l=-,r=;
double step = 4.0/;
int flag=;
for(;l<=r;l++)
{
if(!checkRight(l))
{
flag=;
break;
}
}
printf("Case %d: ",cas++);
if(!flag)
{
puts("Yes");
}
else
{
puts("No");
}
}
return ;
}
bnuoj 29368 Check the Identity(栈)的更多相关文章
- BNU29368:Check the Identity(栈)
Just determine whether an algebraic expression can always simplify to zero. Input The first line con ...
- 【ASP.NET Identity系列教程(二)】运用ASP.NET Identity
注:本文是[ASP.NET Identity系列教程]的第二篇.本系列教程详细.完整.深入地介绍了微软的ASP.NET Identity技术,描述了如何运用ASP.NET Identity实现应用程序 ...
- ASP.NET Identity 二 (转载)
来源:http://www.cnblogs.com/r01cn/p/5180892.html#undefined 推荐看原文,这里转载是怕好文章消失了. 注:本文是[ASP.NET Identity系 ...
- ASP.NET Identity系列教程-3【运用ASP.NET Identity】
https://www.cnblogs.com/r01cn/p/5180892.html 14 运用ASP.NET Identity In this chapter, I show you how t ...
- 关于refs/for/ 和refs/heads/
1. 这个不是git的规则,而是gerrit的规则, 2. Branches, remote-tracking branches, and tags等等都是对commite的引用(re ...
- CLR via C# 3rd - 05 - Primitive, Reference, and Value Types
1. Primitive Types Any data types the compiler directly supports are called primitive types. ...
- [转]Installing SharePoint 2013 on Windows Server 2012 R2
转自:http://www.avivroth.com/2013/07/09/installing-sharepoint-2013-on-windows-server-2012-r2-preview/ ...
- 《Effective C#》:区别和认识四个判等函数
.Net有四个判等函数?不少人看到这个标题,会对此感到怀疑.事实上确是如此,.Net提供了ReferenceEquals.静态Equals,具体类型的Equals以及==操作符这四个判等函数.但是这四 ...
- 【转】区别和认识.Net四个判等函数
原文地址:不详 .Net有四个判等函数?不少人看到这个标题,会对此感到怀疑.事实上确是如此,.Net提供了ReferenceEquals.静态Equals,具体类型的Equals以及==操作符这四个判 ...
随机推荐
- 简单遗传算法求解n皇后问题
版权声明:本文为博主原创文章,转载请注明出处. 先解释下什么是8皇后问题:在8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同一列或同一斜线上,问有多少种摆法.在不 ...
- .net求两个数的最大公约数和最小公倍数
最大公约数:指两个或多个整数共有约束中最大的一个. 最小公倍数:如果有一个自然数a能被自然数b整除,则称a为b的倍数,b为a的约数,对于两个整数来说,指该两数共有倍数中最小的一个. /// <s ...
- 自定义实现简单的Android颜色选择器(附带源码)
在写Android App过程中需要一个简单的颜色选择器,Android自带的ColorPicker和网上的一些ColorPicker都太高端了,都实现了颜色渐变功能,我要的不需要那么复杂,只想提供几 ...
- js中小数的操作及数字类型的验证
1.丢弃小数部分,保留整数部分js:parseInt(7/2) 2.向上取整,有小数就整数部分加1js: Math.ceil(7/2) 3,四舍五入. js: Math.round(7/2) 4,向下 ...
- asp.net中C#获取字符串中汉字的个数实例
符串可以包括数字,字母,汉字或者其他的字符.使用Char类型的IsDigit静态方法可以判断字符串中的字符是否为数字,使用Char类型中的 IsLetter静态方法可以判断字符串中是否为字母.我们来实 ...
- [转]WCF 4 安全性和 WIF 简介
转自:http://www.cnblogs.com/WizardWu/archive/2010/10/04/1841793.html 本帖简介 .NET 新一代的 Windows Identity ...
- dispatch_async & dispatch_sync
Clear that! dispatch_async 是将block发送到指定线程去执行,当前线程不会等待,会继续向下执行. dispatch_sync 也是将block发送到指定的线程去执行,但是当 ...
- (转)优化tomcat,提高网站运行速度
网站优化方案: 网站优化有很多方面,这里我们先主要讲讲 tomcat优化.[主要针对tomcat6.0及以上版本] 1. 为jvm增加更多的内存,tomcat安装时,默认为126M,可以设置. To ...
- (转)Redis 集群方案
根据一些测试整理出来的一份方案: 1. Redis 性能 对于redis 的一些简单测试,仅供参考: 测试环境:Redhat6.2 , Xeon E5520(4核)*2/8G,1000M网卡 Redi ...
- QQ音乐API分析记录
我一直是QQ音乐的用户,最近想做一个应用,想用QQ音乐的API,搜索了很久无果,于是就自己分析QQ音乐的API. 前不久发现QQ音乐出了网页版的,是Flash的,但是,我用iPhone打开这个链接的时 ...