本文将分享CodeforcesRound#436(Div.2)-贪心-D.MakeaPermutation!的详细内容,并且还将对贪心retrospect的进行详尽解释,此外,我们还将为大家带来关于C
本文将分享Codeforces Round #436 (Div. 2)-贪心-D. Make a Permutation!的详细内容,并且还将对贪心retrospect的进行详尽解释,此外,我们还将为大家带来关于C. Diverse Permutation(Codeforces Round #275(div2)_html/css_WEB-ITnose、CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations、CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation、Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))的相关知识,希望对你有所帮助。
本文目录一览:- Codeforces Round #436 (Div. 2)-贪心-D. Make a Permutation!(贪心retrospect的)
- C. Diverse Permutation(Codeforces Round #275(div2)_html/css_WEB-ITnose
- CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations
- CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation
- Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))
Codeforces Round #436 (Div. 2)-贪心-D. Make a Permutation!(贪心retrospect的)
总结
以上是小编为你收集整理的Codeforces Round #436 (Div. 2)-贪心-D. Make a Permutation!全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
C. Diverse Permutation(Codeforces Round #275(div2)_html/css_WEB-ITnose
C. Diverse Permutation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
permutation p is an ordered set of integers p1,???p2,???...,???pn, consisting of n distinct positive integers not larger than n. we''ll denote as nthe length of permutation p1,???p2,???...,???pn.
Your task is to find such permutation p of length n, that the group of numbers |p1?-?p2|,?|p2?-?p3|,?...,?|pn?-?1?-?pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1?≤?k?
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Sample test(s)
input
3 2
output
1 3 2
input
3 1
output
1 2 3
input
5 2
output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
立即学习“前端免费学习笔记(深入)”;
用n个数1~n,每个数只能用一次,组成差值的绝对值有k个数,为1~k。输出任一个方案。
构造题,我是这样构造的,取前k+1个数,第一个数取1,先+k,后一个数-(k-1),在后一个数+k-2.......这样从两头往
中间靠拢,既取完了k+1个数,又构造了1~k的差值绝对值,至于k+1后的嘛,每次+1就行了。
代码:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int maxn=100000+1000;int ans[maxn];int main(){ int n,k; ans[1]=1; scanf("%d%d",&n,&k); if(k==1) { for(int i=1;i <br><br><p></p> </cstring></algorithm></cstdio></iostream>
CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations
总结
以上是小编为你收集整理的CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation
We all kNow that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name ss can transform to another superhero with name tt if ss can be made equal to tt by changing any vowel in ss to any other vowel and any consonant in ss to any other consonant. Multiple changes can be made.
In this problem,we consider the letters ‘a‘,‘e‘,‘i‘,‘o‘ and ‘u‘ to be vowels and all the other letters to be consonants.
Given the names of two superheroes,determine if the superhero with name ss can be transformed to the Superhero with name tt.
The first line contains the string ss having length between 11 and 10001000,inclusive.
The second line contains the string tt having length between 11 and 10001000,inclusive.
Both strings ss and tt are guaranteed to be different and consist of lowercase English letters only.
Output "Yes" (without quotes) if the superhero with name ss can be transformed to the superhero with name tt and "No" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
a u
Yes
abc ukm
Yes
akm ua
No
In the first sample,since both ‘a‘ and ‘u‘ are vowels,it is possible to convert string ss to tt.
In the third sample,‘k‘ is a consonant,whereas ‘a‘ is a vowel,so it is not possible to convert string ss to tt.
strlen()函数求出的字符串长度为有效长度,既不包含字符串末尾结束符 ‘\0’;
sizeof()操作符求出的长度包含字符串末尾的结束符 ‘\0’;
当在函数内部使用sizeof()求解由函数的形参传入的字符数组的长度时,得到的结果为指针的长度,既对应变量的字节数,而不是字符串的长度,此处一定要小心。
代码如下:
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 5 int vow(char a,char b) 6 { 7 if(a == b) 8 return 1; 9 else if(a == ‘a‘ || a == ‘o‘ || a == ‘e‘ || a == ‘i‘ || a == ‘u‘) 10 { 11 if(b == ‘a‘ || b == ‘o‘ || b == ‘e‘ || b == ‘i‘ || b == ‘u‘)//元元 12 return 1; 13 else//元辅 14 return 0; 15 } 16 else if(b == ‘a‘ || b == ‘o‘ || b == ‘e‘ || b == ‘i‘ || b == ‘u‘)//辅元 17 return 0; 18 //辅辅 19 return 1; 20 } 21 int main() 22 { 23 string s,t; 24 while(cin >> s >> t) 25 { 26 int sl = s.size(); 27 int tl = t.size(); 28 if(sl != tl) 29 { 30 cout << "No" << endl; 31 continue; 32 } 33 bool flag = 0; 34 for(int i = 0;i < sl;i++) 35 { 36 if(vow(s[i],t[i]) == 0) 37 { 38 cout << "No" << endl; 39 flag = 1; 40 break; 41 } 42 } 43 if(flag == 0) 44 cout << "Yes" << endl; 45 } 46 return 0; 47 }
Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))
Vasya is reading a e-book. The file of the book consists of nn pages, numbered from 11 to nn. The screen is currently displaying the contents of page xx, and Vasya wants to read the page yy. There are two buttons on the book which allow Vasya to scroll dd pages forwards or backwards (but he cannot scroll outside the book). For example, if the book consists of 1010 pages, and d=3d=3, then from the first page Vasya can scroll to the first or to the fourth page by pressing one of the buttons; from the second page — to the first or to the fifth; from the sixth page — to the third or to the ninth; from the eighth — to the fifth or to the tenth.
Help Vasya to calculate the minimum number of times he needs to press a button to move to page yy.
The first line contains one integer tt (1≤t≤1031≤t≤103) — the number of testcases.
Each testcase is denoted by a line containing four integers nn, xx, yy, dd (1≤n,d≤1091≤n,d≤109, 1≤x,y≤n1≤x,y≤n) — the number of pages, the starting page, the desired page, and the number of pages scrolled by pressing one button, respectively.
Print one line for each test.
If Vasya can move from page xx to page yy, print the minimum number of times he needs to press a button to do it. Otherwise print −1−1.
3
10 4 5 2
5 1 3 4
20 4 19 3
4
-1
5
In the first test case the optimal sequence is: 4→2→1→3→54→2→1→3→5.
In the second test case it is possible to get to pages 11 and 55.
In the third test case the optimal sequence is: 4→7→10→13→16→194→7→10→13→16→19.
翻到头只能从头翻,翻到尾只能从尾倒着翻。
代码:
1 //A
2 #include<bits/stdc++.h>
3 using namespace std;
4 typedef long long ll;
5 const int maxn=1e5+10;
6 const int inf=0x3f3f3f3f;
7
8 int main()
9 {
10 int t;
11 cin>>t;
12 while(t--){
13 int n,x,y,d,ans=inf;
14 cin>>n>>x>>y>>d;
15 if(abs(y-x)%d==0) {ans=min(ans,abs(y-x)/d);}
16 if((y-1)%d==0) {ans=min(ans,x/d+(y-1)/d+(x%d==0?0:1));}
17 if((n-y)%d==0) {ans=min(ans,(n-x)/d+(n-y)/d+((n-x)%d==0?0:1));}
18 if(ans==inf) cout<<-1<<endl;
19 else cout<<ans<<endl;
20 }
21 }
今天关于Codeforces Round #436 (Div. 2)-贪心-D. Make a Permutation!和贪心retrospect的的介绍到此结束,谢谢您的阅读,有关C. Diverse Permutation(Codeforces Round #275(div2)_html/css_WEB-ITnose、CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations、CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation、Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))等更多相关知识的信息可以在本站进行查询。
本文标签: