【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& ...
随机推荐
- C++与C#数据类型对应关系总结
https://blog.csdn.net/u010159842/article/details/51720458 添加: 1.c++参数含有&,c#也需要用ref关键字. 2.在c++中声明 ...
- hustoj题目标准xml格式
具体格式可见google code. 分析了一下发现像<time_limit></time_limit><memory_limit></memory_limi ...
- 总结get和post区别
参考博文: 浅谈HTTP中Get与Post的区别 1. 数据传递方向: Get是向服务器发索取数据的一种请求,Post是向服务器提交数据的一种请求 (都是请求,并不是一个取一个发) Get:①用于获取 ...
- 图解linux安装tomcat(附常用命令)
本例使用的是centos6.5版本,具体内容如下 一.首先到官方下载tomcat服务 http://tomcat.apache.org/download-70.cgi 二.将tomcat上传至linu ...
- IDEA编译的JAR包运行出现“没有主清单属性”
运行编译好的包出现: 解决方案就是: 确保MANIFEST.MF文件在src/main/resources/META_INF/而不是src/main/java/META_INF/
- binlog2sql数据恢复
牛叉的工具有好几个,包括MyFlash.binlog2Sql.mysqlbinlog_flashback,还有一些收费的等等,各有优劣,具体使用可自行百度 1.安装binlog2sql shell&g ...
- JavaScript 语句标识符,变量周期,常见的HTML事件
语句 描述 break 用于跳出循环. catch 语句块,在 try 语句块执行出错时执行 catch 语句块. continue 跳过循环中的一个迭代. do ... while 执行一个语句块, ...
- matlab imwrite
函数功能:将图像数据写入到图像文件中,存储在磁盘上. 调用格式:imwrite(A,filename,fmt) A是图像数据,filename是目标图像名字,fmt是要生成的图片的格式. 图片格式有: ...
- hdu 1115 Lifting the Stone (数学几何)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 配置ssh
1. 实现只允许特定用户ssh登录 1.1. 直接配置ssh来实现 编辑/etc/ssh/sshd_config,在末尾添加如下一行 AllowUsers user1 user2 user3 然后 ...