暴力求解练习

  • UVA-11059 求乘积最大的连续子序列
  • 打表
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define ll long long
#define DEBUG
const int maxn=20+5,maxv=26,INF=0x3f3f3f3f,mod=100000000;
ll v[maxn],dp[maxn][maxn];
int main(){
#ifdef DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n,kase=0;
    while(cin>>n){
        kase++;
        ll ans=0;
        int l,r;
        for(int i=0;i<n;i++){
            cin>>v[i];
        }
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                if(j==i)dp[i][j]=v[i];
                else dp[i][j]=dp[i][j-1]*v[j];
                if(dp[i][j]>ans){ans=dp[i][j];l=i;r=j;}
            }
        }
        printf("Case #%d: The maximum product is %lld.\n\n",kase,ans);
    }
#ifdef DEBUG
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}


  • UVA-725 不重复的除法表达式

long long还是绕不过去的一个坑

#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define LL long long
#define DEBUG
const int maxn=12+5,maxv=26,INF=0x3f3f3f3f,mod=100000000;
int v[10];
bool ok(LL a,int m){
    LL r=a;
    for(int i=0;i<10;i++)v[i]=0;
    while(m--){
        if(v[r%10])return false;
        else v[r%10]=1;
        r=r/10;
    }
    if(r)return false;
    return true;
}
int main(){
#ifdef DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n;
    int t=0;
    while(cin>>n&&n){
        if(t++) printf("\n");
        bool flag=0;
        for(int i=1234;i<50000;i++){
            if(ok(i,5)&&ok(i*n,5)&&ok((i*n*(LL)100000+i),10))printf("%05ld / %05ld = %d\n",i*n,i,n),flag=1;
        }
        if(!flag)
            printf("There are no solutions for %d.\n",n);
    }
    return 0;
#ifdef DEBUG
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值