Codeforces (ccpc-wannafly camp day2) L. Por Costel and the Semipalindromes
题目链接:http://codeforces.com/gym/100923/problem/L
分析:题目要求序列首尾相同,在此基础上的字典序第k个;因为只存在a,b所以我们把它等效成0和1的话,字典序k也就是二进制下的k,将其最后一位与序列头部相同即可
1 #include<iostream>
2 #include<sstream>
3 #include<cstdio>
4 #include<cstdlib>
5 #include<string>
6 #include<cstring>
7 #include<algorithm>
8 #include<functional>
9 #include<iomanip>
10 #include<numeric>
11 #include<cmath>
12 #include<queue>
13 #include<vector>
14 #include<set>
15 #include<cctype>
16 const double PI = acos(-1.0);
17 const int INF = 0x3f3f3f3f;
18 const int NINF = -INF - 1;
19 typedef long long ll;
20 #define MOD 1000000007
21 using namespace std;
22 typedef pair<int, int> P;
23 ll t, n, ans, temp;
24 int main()
25 {
26 freopen("semipal.in","r",stdin);
27 freopen("semipal.out","w",stdout);
28 ll t;
29 cin >> t;
30 while (t--)
31 {
32 ll n, k;
33 cin >> n >> k;
34 char s[1005];
35 k--;
36 for (int i = n - 2; i >= 0; i--)
37 {
38 if (k % 2) s[i] = 'b';
39 else s[i] = 'a';
40 k /= 2;
41 }
42 s[n-1] = s[0];
43 for (int i = 0; i < n; ++i)
44 cout << s[i];
45 cout << endl;
46 }
47 return 0;
48 }
Codeforces (ccpc-wannafly camp day2) L. Por Costel and the Semipalindromes的更多相关文章
- 【找规律】Gym - 100923L - Por Costel and the Semipalindromes
semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...
- Codeforces 1167c(ccpc wannafly camp day1) News Distribution 并查集模板
题目: In some social network, there are nn users communicating with each other in mm groups of friends ...
- 2020 CCPC Wannafly Winter Camp Day1 C. 染色图
2020 CCPC Wannafly Winter Camp Day1 C. 染色图 定义一张无向图 G=⟨V,E⟩ 是 k 可染色的当且仅当存在函数 f:V↦{1,2,⋯,k} 满足对于 G 中的任 ...
- 【分块打表】Gym - 100923K - Por Costel and the Firecracker
semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...
- 2020 CCPC-Wannafly Winter Camp Day2
2020 CCPC-Wannafly Winter Camp Day2 A 托米的字符串 虽然每个子串出现的概率是相同的,但是同一长度的子串个数是不同的,所以要分别处理.计算出某一长度的情况下,元音字 ...
- 【Heap-dijkstra】Gym - 100923B - Por Costel and the Algorithm
algoritm.in / algoritm.out Even though he isn't a student of computer science, Por Costel the pig ha ...
- 【数形结合】Gym - 100923I - Por Costel and the Pairs
perechi3.in / perechi3.out We don't know how Por Costel the pig arrived at FMI's dance party. All we ...
- 【并查集】Gym - 100923H - Por Costel and the Match
meciul.in / meciul.out Oberyn Martell and Gregor Clegane are dueling in a trial by combat. The fight ...
- 【动态规划】Gym - 100923A - Por Costel and Azerah
azerah.in / azerah.out Por Costel the Pig has received a royal invitation to the palace of the Egg-E ...
随机推荐
- poj3585 Accumulation Degree(树形dp,换根)
题意: 给你一棵n个顶点的树,有n-1条边,每一条边有一个容量z,表示x点到y点最多能通过z容量的水. 你可以任意选择一个点,然后从这个点倒水,然后水会经过一些边流到叶节点从而流出.问你最多你能倒多少 ...
- Codeforces Testing Round #16 C.Skier
题意: 一个人在雪地上滑雪,每次可以向上下左右四个方向移动一个单位,如果这条路径没有被访问过,则需要5秒的时间,如果被访问过,则需要1秒(注意:判断的是两点之间的距离,不是单纯的点).给你他的行动轨迹 ...
- 2020牛客暑期多校训练营(第二场) F.Fake Maxpooling (单调队列)
题意:有一个\(n\)x\(m\)的矩阵,\(A_{i,j}=lcm(i,j)\),对于每个\(k\)x\(k\)的子矩阵,其最大元素贡献给答案,求答案的最大值. 题解:矩阵构成我们直接\(i*j/g ...
- Entity Framework (EF) Core学习笔记 1
1. Entity Framework (EF) Core 是轻量化.可扩展.开源和跨平台的数据访问技术,它还是一 种对象关系映射器 (ORM),它使 .NET 开发人员能够使用面向对象的思想处理数据 ...
- Typora Themes自定义
Typora Themes自定义 Typora 支持css样式,自定义主题十分方便,修改自己的css文件,再放入其themes文件夹,重启Typora,即可看到自定义主题. Typora 官网,自定义 ...
- 大规模数据爬取 -- Python
Python书写爬虫,目的是爬取所有的个人商家商品信息及详情,并进行数据归类分析 整个工作流程图: 第一步:采用自动化的方式从前台页面获取所有的频道 from bs4 import Beautiful ...
- Linux系统CentOS进入单用户模式和救援模式详解
一.概述 目前在运维日常工作中,经常会遇到服务器异常断电.忘记root密码.系统引导文件损坏无法进入系统等等操作系统层面的问题,给运维带来诸多不便,现将上述现象的解决方法和大家分享一下,本次主要以Ce ...
- 关于rand()
虽然很早就知道rand是伪随机了,但是一般都懒得用srand. 直到模拟银行家算法时不用srand就造成数据实在有点假(-_-||) 所以要记得srand((int)time(0))啊
- codeforces 11B Jumping Jack
Jack is working on his jumping skills recently. Currently he's located at point zero of the number l ...
- 前端接收后端文件流导出excel文档遇到的问题
先上代码: Vue.prototype.download = function(oUrl, filename) { this.axios .get(oUrl, { responseType: 'arr ...