http://www.ifrog.cc/acm/problem/1083

题意:比较好懂。注意答案的x不包含ax本身,所以才输出-1。

思路:离线处理。根据x排序,然后每次更新Hash[]数组就好了。

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
#define N 100010
#define INF 0x3f3f3f3f
struct P {
int x, id;
} ask[N];
int Hash[N], p[N], ans[N]; bool cmpx(const P &a, const P &b) { if(a.x == b.x) return a.id < b.id; return a.x < b.x; } int get(int num) {
int ans = ;
while(num) {
ans += num % ;
num /= ;
}
return ans;
} int main()
{
int t, cas = ;
scanf("%d", &t);
while(t--) {
int n, q;
scanf("%d%d", &n, &q);
for(int i = ; i <= n; i++)
scanf("%d", &p[i]);
for(int i = ; i <= q; i++) {
scanf("%d", &ask[i].x);
ask[i].id = i;
}
sort(ask + , ask + q + , cmpx);
printf("Case #%d:\n", cas++);
memset(Hash, -, sizeof(Hash));
int j = , now;
for(int i = ; i <= q; i++) {
while(ask[i].x > j && j <= n) {
now = get(p[j]);
Hash[now] = max(Hash[now], p[j]);
j++;
}
now = get(p[ask[i].x]);
if(Hash[now] == -) ans[ask[i].id] = -;
else ans[ask[i].id] = Hash[now];
}
for(int i = ; i <= q; i++) printf("%d\n", ans[i]);
}
return ;
}

玲珑OJ 1083:XJT Love Digits(离线处理+哈希)的更多相关文章

  1. 玲珑oj 1117 线段树+离线+离散化,laz大法

    1117 - RE:从零开始的异世界生活 Time Limit:1s Memory Limit:256MByte Submissions:438Solved:68 DESCRIPTION 486到了异 ...

  2. 玲珑OJ 1082:XJT Loves Boggle(爆搜)

    http://www.ifrog.cc/acm/problem/1082 题意:给出的单词要在3*3矩阵里面相邻连续(相邻包括对角),如果不行就输出0,如果可行就输出对应长度的分数. 思路:爆搜,但是 ...

  3. 九度OJ 1083:特殊乘法 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4114 解决:2809 题目描述: 写个算法,对2个小于1000000000的输入,求结果. 特殊乘法举例:123 * 45 = 1*4 + ...

  4. 玲珑OJ 1129 - 喵哈哈村的战斗魔法师丶坏坏い月

    1129 - 喵哈哈村的战斗魔法师丶坏坏い月 Time Limit:3s Memory Limit:256MByte Submissions:315Solved:71 DESCRIPTION 坏坏い月 ...

  5. 玲珑oj 1028 贪心

    http://www.ifrog.cc/acm/problem/1028 很有趣的一道题,求从n个数里挑出不同的两个,使得他俩'|','&','^'后的值尽量大,求这个最大的结果. 求最大的异 ...

  6. 玲珑oj 1121 思维

    1121 - Reverse the lights Time Limit:2s Memory Limit:256MByte Submissions:376Solved:111 DESCRIPTION ...

  7. 玲珑oj 1128 RMQ模板

    1128 - 咸鱼拷问 Time Limit:3s Memory Limit:128MByte Submissions:380Solved:118 DESCRIPTION 给你两个序列A,B.每个序列 ...

  8. 玲珑oj 1129 ST

    1129 - 喵哈哈村的战斗魔法师丶坏坏い月 Time Limit:3s Memory Limit:256MByte Submissions:490Solved:107 DESCRIPTION 坏坏い ...

  9. 值域线段树 (玲珑OJ 1117)

    点击打开题目链接 题目意思很简单: 1.插入x 2.把小于x的数变成x 3.把大于x的数变成x 4.求集合中第x小数 5.求集合中小于x的数个数 思路: 线段树,节点是值的分数,你可以离散,也可以不离 ...

随机推荐

  1. TemplatePart用法说明

    原文:TemplatePart用法说明 TemplatePart(Name="PART_Decrease", Type=typeof(RepeatButton)) 一直没明白这是干 ...

  2. Xamarin 弹窗

    包括通知类弹窗和选择类弹窗,以下是安卓手机的显示效果 关键代码 DisplayAlert("Alert", "You have been alerted", & ...

  3. WPF - Group分组对ListBox等列表样式的约束

    原文:WPF - Group分组对ListBox等列表样式的约束 在做WPF主题支持时,出现一个分组引起的莫名错误,可是折腾了我一番.在没有使用样式时,列表分组很正常,使用了别人写的ListBox列表 ...

  4. 向WPF的Grid里面增加控件

    在c#中,有时需要通过代码创建面板控件,但是对于面板的操作与之前的控件并不是很直观,因此记下方法,以供后来复习使用: 创建两行两列的表格: 第一种方法: Grid grid = new Grid(); ...

  5. C# Thread 参数

     Thread (ParameterizedThreadStart) 初始化 Thread 类的新实例,指定允许对象在线程启动时传递给线程的委托.   Thread (ThreadStart) 初 ...

  6. wcf 代理实例

    通过过代理调用 wcf服务 using Microsoft.Extensions.Options; using System; using System.Collections.Generic; us ...

  7. Visual Studio 2015 和 Apache Cordova 跨平台开发入门

    原文:Visual Studio 2015 和 Apache Cordova 跨平台开发入门(一) 基于 Windows 10 的 Visual Studio 2015 跨平台的应用开发主要分为基于V ...

  8. 图像滤镜艺术----Brannan滤镜

    原文:图像滤镜艺术----Brannan滤镜     作为第一篇文章,本人将介绍Instagram中Brannan 滤镜的实现过程,当然,是自己的模拟而已,结果差异敬请谅解.     先看下效果图: ...

  9. EPPlus导出两千万行记录到xlsx的c#代码

    private void button5_Click(object sender, EventArgs e) { Stopwatch watch = new Stopwatch(); Backgrou ...

  10. Redis实现Timeline

    上回写了[使用Redis实现关注关系][1],这次说说使用Redis实现Timeline. Timeline的实现一般有推模式.拉模式.推拉结合这几种. 推模式:某人发布内容之后推送给所有粉丝,空间换 ...