2015多校第四场两水题(2015 Multi-University Training Contest 4)


原谅我就只会这两水题了,其他题没怎么看~估计看了也是无奈

Olympiad

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 234    Accepted Submission(s): 171


Problem Description
You are one of the competitors of the Olympiad in numbers. The problem of this year relates to beatiful numbers. One integer is called beautiful if and only if all of its digitals are different (i.e. 12345 is beautiful, 11 is not beautiful and 100 is not beautiful). Every time you are asked to count how many beautiful numbers there are in the interval  [a,b] (ab) . Please be fast to get the gold medal!
 

Input
The first line of the input is a single integer  T (T1000) , indicating the number of testcases. 

For each test case, there are two numbers  a  and  b , as described in the statement. It is guaranteed that  1ab100000 .
 

Output
For each testcase, print one line indicating the answer. 
 

Sample Input
   
   
2 1 10 1 1000
 

Sample Output
   
   
10 738
 

Author
XJZX
 

Source
 

Recommend
wange2014
 

1001:
题意:  beautiful numbers的定义:就是一个数的每一位不能有相同的数字,现在给你一个区间,让你求这区间内有多少个这样的漂亮数

思路方法:打表,预处理前n个数有多少个漂亮数,然后求解时直接输出
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#define N 100010
typedef long long LL;
using namespace std;
int p[N],a[12];
void init(){
    p[0]=0;
    for(int i=1;i<100010;i++){
        int ok=1;
        memset(a,0,sizeof(a));
        int x=i;
        while(x){
            //cout<<x<<endl;
            a[x%10]++;
            x/=10;
        }
        for(int j=0;j<10;j++){
            if(a[j]>=2) ok=0;
        }
        if(ok) p[i]=p[i-1]+1;
        else p[i]=p[i-1];
    }
}
int main(){
    init();
    int T;
    scanf("%d",&T);
    while(T--){
        int l,r;
        scanf("%d%d",&l,&r);
        printf("%d\n",p[r]-p[l-1]);
    }
    return 0;
}

Problem Killer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 470    Accepted Submission(s): 194


Problem Description
You are a "Problem Killer", you want to solve many problems. 
Now you have  n  problems, the  i -th problem's difficulty is represented by an integer  ai  ( 1ai109 ).
For some strange reason, you must choose some integer  l  and  r  ( 1lrn ), and solve the problems between the  l -th and the  r -th, and these problems' difficulties must form an AP (Arithmetic Progression) or a GP (Geometric Progression). 
So how many problems can you solve at most?

You can find the definitions of AP and GP by the following links:
https://en.wikipedia.org/wiki/Arithmetic_progression
https://en.wikipedia.org/wiki/Geometric_progression
 

Input
The first line contains a single integer  T , indicating the number of cases. 
For each test case, the first line contains a single integer  n , the second line contains  n  integers  a1,a2,,an

T104,n106
 

Output
For each test case, output one line with a single integer, representing the answer.
 

Sample Input
   
   
2 5 1 2 3 4 6 10 1 1 1 1 1 1 2 3 4 5
 

Sample Output
   
   
4 6
 

Author
XJZX
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5338  5337  5336  5335  5334 


题意:在一个长度为n的序列中取出连续的k个数,让这k个数组成等差数列或者等比数列,问这样的k最大可以是多少。

思路方法:当时和几个队友在讨论,然后他们在讨论暴力n^2是否会超时,结果时肯定的。然后我的第一想法是想到用前n相和去枚举判断,然后可以通过每次求到的k的大小去去除后面无须判断的数据,然后算了下复杂度是介于n~n方,当时以为是不会超的,然后还是太年轻。。后来后来就发现其实是可以先开出两个数组,算出每一项与前一项的公差和公比,然后就会发现,此题就可以转化为求最长相同的子序列,复杂度为O(n)。(!!注:C++ TLE,G++ AC,不要问我为什么,我也不知道)
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#define N 1000010
#define eps 1e-8
#define INF 0x3f3f3f3f
typedef long long LL;
using namespace std;
double a[N],b[N],c[N];

int main(){
    int T,n;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%lf",&c[i]);
        }
        if(n==0||n==1||n==2){
            printf("%d\n",n);
            continue;
        }
        for(int i=2;i<=n;i++){
            a[i]=c[i]-c[i-1];
            b[i]=c[i]/c[i-1];
        }
        a[1]=b[1]=INF;
        int ans=2;
        double t=a[1],tot=0;
        for(int i=1;i<=n;i++){
            if(fabs(a[i]-t)<=eps){
                tot++;

            }else{
                tot=1;
                t=a[i];
            }
            if(ans<tot+1) ans=tot+1;
        }
        t=a[1],tot=0;
        for(int i=1;i<=n;i++){
            if(fabs(b[i]-t)<=eps){
                tot++;

            }else{
                tot=1;
                t=b[i];
            }
            if(ans<tot+1) ans=tot+1;
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值