123 A. Prime Permutation】的更多相关文章

链接 http://codeforces.com/contest/123/problem/A 题目 You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is…
Prime Permutation 原题地址: http://codeforces.com/problemset/problem/123/A 题目大意: 给你一个字符串(只包含小写字母),从1开始存放.定义长度为|s|,有1<=|s|<=1000.要求通过调整字符在字符串中的位置,使得:       设p为小于等于|s|的素数,有s[p]=s[p*i] (p*i<=|s|),能够完成该项任务就输出YES和调整后的字符串,不能则输出NO. 大致思路: 由于s[p]=s[p*i],如果|s|…
A. Prime Permutation 题目连接: http://www.codeforces.com/contest/123/problem/A Description You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from…
题意:给定一个字符串,问你能不能通过重排,使得任意一个素数p <= 字符串长度n,并且 任意的 i <= 长度n/素数p,满足s[p] == s[p*i]. 析:很容易能够看出来,只要是某个素数的小于等于该素数的倍数都是一样的,然后如果他和其他素数也有倍数,那么这些位置也是一样的, 所以我们只要找到任意一个小于等于 n 的素数与该素数相乘都大于 n的,然后用把数目最少的字符种给它,然后剩下的给那些. 所以能够看出lcm(2, i) (i是素数) <= n的那么这些位置包括小于等于该素数的…
例12   Eratosthenes筛法求质数 问题描述 Eratosthenes筛法的基本思想是:把某范围内的自然数从小到大依次排列好.宣布1不是质数,把它去掉:然后从余下的数中取出最小的数,宣布它为质数,并去掉它的倍数.在第1步之后,得到质数2,筛中只包含奇数:第2步之后,得到质数3,一直做下去,当筛中为空时结束. 用Eratosthenes筛法求给定区间内的所有质数. 输入格式 两个整数a和b,其中1≤a≤b≤10000 输出格式 输出给定范围[a,b]间的所有质数,输出时每个质数占6列,…
基本数据类型补充 set set集合,是一个无序且不重复的元素集合 #创建 s = {11,22,33,44}#类似字典 s = set() #转换 l = (11,22,33,44) s1 = set(l) #iterable print(s1) l = [11,22,33,44] s1 = set(l) #iterable print(s1) l = "1234" s1 = set(l) #iterable print(s1) {33, 11, 44, 22} {33, 11, 4…
Codeforces 1091D New Year and the Permutation Concatenation https://codeforces.com/contest/1091/problem/D 题目: Let n be an integer. Consider all permutations on integers 1 to n in lexicographic order, and concatenate them into one big sequence p. For…
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): "123" "132" "213" "231" "312" "3…
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): "123" "132" "213" "231" "312" "3…
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): "123" "132" "213" "231" "312" "3…