- 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;
}