首页 > 其他分享 >hdu Polynomial Problem

hdu Polynomial Problem

时间:2023-07-18 19:34:48浏览次数:36  
标签:hdu str int len flag num && Polynomial Problem


 

有点杂乱无章,考虑各种情况就行了。

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define INF 0x3fffffff
#define MAXN 100001

int main()
{
    int n,m, x, flag, mul, ans;
    char str[MAXN];
    while(~scanf("%d",&x)){
        scanf("%s",str);
        int len = strlen(str);
        int num = -INF;
        flag = 1;
        ans = 0;
        for(int i = 0; i < len; i++){
            if(str[i] == '-'){
                flag = 0;
                if(i + 1 < len && str[i + 1] == 'X')num = 1;
                continue;
            }
            if(str[i] == '+'){
                flag = 1;
                if(i + 1 < len && str[i + 1] == 'X')num = 1;
                continue;
            }
            if(str[i] == 'X'){
                if(i-1<0)num = 1;
                if(!flag)num = -num;flag = 1;
                if((i + 1 < len && str[i+1] != '^')||i+1>=len)ans += num*x, num = -INF;
                continue;
            }
            if(i - 1 >= 0 && str[i] >= '0' && str[i] <= '9' && str[i-1]== '^'){
                if(i + 1 < len && str[i+1] >= '0' && str[i+1]<= '9'){
                    mul = (str[i] -'0')*10 + str[i+1] - '0';
                    i++;
                }
                else mul = str[i] -'0';
                if(!flag)num = -num;flag = 1;
                int mid = x;
                for(int j = 2; j <= mul; j++){
                    mid *= x;
                }
                ans += num * mid;
                num = -INF;
                continue;
            }
            if(str[i] >= '0' &&str[i] <= '9'){
                if(num == -INF)num = str[i] - '0';
                else num = num*10 + str[i] - '0';
            }

        }
        if(num != -INF){
            if(!flag)num = -num;
            ans += num;
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

标签:hdu,str,int,len,flag,num,&&,Polynomial,Problem
From: https://blog.51cto.com/u_16192154/6767465

相关文章

  • hdu 1010 Tempter of the Bone (dfs+奇偶剪枝)
    小记:最开始以为是T时间内,用bfsWA了,后来知道是刚好T时间,然后就用dfs,相当于暴力了,然后简单的dfs提交TLE,必须剪枝。首先判最少需要的时间是否有,没有就不用继续了,而如果有,那么因为我们是要花掉T时间刚好到达,那么我们先保证能走到终点的时间,然后在路上花掉多余的时间此时,我们必须保证......
  • 题解 Yet Another Minimization Problem
    YetAnotherMinimizationProblem神仙题。第一眼看上去就是DP。定义\(f_{i,j}\)表示当前点\(i\),分\(j\)段的最小费用。\(f_{i,j}=\min(f_{i,j},f_{k,j-1}+val_{k+1,i})\)然后发现复杂度\(O(n^2k)\),直接T飞,需要优化。我们发现\(j\)那一维可以滚掉,也就是只考虑第......
  • 题解 HDU5726【GCD】/ LGT353762【Soso 的最大公约数】
    Problem给你一个长为\(N(1\leqN\leq1\times10^5)\)的整数序列:\(a_{1},\cdots,a_{n}(0<a_{i}\leq1\times10^9)\)。有\(Q(1\leqQ\leq1\times10^5)\)次提问。每次提问有个范围\(l,r\),你需要计算出\(\gcd(a_{l},,a_{l+1},...,a_{r})\),并且统计数对\((l’,r’......
  • 解决报错Cannot connect to the Maven process. Try again later. If the problem per
    故障描述:使用idea下载java某个源文件,idea报错:CannotconnecttotheMavenprocess.Tryagainlater.Iftheproblempersists,checktheMaven解决方案:修改maven的配置文件......
  • Mac环境下 罗技 Logi Options+ Backend Connection Problem
    m1芯片MacBook,安装LogiOptions+。打开后一直提示Backendconnectionproblem-clickheretolaunchbackend。报错图片如下 查询后得知,是一个启动程序没有打开。解决方案如下:下载一个AppCleaner&Uninstaller,软件官网:(AppCleaner&Uninstaller-DownloadfromOffic......
  • 【题解】CF gym 104337 G. Guess the Polynomial
    statement:https://codeforces.com/gym/104337/problem/G。即求\(f(x)=\sum\limits_{i=0}^{p-2}a_ix^i\),其中只有不超过\(n\)个\(a_i\)非\(0\)。记:\[\begin{aligned}A_{n}^{k}&=\sum_{i\equivk\pmod{n}}a_i=\frac{1}{n}\sum_{i=0}^{n-1}f(\omega_{n}^{......
  • POJ3468 A Simple Problem with Integers
    ASimpleProblemwithIntegers题目链接:ASimpleProblemwithIntegers题意给定\(N\)个数,可以选择\([l,r]\),让下标在区间内的值都增加一定值,或者输出下标在区间内元素的和。思路可以用带懒标记的线段树写,但是代码太长,不利于编写。这里有一个利用差分借助树状数组实现的写法......
  • 1002 A+B for Polynomials C++
    Thistime,youaresupposedtofind A+B where A and B aretwopolynomials.InputSpecification:Eachinputfilecontainsonetestcase.Eachcaseoccupies2lines,andeachlinecontainstheinformationofapolynomial:K N1​ aN1​​ N2​ aN2​​ ......
  • 【cs50】lab7 & problem set7
    (1)lab7songssqlite3songs.db1)listthenamesofallsongsinthedatabaseSELECTnameFROMsongs;2)listnamesofallsongsinincreasingorderoftempoSELECTnameFROMsongsORDERBYtempo;3) listthenamesofthetop5longests......
  • L11U3-3 Dealing with flight problems
    1ExpressionsFlightproblemsListentodiscussbadnewshereceivesabouthisflight.hasbeendelayed.mechanicalproblems.hasbeencanceledduetomaintenanceissues.It'simportantthatyouunderstandmessagesaboutflightproblemswhetheryoug......