玲珑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的数个数 思路: 线段树,节点是值的分数,你可以离散,也可以不离 ...
随机推荐
- java线:辛格尔顿隐藏ThreadLocal实现线程数据共享
效果图分享: A和B需要共享同一线程,还有一组的相同A和B共享还有一组线程,两组相互之间不受影响. 代码: package cn.itcast.lesson6; import java.util.Ra ...
- RPC的发展历史(本质就是双方定义好协议,传递参数后远程调用)
服务器通讯原理就是一台socket服务器A,另一台socket客户端B,现在如果要通讯的话直接以流方式写入或读出. 这样能实现通讯,但有个问题.如何知道更多信息?比如需要发送流大小,编码,Ip等. 这 ...
- 2-16 mysql主从复制
1. 部署MYSQL主从同步 <M-S> 环境:mysql版本一致,均为5.7.18 master xuegod4 ip 192.168.10.34 数据库密码 yourpassw ...
- JAVASCRIPT高程笔记-------第五章 引用类型
一.Object类型 1.1创建方式 ①new关键字 : var person = new Oject(); ②给定直接量: var person = { name : "zhangsan& ...
- WPF 验证错误模板
<Window x:Class="BindingExam.MainWindow" xmlns="http://schemas.microsoft.co ...
- liunx 查看php 安装的扩展
/usr/local/php5/bin/php -i |less 查看配置文件在哪里,编译参数 /usr/local/php5/bin/php -m |less 查看php加载的模块
- VS生成Cordova for Android应用之Gradle
原文:VS生成Cordova for Android应用之Gradle 一.Gradle简介 Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化建构工具.它使用一种基 ...
- 小记同学一次奇葩的DNS欺骗实验失败经历
这是一个DNS欺骗实验,使用kali的ettercap.有受害者.攻击者(虚拟机).Web服务器三台机器.受害者的事124.16.70.105虚拟机的是124.16.71.48web服务器是124.1 ...
- android中优雅实现recyclerview
在慕课网上看了Abner_泥阿布老师不一样的RecyclerView优雅实现复杂列表布局这个视频课程,本人在Ubuntu16.04LTS下使用android studio2.2.3按照老师讲解写的代码 ...
- Cindy components(配色很不错)
https://sourceforge.net/projects/tcycomponents/