【BZOJ4104】解密运算 [暴力]
解密运算
Time Limit: 10 Sec Memory Limit: 512 MB
[Submit][Status][Discuss]
Description
对于一个长度为N的字符串,我们在字符串的末尾添加一个特殊的字符"."。之后将字符串视为一个环,从位置1,2,3,...,N+1为起点读出N+1个字符,就能得到N+1个字符串。
Input
Output
输出仅一行,包含N个整数,用空格隔开,依次表示加密前字符串中每个字符的编号。
Sample Input
1 1 1 3 0 1 2
Sample Output
HINT
Solution
显然,按照权值(即这个字符串首字母)为第一关键字,位置(即这个字符后面的串的排名)为第二关键字排序。
然后这时候权值就是矩阵的第一列。
形如:
*ABCD
-----
-----
这时第一行后面ABCD的排名,显然就是读入中*的位置,因为*作为ABCD*的最后一个字符。
比如ABCD*排名为x,那么这时候 A 显然在矩阵第一列中的第x个,输出即可。
Code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
using namespace std;
typedef long long s64; const int ONE = 2e6 + ;
const s64 INF = 1e18; int n, m;
struct power
{
int val, pos;
}a[ONE]; int get()
{
int res=,Q=;char c;
while( (c=getchar())< || c> )
if(c=='-')Q=-;
res=c-;
while( (c=getchar())>= && c<= )
res=res*+c-;
return res*Q;
} int cmp(const power &a, const power &b)
{
if(a.val != b.val) return a.val < b.val;
return a.pos < b.pos;
} int main()
{
n = get(); m = get();
for(int i = ; i <= n + ; i++)
a[i] = (power){get(), i};
sort(a + , a + n + + , cmp); int pos = ;
for(int i = ; i <= n; i++)
{
pos = a[pos].pos;
printf("%d ", a[pos].val);
}
}
【BZOJ4104】解密运算 [暴力]的更多相关文章
- [Thu Summer Camp 2015]解密运算
4104: [Thu Summer Camp 2015]解密运算 Time Limit: 10 Sec Memory Limit: 512 MB Description 对于一个长度为N的字符串,我 ...
- 【BZOJ 4104】 4104: [Thu Summer Camp 2015]解密运算 (智商)
4104: [Thu Summer Camp 2015]解密运算 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 370 Solved: 237 De ...
- BZOJ4104 [Thu Summer Camp 2015]解密运算 【乱搞】
题目链接 BZOJ4104 题解 我们将已知字符排序,由循环就可以得到一个对应关系 如样例就是: 0->第5行 1->第1行 1->第2行 1->第3行 1->第5行 2 ...
- BZOJ4104:[Thu Summer Camp 2015]解密运算——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4104 对于一个长度为N的字符串,我们在字符串的末尾添加一个特殊的字符".".之 ...
- bzoj4104 [Thu Summer Camp 2015]解密运算
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4104 [题解] 脑洞+找规律做出来的.. 我用样例作为说明吧 样例给了我们这个 AAAC.A ...
- CodeForces - 1013B And 与运算暴力
题目链接: https://vjudge.net/problem/1735275/origin 基本思路: 本题思路比较简单,首先,我们知道 a & x = b, b & x = b; ...
- Codeforces 868D Huge Strings - 位运算 - 暴力
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...
- POJ1753 Flip Game(位运算+暴力枚举)
Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 square ...
- 【BZOJ 4104】【Thu Summer Camp 2015】解密运算
http://www.lydsy.com/JudgeOnline/problem.php?id=4104 网上题解满天飞,我也懒得写了 #include<cstdio> #include& ...
随机推荐
- Notes of the scrum meeting before publishing(12.19)
meeting time:18:30~20:30p.m.,December 19th,2013 meeting place:3号公寓一层 attendees: 顾育豪 ...
- Java版office文档在线预览
java将office文档pdf文档转换成swf文件在线预览 第一步,安装openoffice.org openoffice.org是一套sun的开源office办公套件,能在widows,linux ...
- 深入理解Java对象序列化(转载)
原文地址:http://developer.51cto.com/art/201202/317181.htm 1. 什么是Java对象序列化 Java平台允许我们在内存中创建可复用的Java对象,但一般 ...
- 【Docker 命令】- run命令
docker run :创建一个新的容器并运行一个命令 语法: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] OPTIONS说明: -a stdin: 指 ...
- 设置启动窗体Program.cs文件
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; names ...
- QT分析之消息事件机制
原文地址:http://blog.163.com/net_worm/blog/static/127702419201001432028526/ 上回我们分析到QPushButton的初始化,知道了Wi ...
- java-实用的sql语句
一.在数据库创建表格的SQL语句 1,创建一个link表格,包含属性:lid 主键,title 标题, imgpath 图片地址 , url 网址 , info 说明, isshow 显示1 ...
- tc:逼良为娼
tc的学习原来是想着直接从用户态学习的,但是万万没想到哇,qdisc class两个概念直接把我给搞晕了,直接看代码吧 调用:tc qdisc add dev tap0 root handle 1: ...
- ErrorUnable to tunnel through proxy. Proxy returns HTTP1.1 400 Bad Reques
导入项目的时候,一般会出现这种错误,因为我们的gradle版本,不对,所以默认AS导入后,回去下载你需要的gradle,所以很慢, 先打开:项目路径底下的\gradle\wrapper\gradle- ...
- concurrenthashmap jdk1.8
参考:https://www.jianshu.com/p/c0642afe03e0 CAS的思想很简单:三个参数,一个当前内存值V.旧的预期值A.即将更新的值B,当且仅当预期值A和内存值V相同时,将内 ...