E -- XJT Love Digits-----水题
来源:互联网 发布:网站数据安全如何保证 编辑:程序博客网 时间:2024/06/06 01:12
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 sequencea1,a2,a3,...,ana1,a2,a3,...,an, and q queries. Each query contains a number x, you need to output max number p amonga1,...,ax,ax−1a1,...,ax,ax−1,which satisfies f(p) = f(axax).
INPUT
The first line of input contains an integerT(T≤5)T(T≤5) indicating the number of test cases.The first line of each case contains two intergern(1≤n≤100000)n(1≤n≤100000) and q(1≤q≤100000)q(1≤q≤100000).The second line contains n numbers: a1,a2,...an(1≤ai≤109)a1,a2,...an(1≤ai≤109).Following q lines, each line contains a integer x(1≤x≤n)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 amonga1,...,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
玲珑杯的水题,没什么好说的。
代码:
#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
- E -- XJT Love Digits-----水题
- "玲珑杯”ACM比赛 Round #8-E XJT Love Digits(递推)
- 玲珑学院 - -1083 - XJT Love Digits
- [玲珑杯#Round8] XJT Love Strings KMP+树上倍增
- KMP,LCA(XJT Love Strings,玲珑杯 Round#8 A lonlife 1079)
- 左偏树(XJT Love Trees,玲珑杯 Round#8 C lonlife 1081)
- 258-e-Add Digits
- E - I Love You Too解题报告
- MUTC 3 E - Triangle LOVE 图论/搜索
- E文积累_20071212_All's fair in love and war
- E - I Love You Too解题报告(陈渊)
- E - I Love You Too解题报告(张宇)
- 【HDU 5082】【水题】Love
- 水题-kblack love flags
- Love
- LOVE
- love
- Love
- bzoj 3993: [SDOI2015]星际战争 (二分+最大流)
- 使用springmvc下载文件
- Doctype & 严格模式与混杂模式
- 品味慢生活,少一点急躁、多一点从容
- 自定义view之继承控件
- E -- XJT Love Digits-----水题
- SSH学习(三)Struts2之Action下
- 17 - 04 - 08 Web安全(04)
- XML学习
- 学习笔记:Zookeeper 应用案例(上下线动态感知)
- /usr/bin/ld: cannot find -llapack
- 来自北邮人的大牛校招准备经验分享:17届大牛学长分享:如何集齐BAT三家offer
- hi3559笔记
- jsp中表单提交方法和获取对应值,jsp登录页面