http://acm.hdu.edu.cn/showproblem.php?pid=1296

随手练习

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
int n;
char s[];
ll Solve(string s,int i)
{
ll num=;
int l=i-;
int r=i+;
string s1="";
while(s[l]>=''&&s[l]<='')
{
s1+=s[l];
l--;
}
reverse(s1.begin(),s1.end());
ll ans=;
ll sum=;
int len=s1.length();
for(int j=; j<len; j++)
{
ans*=;
ans+=(s1[j]-'');
}
if(ans==){
ans=; }
if(s[r]=='^')
{
r++;
while(s[r]>=''&&s[r]<='')
{
sum*=;
sum+=(s[r]-'');
r++;
}
ll pos=n;
for(int j=; j<sum; j++)
{
pos*=n;
}
num+=pos*ans;
}
else
{
num+=ans*n;
}
i=r;
if(s[l]=='-')
{
num*=-;
}
return num;
}
int main()
{
while(~scanf("%d",&n))
{
ll x=;
scanf("%s",s);
int len=strlen(s);
if((s[]>=''&&s[]<='')||s[]=='X')
{
string s1="";
int i=;
int pos=;
int flag=;
for(i=; s[i]!='+'&&s[i]!='-'&&i<len; i++)
{
s1+=s[i];
if(s[i]=='X')
{
flag=;
pos=i;
}
}
if(flag)
{
x+=Solve(s1,pos);
flag=;
}
else
{
ll ans=;
for(int j=; j<s1.length(); j++)
{
ans*=;
ans+=(s1[j]-'');
}
x+=ans;
}
for(int j=i; j<len;)
{
if(s[j]=='-'||s[j]=='+')
{
string s2="";
s2+=s[j];
j++;
int ans=;
while(s[j]!='-'&&s[j]!='+'&&j<len)
{
s2+=s[j];
ans++;
if(s[j]=='X')
{
pos=ans;
flag=;
}
//cout<<s[j]<<endl;
j++;
}
if(flag)
{
x+=Solve(s2,pos);
flag=;
}
else
{
ll ans=;
for(int j=; j<s2.length(); j++)
{
ans*=;
ans+=(s2[j]-'');
}
if(s2[]=='-')
{
ans*=-;
}
x+=ans;
}
flag=;
}
}
cout<<x<<endl;
}
else
{
int flag=;
int pos=;
string s3="";
s3+=s[];
int i;
for(i=; s[i]!='-'&&s[i]!='+'&&i<len; i++)
{
s3+=s[i];
if(s[i]=='X')
{
flag=;
pos=i;
}
}
if(flag)
{
x+=Solve(s3,pos);
flag=;
}
else
{
ll ans=;
for(int j=; j<s3.length(); j++)
{
ans*=;
ans+=(s3[j]-'');
}
if(s3[]=='-')
{
ans*=-;
}
x+=ans;
}
flag=;
for(int j=i; j<len;)
{
if(s[j]=='-'||s[j]=='+')
{
string s2="";
s2+=s[j];
j++;
int ans=;
while(s[j]!='-'&&s[j]!='+'&&j<len)
{
s2+=s[j];
ans++;
if(s[j]=='X')
{
pos=ans;
flag=;
}
//cout<<s[j]<<endl;
j++;
}
if(flag)
{
x+=Solve(s2,pos);
flag=;
}
else
{
ll ans=;
for(int j=; j<s2.length(); j++)
{
ans*=;
ans+=(s2[j]-'');
}
if(s2[]=='-')
{
ans*=-;
}
x+=ans;
}
flag=;
}
}
cout<<x<<endl;
}
}
return ;
}

HDU1296 Polynomial Problem的更多相关文章

  1. Polynomial Problem(hdu 1296 表达式求值)

    We have learned how to obtain the value of a polynomial when we were a middle school student. If f(x ...

  2. hdu 1296 Polynomial Problem(多项式模拟)

    Problem Description We have learned how to obtain the value of a polynomial when we were a middle sc ...

  3. FZU 2215 Simple Polynomial Problem(简单多项式问题)

    Description 题目描述 You are given an polynomial of x consisting of only addition marks, multiplication ...

  4. FZU2215 Simple Polynomial Problem(中缀表达求值)

    比赛时没做出这题太可惜了. 赛后才反应过来这就是个中缀表达式求值,数字栈存的不是数字而是多项式. 而且,中缀表达式求值很水的,几行就可以搞定. #include<cstdio> #incl ...

  5. 第六届福建省大学生程序设计竞赛(FZU2213—FZU2221)

    from:piaocoder Common Tangents(两圆之间的公公切线) 题目链接: http://acm.fzu.edu.cn/problem.php?pid=2213 解题思路: 告诉你 ...

  6. NOIp初赛题目整理

    NOIp初赛题目整理 这个 blog 用来整理扶苏准备第一轮 csp 时所做的与 csp 没 有 关 系 的历年 noip-J/S 初赛题目,记录了一些我从不知道的细碎知识点,还有一些憨憨题目,不定期 ...

  7. CF #296 (Div. 1) B. Clique Problem 贪心(构造)

    B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. [codeforces 528]B. Clique Problem

    [codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...

  9. 周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏

    Integration of Polynomial Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...

随机推荐

  1. jQuery 获取有多个class名的元素

    HTML内容: <div class="write-upload"> <p class="write-files old-files"> ...

  2. hdu-5793 A Boring Question(二项式定理)

    题目链接: A Boring Question Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java ...

  3. 国内镜像pip

    建议非清华大学校内的使用这个镜像: http://e.pypi.python.org/simple(这也是一个http://pypi.v2ex.com/simple),清华校内的就使用这个:http: ...

  4. 「USACO15FEB」「LuoguP3121」审查(黄金)Censoring (Gold)(AC自动机

    题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they h ...

  5. ACM学习历程—HDU 1276 士兵队列训练问题(队列)

    Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠 拢,再从头开始进行一至三报数,凡 ...

  6. [SHOI 2017] 分手是祝愿

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4872 [算法] 首先发现 , 对于一个开关 , 按下2次和没按是等价的 , 因此每个 ...

  7. 使用Tornado作为Django App的服务器

    闲来无事,折腾折腾. 老是听说tonado是个异步web框架和服务器,作为框架倒是了解到了,但是服务器一直不太懂.所以决定了解一下,既然可以做服务器,那就把自己的django app部署到这上边去. ...

  8. 简单两步快速实现shiro的配置和使用,包含登录验证、角色验证、权限验证以及shiro登录注销流程(基于spring的方式,使用maven构建)

    前言: shiro因为其简单.可靠.实现方便而成为现在最常用的安全框架,那么这篇文章除了会用简洁明了的方式讲一下基于spring的shiro详细配置和登录注销功能使用之外,也会根据惯例在文章最后总结一 ...

  9. linux 中spfvim安装

    1. 安装 git 1.1 安装依赖的包: curl          curl-devel     zlib-devel         openssl-devel      perl      c ...

  10. Ubuntu下Apache重启错误:Could not reliably determine解决

    错误信息:apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 ...