玲珑OJ 1083:XJT Love Digits(离线处理+哈希)
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(离线处理+哈希)的更多相关文章
- 玲珑oj 1117 线段树+离线+离散化,laz大法
1117 - RE:从零开始的异世界生活 Time Limit:1s Memory Limit:256MByte Submissions:438Solved:68 DESCRIPTION 486到了异 ...
- 玲珑OJ 1082:XJT Loves Boggle(爆搜)
http://www.ifrog.cc/acm/problem/1082 题意:给出的单词要在3*3矩阵里面相邻连续(相邻包括对角),如果不行就输出0,如果可行就输出对应长度的分数. 思路:爆搜,但是 ...
- 九度OJ 1083:特殊乘法 (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4114 解决:2809 题目描述: 写个算法,对2个小于1000000000的输入,求结果. 特殊乘法举例:123 * 45 = 1*4 + ...
- 玲珑OJ 1129 - 喵哈哈村的战斗魔法师丶坏坏い月
1129 - 喵哈哈村的战斗魔法师丶坏坏い月 Time Limit:3s Memory Limit:256MByte Submissions:315Solved:71 DESCRIPTION 坏坏い月 ...
- 玲珑oj 1028 贪心
http://www.ifrog.cc/acm/problem/1028 很有趣的一道题,求从n个数里挑出不同的两个,使得他俩'|','&','^'后的值尽量大,求这个最大的结果. 求最大的异 ...
- 玲珑oj 1121 思维
1121 - Reverse the lights Time Limit:2s Memory Limit:256MByte Submissions:376Solved:111 DESCRIPTION ...
- 玲珑oj 1128 RMQ模板
1128 - 咸鱼拷问 Time Limit:3s Memory Limit:128MByte Submissions:380Solved:118 DESCRIPTION 给你两个序列A,B.每个序列 ...
- 玲珑oj 1129 ST
1129 - 喵哈哈村的战斗魔法师丶坏坏い月 Time Limit:3s Memory Limit:256MByte Submissions:490Solved:107 DESCRIPTION 坏坏い ...
- 值域线段树 (玲珑OJ 1117)
点击打开题目链接 题目意思很简单: 1.插入x 2.把小于x的数变成x 3.把大于x的数变成x 4.求集合中第x小数 5.求集合中小于x的数个数 思路: 线段树,节点是值的分数,你可以离散,也可以不离 ...
随机推荐
- 关于idea maven工程创建struts2入门配置及案例
1.在maven工程下添加需要导入的jar包节点 <dependencies> <dependency> <groupId>org.apache.struts< ...
- eclipse 配置maven tomcat 环境
一 maven配置文件路径 二 tomcat 和JRE位置 三 validation 设置 四 五 六 设置run(debug) configurations 七 添加server时添加 reso ...
- redis 从0到1 linux下的安装使用 数据类型 以及操作指令 一
安装 redis 到 /usr/目录下 我这里安装的是redis-3.2.9.tar.gz tar zxvf redis-3.2.9.tar.gz -C /usr 然后进行 执行编译命令 mak ...
- Sqlite在.NET下的使用和Sqlite数据库清理
原文:Sqlite在.NET下的使用和Sqlite数据库清理 Sqlite 是一款轻量级的关系型数据库,她的好处我就不详细道来了.本文的初衷是为.net平台的使用者提供帮助. Sqlite有专门为VS ...
- 错误:“ResourceDictionary”根元素需要 x:Class 特性来支持 XAML 文件中的事件处理程序。请移除 MouseLeftButtonDown 事件的事件处理程序.
原文:错误:"ResourceDictionary"根元素需要 x:Class 特性来支持 XAML 文件中的事件处理程序.请移除 MouseLeftButtonDown 事件的事 ...
- MASMPlus汇编之简单窗体
.386 .model flat,stdcall option casemap:none ;include 定义 include windows.inc include gdi32.inc i ...
- ML:吴恩达 机器学习 课程笔记(Week9~10)
Anomaly Detection Recommender Systems Large Scale Machine Learning
- ASP.NET Core 通过 Microsoft.DotNet.Watcher.Tools 实现热部署
之前开发前端的时候,webpack 会有热更新工具,在修改了代码之后,自动将代码编译,实时展现到页面上,给开发带来了极大的方便. Java也可以通过第三方插件JRebel实现热部署,不用频繁的重启To ...
- face='Webdings' 的字体对照表
刚才研究动网论坛代码,发现一个页面提示标记 i 感觉很神奇,看了半天才明白原来是一种叫“Webdings”的字体,其实很简单,只需要<font face='webdings' size=&quo ...
- flask(二)
1.装饰器坑 使用装饰器后,视图函数名字相同问题view function错误问题 1.给装饰器加functiontools 2.反向生成url地址标志,指定endpoint(endpoint必须唯一 ...