HDU1296 Polynomial Problem
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的更多相关文章
- 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 ...
- hdu 1296 Polynomial Problem(多项式模拟)
Problem Description We have learned how to obtain the value of a polynomial when we were a middle sc ...
- FZU 2215 Simple Polynomial Problem(简单多项式问题)
Description 题目描述 You are given an polynomial of x consisting of only addition marks, multiplication ...
- FZU2215 Simple Polynomial Problem(中缀表达求值)
比赛时没做出这题太可惜了. 赛后才反应过来这就是个中缀表达式求值,数字栈存的不是数字而是多项式. 而且,中缀表达式求值很水的,几行就可以搞定. #include<cstdio> #incl ...
- 第六届福建省大学生程序设计竞赛(FZU2213—FZU2221)
from:piaocoder Common Tangents(两圆之间的公公切线) 题目链接: http://acm.fzu.edu.cn/problem.php?pid=2213 解题思路: 告诉你 ...
- NOIp初赛题目整理
NOIp初赛题目整理 这个 blog 用来整理扶苏准备第一轮 csp 时所做的与 csp 没 有 关 系 的历年 noip-J/S 初赛题目,记录了一些我从不知道的细碎知识点,还有一些憨憨题目,不定期 ...
- 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 ...
- [codeforces 528]B. Clique Problem
[codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...
- 周赛-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 ...
随机推荐
- js面向(基于)对象编程-三大特征
①抽象 js提供以下几种控制方法和属性的访问权限: (1)公开级别:对外公开 (2)私有级别:类本身可以访问,不对外公开 案例如下所示: function Person(name,age,sal){ ...
- sql中使用timestamp增量抽取数据
网址:http://www.cnblogs.com/shuaifei/p/4469526.html 最近的项目中需要对上百万级的数据进行增量抽取操作,因此了解了一下TIMESTAMP的应用,特此记录 ...
- 2018.3.3 How too much fructose may cause liver damage
Fructose is the sweetest of the natural sugars. As its name suggests, it is found mainly in fruits. ...
- oracle 11g 常用命令
sqlplus system/123@ORCL; 查看oracle字符集: select * from nls_database_parameters where parameter ='NLS_CH ...
- ACM学习历程——HDU5202 Rikka with string(dfs,回文字符串)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- 【C++ Primer 5th】Chapter 15
摘要: 1. 面向对象程序设计的核心思想是数据抽象.继承和动态绑定.数据抽象将类的接口和实现分离:继承定义相似的类型并对齐相似关系建模:动态绑定,在一定程度上忽略相似类型的区别,而以统一的方式使用它们 ...
- RabbitMQ的持久化机制
一.问题的引出 RabbitMQ的一大特色是消息的可靠性,那么它是如何保证消息可靠性的呢?——消息持久化.为了保证RabbitMQ在退出,服务重启或者crash等异常情况下,也不会丢失消息,我们可以将 ...
- Behave + Selenium(Python)一:
Behave 介绍:(来自T先生) 最近一个项目用了behave来做测试,因为之前没有接触过,所以写下最近的心得总结. 做自动化的人估计对selenium已经不是很陌生了,但是对于Behave工具,估 ...
- MFC中界面自适应
void CMyDlg::OnSize(UINT nType, int cx, int cy){ CDialogEx::OnSize(nType, cx, cy); CRect rt; GetClie ...
- 03_通过OpenHelper获取SqliteDatabase对象
MyOpenHelper openHelper = new MyOpenHelper(this); 类似于java的File file = new File();只是声明这个东西,但是文件还并没有真正 ...