E -- XJT Love Digits-----水题

E -- XJT Love Digits

Time Limit:1s Memory Limit:64MByte

Submissions:298Solved:88

DESCRIPTION

Define a function f(x) = the sum of digits of x, such as f(123) = 6. You will be given one sequence a1,a2,a3,...,ana1,a2,a3,...,an, and q queries. Each query contains a number x, you need to output max number p among a1,...,ax,ax1a1,...,ax,ax−1,which satisfies f(p) = f(axax).

INPUT
The first line of input contains an integer T(T5)T(T≤5) indicating the number of test cases.The first line of each case contains two interger n(1n100000)n(1≤n≤100000) and q(1q100000)q(1≤q≤100000).The second line contains n numbers: a1,a2,...an(1ai109)a1,a2,...an(1≤ai≤109).Following q lines, each line contains a integer x(1xn)x(1≤x≤n).
OUTPUT
For each case, output "Case #X:" in a line where X is the case number, staring from 1. Then for each query, output one line. Each line contains one integer p. If there is no such p among a1,...,axa1,...,ax which satisfies f(p) = f( axax), then just output -1.
SAMPLE INPUT
16 61 2 20 11 4 1654321
SAMPLE OUTPUT
Case #1:1-1202-1-1
题目链接:http://www.ifrog.cc/acm/problem/1083?contest=1010&no=4


玲珑杯的水题,没什么好说的。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
struct node{
    int maxn;
    int data;
}xin[200000];
int a[200];
int bit(int n){
    int x=n;
    int ans=0;
    while(x){
        ans+=x%10;
        x/=10;
    }
    return ans;
}
int main(){
    int t;
    scanf("%d",&t);
    int cnt=0;
    while(t--){
        cnt++;
        memset(a,-1,sizeof(a));
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++){
            scanf("%d",&xin[i].data);
            int h=bit(xin[i].data);
            xin[i].maxn=a[h];
            a[h]=max(a[h],xin[i].data);
        }
        printf("Case #%d:\n",cnt);
        for(int i=0;i<m;i++){
            int x;
            scanf("%d",&x);
            printf("%d\n",xin[x].maxn);
        }
    }
    return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值