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 ...
随机推荐
- 苹果AppStore如何申请加急审核
登录iTunesconnect,点击右上角的“?”图标,选择“联系我们”. iTunes Connect首页 依次选择“App Review”.“App Store Review” .” Reques ...
- JS遍历获取多个控件(使用索引‘i’)
1.n个tid="n1"的input.n个tid="n2"的input.n个tid="n3"的input---循环遍历 ; i <= ...
- js 阿拉伯数字转转汉字
js:(单纯的转汉字,没有个.十.千.万,待我日后完善) var number = 323413290907; var N = [ "零", "一", &quo ...
- POJ3107Godfather(求树的重心裸题)
Last years Chicago was full of gangster fights and strange murders. The chief of the police got real ...
- 生成0-42之间的7个不重复的int值
public static void main(String[] args) { //set集合存储不重复无序的值 Set<Integer> set = new HashSet<In ...
- BZOJ_3124_[Sdoi2013]直径_树形DP
BZOJ_3124_[Sdoi2013]直径_树形DP Description 小Q最近学习了一些图论知识.根据课本,有如下定义.树:无回路且连通的无向图,每条边都有正整数的权值来表示其长度.如果一棵 ...
- 【C++基础】浅拷贝和深拷贝
简单理解: 对于一块内存,浅拷贝只是增加了一个指针,这样两个变量都指向这块内存,二深拷贝则是先开辟一块同等大小的新内存区,将待拷贝内存的内容复制过来,再赋予一个指向新内存的指针.区别在于:浅拷贝会造成 ...
- 字典树Trie的使用
1. Trie树介绍 Trie,又称单词查找树.前缀树,是一种多叉树结构.如下图所示: 上图是一棵Trie树,表示了关键字集合{“a”, “to”, “tea”, “ted”, “ten”, “i”, ...
- 对于makefile传递参数的一些问题
makefile变量说明: 1.总控Makefile中使用“-e”参数覆盖下一层Makefile中的变量. 2.父级Makefile向子级Makefile传送变量方式:export <varia ...
- 如何用CSS实现矩形按钮右边缘的中间有个往里凹的小半圆
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...