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 ...
随机推荐
- 多线程mtr-代码
#!/bin/env python # -*- coding: utf-8 -*- # @Date : 2015-09-06 11:30:48 # @Author : Your Name (you@e ...
- 1067 Bash 游戏v2
传送门 1067 Bash游戏 V2 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次只能拿1,3,4颗,拿到最后1颗石子的人 ...
- javaCV入门指南:序章
前言 从2016年6月开始写<javacv开发详解>系列,到而今的<javacv入门指南>,虽然仅隔了两年多时间,却也改变了很多东西. 比如我们的流媒体技术群从刚开始的两三个人 ...
- css3渐变gradient
参考: http://www.w3cplus.com/content/css3-gradient
- 洛谷 P4512 [模板] 多项式除法
题目:https://www.luogu.org/problemnew/show/P4512 看博客:https://www.cnblogs.com/owenyu/p/6724611.html htt ...
- linux——boot空间不足
1. 先用df命令,查看磁盘分区情况 2. dpkg --get-selections|grep linux-image(查看更新了多少内核) root@ubuntu:/home/hadoop# dp ...
- JS---计算两个日期之间相差多少天
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 绝对路径VS相对路径
绝对路径:不必赘述,就是从盘符开始写直到找到你所需要的文件为止,把所有的目录写完整即可.但是在做网站的时候绝对不推荐用绝对路径,因为不可能服务器中的路径和在做设计时候所用的电脑的路径一致,也不可能说在 ...
- jquery中对于批量deferred的处理
此代码仿照jquery源码中$.when()的实现 function test(i) { var dfd = $.Deferred(); if(i%2 == 0) { console.log(&quo ...
- [hiho第92周]Miller-Rabin素性测试的c++实现
证明: 如果n是素数,整数$a$ 与$n$ 互素,即$n$ 不整除$a$ ,则${a^{n - 1}} \equiv 1(\bmod n)$ ,如果能找到一个与$n$ 互素的整数$a$ ,是的上式不成 ...