Problem Description 
We have learned how to obtain the value of a polynomial when we were a middle school student. If f(x) is a polynomial of degree n, we can let.If we have x, we can get f(x) easily. But a computer can not understand the expression like above. So we had better make a program to obtain f(x).

Input 
There are multiple cases in this problem and ended by the EOF. In each case, there are two lines. One is an integer means x (0<=x<=10000), the other is an expression means f(x). All coefficients ai(0<=i<=n,1<=n<=10,-10000<=ai<=10000) are integers. A correct expression maybe likes  1003X^5+234X^4-12X^3-2X^2+987X-1000

Output 
For each test case, there is only one integer means the value of f(x).

Sample Input 

1003X^5+234X^4-12X^3-2X^2+987X-1000

Sample Output 
264302

Notice that the writing habit of polynomial f(x) is usual such as 
X^6+2X^5+3X^4+4X^3+5X^2+6X+7 
-X^7-5X^6+3X^5-5X^4+20X^3+2X^2+3X+9 
X+1 
X^3+1 
X^3 
-X+1 etc. Any results of middle process are in the range from -1000000000 to 1000000000.

自己写的超丑,查了一年的bug,最后发现是多组数据而我只写了一组.........哭了

 #include <iostream>
#include <cstdio>
#include <string.h>
#include <math.h>
#include <algorithm>
#define MIN(x,y) ((x)>(y))?(y):(x)
#define MAX(x,y) ((x)>(y))?(x):(y) using namespace std; const int inf = 0x3f3f3f3f;
const double dinf = 0xffffffff;
const int vspot = ;
const int espot = ;
typedef long long ll; int bit[];
int x, weishu, cnt;
ll ans;
int bound;
bool e;
bool positive; long long getNum()
{
if( !weishu )
{
if(positive)
return ;
else
return -;
} ll num = ;
int k = weishu;
for( int i = ; i < k; i++ )
{
weishu--;
ll zhishu = ;
for( int j = ; j < weishu; j++ )
zhishu *= ;
num += (long long)(bit[i]*zhishu);
} if(positive)
return num;
else
return -num;
} bool check()
{
if ( cnt == bound )
return true;
return false;
} int main()
{ while( cin >> x )
{
string ads, str = "+";
cin >> ads; cnt = ;
e = false;
ans = ; if ( ads[]=='-' )
str = ads;
else
str += ads; bound = str.size() - ; while(true)
{
////////////////////符号部分////////////////////
if ( str[cnt++]=='+' )
positive = true;
else
positive = false; //////////////////////因数ai部分///////////////////
weishu = ;
memset( bit, -, sizeof(bit) );
while(true)
{
if ( str[cnt]>='' && str[cnt]<='' )
{
if ( check() )
{
e = true;
bit[weishu++] = str[cnt]-'';
ans += getNum();
break;
}
else
bit[weishu++] = str[cnt++]-'';
}
else
break;
}
if (e)
break;
//////////////X^x部分//////////////////////
ll ai = getNum();
int cishu = ;
if( check() )
e = true;
else
{
if ( str[cnt+] == '^' )
{
cnt++; cnt++;
if ( str[cnt]>='' && str[cnt]<='' )
cishu = str[cnt]-'';
else
{ cishu = ; cnt++;}
}
}
if ( check() )
e = true;
else
cnt++;
//////////////计算部分/////////////////////////
ll temp = ;
for( int i = ; i < cishu; i++ )
temp *= x;
ans += ai*temp;
if (e)
break;
}
cout << ans << endl;
}
return ;
}

再看看 别人写的.........我............我好菜呀QAQ

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const nMax = ;
#define sf scanf
#define pf printf
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
char s[nMax];
int x;
#define ll long long
ll go(int &i)
{
int a,b,c;
a = ;
b = ;
if(s[i] == '-') a*=-,i++;
if(s[i] == '+') i++;
while(s[i]>='' && s[i]<='')
{
b = b* + s[i]-'';
i++;
}
if(b==) b = ;//这句就是应证X+1
c = ;
if(s[i] == 'X')
{
i++;
if(s[i]=='^')
{
i++; c = ;
while(s[i]>='' && s[i]<='')
{
c = c* + s[i] - '';
i ++;
}
}
else
{
c = ;
}
}
ll ret = ;
ret = (ll)a*b;
for(int i=; i<c; i++) ret *= x;
return ret;
}
int main()
{
while(cin >> x >> s)
{
int i = ;
int l = strlen(s);
ll ans = ;
while(i<l)
{
ans += go(i);
}
cout << ans << endl;
}
return ;
}

hdu 1296 Polynomial Problem(多项式模拟)的更多相关文章

  1. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  2. HDU 5867 Water problem (模拟)

    Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...

  3. HDOJ/HDU 1022 Train Problem I(模拟栈)

    Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...

  4. HDU 1022 Train Problem I 模拟栈题解

    火车进站,模拟一个栈的操作,额外的栈操作,查看能否依照规定顺序出栈. 数据量非常少,故此题目非常easyAC. 直接使用数组模拟就好. #include <stdio.h> const i ...

  5. HDU 5867 Water problem ——(模拟,水题)

    我发这题只是想说明:有时候确实需要用水题来找找自信的~ 代码如下: #include <stdio.h> #include <algorithm> #include <s ...

  6. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  7. HDU 3549 Flow Problem(最大流)

    HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...

  8. hdu 5106 Bits Problem(数位dp)

    题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...

  9. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

随机推荐

  1. Extjs4 desktop 图标自动换行,横纵排列 图标大小修改

    一.图标换行 /*! * Ext JS Library 4.0 * Copyright(c) 2006-2011 Sencha Inc. * licensing@sencha.com * http:/ ...

  2. x64:x64

    ylbtech-x64:x64 “x86-64”,有时会简称为“x64”,是64位微处理器架构及其相应指令集的一种,也是Intel x86架构的延伸产品.“x86-64”1999由AMD设计,AMD首 ...

  3. System.Web.Mvc.ModelValidationResult.cs

    ylbtech-System.Web.Mvc.ModelValidationResult.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutr ...

  4. 左神算法书籍《程序员代码面试指南》——1_01设计一个有getMin功能的栈

    [题目] 实现一个特殊的栈,在实现栈的基本功能的基础上,再实现返回栈中最小元素的操作. [要求] 1.pop.push.getMin操作的时间复杂度都是O(1).2.设计的栈类型可以使用现成的栈结构. ...

  5. ASP.NET MVC生命周期与管道模型

      先来熟悉下asp.net请求管道 1.当客户端发送http://localhost:80/home/index请求时 2.首先到达服务端的内核模块HTTP.SYS(它监听80端口),通过访问注册表 ...

  6. Java基础(业务问题)

    幂等的处理方式 一.查询与删除操作是天然幂等 二.唯一索引,防止新增脏数据 三.token机制,防止页面重复提交 四.悲观锁  for update 五.乐观锁(通过版本号/时间戳实现, 通过条件限制 ...

  7. C#墨攻IOC[转]

    原文叫看<墨攻>理解IOC概念 2006年多部贺岁大片以让人应接不暇的频率纷至沓来,其中张之亮的<墨攻>算是比较出彩的一部,讲述了战国时期墨家人革离帮助梁 国反抗赵国侵略的个人 ...

  8. xshell添加脚本

    ##### xshell添加脚本```属性连接 - 用户身份验证 - 登陆脚本 - 添加等待:[usmshell]$发送:open 212 //212是指188那台机器的ID再添加一个等待:passw ...

  9. 你所不知道的Mac截图的强大

    Mac的截图功能扩展功能很强大的,不要用QQ那个COM+Ctrl+A弱爆了的截图了~ 首先说一下两种截图 1.Command+shift+3:全屏截图,保存截图到桌面 2.Command+shift+ ...

  10. 善用 NuGet 程序包管理器控制台

    每种集成开发环境都会提供扩展包的下载与安装,VS (微软可视化集成开发环境) 下的叫程序包管理控制台,我们把他叫做<牛干 程序包管理控制台>. 在 工具=>NuGet 程序包管理器= ...