codeforces 552 第一次能全做出来DIV2流下了感动的泪水....

#include <iostream>
#include <cstdio>
using namespace std;


/*B*/
/*注意要开长整型.........没别的说的*/
/*
int main()
{
    long long int m;
    scanf("%lld",&m);
    if(m<10) {printf("%d\n",m);return 0;}
    long long int n=m;
    int q=0;
    while(n)
    {
        n=n/10;
        q++;
    }//printf("%d\n",q);
    long long int sum=0;
    long long int w;
    int i;
    for(i=0;i<q-1;i++)
    {
        w=1;
        for(int j=0;j<i;j++) w=w*10;
        sum+=(i+1)*(9*w);
    }
    m=m-10*w;
    m=sum+(i+1)*(m+1);
    printf("%lld\n",m);
    return 0;
}
*/

/*A*/
/*题意很难懂,,但是一看提示就会了.......没啥说的硬算*/
/*
int main()
{
    int m; scanf("%d",&m); int x[101][101]={0};
    int a,b,c,d;
    for(int i=0;i<m;i++)
    {
        scanf("%d %d %d %d",&a,&b,&c,&d);
        for(int j=b;j<=d;j++)
        {
            for(int w=a;w<=c;w++)
            {
                x[j][w]++;
            }
        }

    }
    int sum=0;
    for(int i=0;i<=100;i++)
    {
        for(int j=0;j<=100;j++)
        {
            sum+=x[i][j];
        }
    }
    printf("%d\n",sum);
}
*/

/*C*/
/*用质量w的幂作为砝码看能否称出给出物体的质量,,,,,砝码可左可右......
主要就是把砝码看作进制,将物品转化成这个进制,每一位要么是0(不用砝码)要么是1(用1个)要么是w-1(用1个放左边)*/
/*
int main()
{
    int m,n;
    scanf("%d%d",&m,&n);
    while(n)
    {
        if(n%m==1) n--;
        else if(n%m==0) n=n/m;
        else if(n%m==m-1) n++;
        else {puts("NO"); return 0;}
    }
    puts("YES");
}
*/

/*D*/
/*三点不共线就是一组解*/
/*四秒的时间给的酸爽阿,,,,,一点优化都没有233333333*/
/*
int main()
{
    int a[2001][2];
    int m;
    scanf("%d",&m);
    int i,j;
    for(i=0;i<m;i++)
    {
        scanf("%d%d",&a[i][0],&a[i][1]);
    }
    if(m<3)
    {
        printf("0\n");
        return 0;
    }
    int sum=0;
    for(i=0;i<m-2;i++)
    {
        for(j=i+1;j<m-1;j++)
        {
            for(int l=j+1;l<m;l++)
            {
                if((a[i][0]==a[j][0]&&a[i][0]==a[l][0])||((a[l][1]-a[j][1])*(a[j][0]-a[i][0])==(a[l][0]-a[j][0])*(a[j][1]-a[i][1]))) continue;
                sum++;
            }
        }
    }
    printf("%d\n",sum);
}
*/

/*E*/

/*加一组括号使和最大~~*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include<bits/stdc++.h>
#include <string.h>

using namespace std;

char s[5005];
int n=0;
long long cal(const char *s,int l,int r)
{
    stack<long long> num;
    stack<char> ope;
    ope.push('(');
    for(int i=l;i<=r;i++)
    {
        char c=s[i];
        if(i==r) c=')';
        if(isdigit(c))
        {
            num.push(c-'0');
        }
        else
        {
            if(c=='(')
            {
                ope.push('(');
                continue;
            }
            while(!ope.empty()&&((c==')'&&ope.top()!='(')||(c!=')'&&ope.top()<=c&&ope.top()!='(')))
            {
                long long a=num.top();
                num.pop();
                long long b=num.top();
                num.pop();
                if(ope.top()=='*') num.push(a*b);
                else num.push(a+b);
                ope.pop();
            }
            if(c==')') ope.pop();
            else ope.push(c);
        }
    }
    return num.top();
}

int p[5000],cnt;
char sa[5005];
int main()
{
    s[0]='1';//前后都加上*1这样加括号的时候可以通判不用看首尾
    s[1]='*';
    gets(s+2);
    n=strlen(s);
    s[n++]='*';
    s[n++]='1';
    long long int ans=cal(s,0,n);
    for(int i=0;i<n;i++)
    {
        if(s[i]=='*') p[cnt++]=i;  //标记出现过*的地方
    }
    for(int i=0;i<cnt;i++)
    {
        for(int j=i+1;j<cnt;j++)
        {
            int pos=0;
            for(int k=0;k<n;k++)
            {
                if(k==p[j]) sa[pos++]=')';
                sa[pos++]=s[k];
                if(k==p[i]) sa[pos++]='(';
            }
        sa[pos]=0;
        ans=max(ans,cal(sa,0,pos));
        }

    }
    printf("%lld\n",ans);
 return 0;
}
没啥说的就是四则混合运算但是要熟练额。。。。。。


就这样啦2333333333


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值