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. uboot初体验-----趣谈nand设备发起的浅显理解

    1 选择Uboot版本号 2 移植uboot至console正常work 3 制造uImage和使用uboot指南 4 写NFC驱动器 5 uboot从nand启动引导系统 1 选择Uboot版本号 ...

  2. BZOJ 3329 Xorequ 数字DP+矩阵乘法

    标题效果:特定n,乞讨[1,n]内[1,2^n]差多少x满足x^3x=2x x^3x=2x相当于x^2x = 3x 和3x=x+2x 和2x=x<<1 因此x满足条件IFFx&(x ...

  3. js css加时间戳

    为了强制更新文件,取消浏览器缓存 <link rel="stylesheet" href="~/XXX.css?time='+new Date().getTime( ...

  4. DotNetBar for Windows Forms 14.0.0.15_冰河之刃重打包版发布

    关于 DotNetBar for Windows Forms 14.0.0.15_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版------------- ...

  5. js 指向表格行变色,离开恢复

    <!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  6. wpf 路由事件 代码片段

    <?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http: ...

  7. C# dotnetcore2.0结合Selenium搜索网页

    using System; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; namespace ConsoleApp_Selenium { c ...

  8. C# Oracle数据库操作类

    using System; using System.Data; using System.Collections.Generic; using System.Configuration; using ...

  9. duilib禁止標題欄雙擊放大窗口

    創建窗口函數中使用UI_WNDSTYLE_DIALOG CMainWnd *win = new CMainWnd(_T("main_win.xml")); win->Crea ...

  10. Mysql下载(on windows-noinstall zip archive)

    所有内容,都是针对Mysql5.7.18介绍. 1.首先你需要下载一个完整的包,Mysql目前有两个版本可以使用: a. MySql Enterprise Edition:企业版 b. MySql C ...